Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ def _copy_files_needed_for_post_processing(output: str, input: str, library_id:
f"{output}/{path_to_library}/.repo-metadata.json",
)

source_readme_path = Path(output) / path_to_library / "README.rst"
if source_readme_path.exists():
destination_docs_dir = Path(output) / path_to_library / "docs"
destination_readme_path = destination_docs_dir / "README.rst"

os.makedirs(destination_docs_dir, exist_ok=True)
shutil.copy(source_readme_path, destination_readme_path)

# copy post-procesing files
for post_processing_file in glob.glob(
f"{input}/client-post-processing/*.yaml"
Expand Down
22 changes: 22 additions & 0 deletions .generator/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,28 @@ def test_copy_files_needed_for_post_processing_copies_metadata_if_exists(mocker)
mock_makedirs.assert_called()


def test_copy_files_needed_for_post_processing_copies_readme(mocker):
"""Tests that README.rst is copied to the docs directory if it exists."""
mock_makedirs = mocker.patch("os.makedirs")
mock_shutil_copy = mocker.patch("shutil.copy")
mock_path_exists = mocker.patch("pathlib.Path.exists", return_value=True)
mocker.patch("os.path.exists", return_value=False) # for .repo-metadata.json

_copy_files_needed_for_post_processing("output", "input", "google-cloud-language")

mock_makedirs.assert_called_with(
Path("output") / "packages" / "google-cloud-language" / "docs", exist_ok=True
)
mock_shutil_copy.assert_called_with(
Path("output") / "packages" / "google-cloud-language" / "README.rst",
Path("output")
/ "packages"
/ "google-cloud-language"
/ "docs"
/ "README.rst",
)


def test_copy_files_needed_for_post_processing_skips_metadata_if_not_exists(mocker):
"""Tests that .repo-metadata.json is not copied if it does not exist."""
mock_makedirs = mocker.patch("os.makedirs")
Expand Down
Loading
Loading