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
24 changes: 19 additions & 5 deletions .generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,25 @@ def _copy_files_needed_for_post_processing(

path_to_library = f"packages/{library_id}" if is_mono_repo else "."
source_dir = f"{input}/{path_to_library}"
repo_metadata_path = f"{source_dir}/.repo-metadata.json"

# We need to create these directories so that we can copy files necessary for post-processing.
os.makedirs(
f"{output}/{path_to_library}/scripts/client-post-processing", exist_ok=True
)

# `shutil.copytree` does not copy hidden files in sub-directories.
# We need to use `shutil.copy` to explicitly copy the file we want
# TODO(https://github.com/googleapis/librarian/issues/2334):
# if `.repo-metadata.json` for a library exists in
# `.librarian/generator-input`, then we override the generated `.repo-metadata.json`
# with what we have in `generator-input`. Remove this logic once the
# generated `.repo-metadata.json` file is completely backfilled.
if Path(repo_metadata_path).exists():
shutil.copy(
repo_metadata_path,
f"{output}/{path_to_library}/.repo-metadata.json",
)

if Path(source_dir).exists():
shutil.copytree(
Expand All @@ -377,11 +396,6 @@ def _copy_files_needed_for_post_processing(
ignore=shutil.ignore_patterns("client-post-processing"),
)

# We need to create these directories so that we can copy files necessary for post-processing.
os.makedirs(
f"{output}/{path_to_library}/scripts/client-post-processing", exist_ok=True
)

# copy post-procesing files
for post_processing_file in glob.glob(
f"{input}/client-post-processing/*.yaml"
Expand Down
2 changes: 2 additions & 0 deletions .generator/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,13 +858,15 @@ def test_copy_files_needed_for_post_processing_copies_files_from_generator_input
):
"""Tests that .repo-metadata.json is copied if it exists."""
mock_makedirs = mocker.patch("os.makedirs")
mock_shutil_copy = mocker.patch("shutil.copy")
mock_shutil_copytree = mocker.patch("shutil.copytree")
mocker.patch("pathlib.Path.exists", return_value=True)

_copy_files_needed_for_post_processing(
"output", "input", "library_id", is_mono_repo
)

mock_shutil_copy.assert_called()
mock_shutil_copytree.assert_called()
mock_makedirs.assert_called()

Expand Down
Loading