Skip to content

Commit 22b9640

Browse files
authored
chore(librarian): resolve issue where generation failed for certain packages (#14828)
This PR fixes an issue where generation fails for libraries when `/input/packages/google-cloud-<api>` does not exist. ``` Traceback (most recent call last): File "/app/./cli.py", line 620, in handle_generate _copy_files_needed_for_post_processing(output, input, library_id, is_mono_repo) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/./cli.py", line 372, in _copy_files_needed_for_post_processing shutil.copytree( ~~~~~~~~~~~~~~~^ source_dir, ^^^^^^^^^^^ ...<2 lines>... ignore=shutil.ignore_patterns("client-post-processing"), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/usr/local/lib/python3.14/shutil.py", line 652, in copytree with os.scandir(src) as itr: ~~~~~~~~~~^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '/input/packages/google-cloud-hypercomputecluster' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/./cli.py", line 1582, in <module> args.func( ~~~~~~~~~^ librarian=args.librarian, ^^^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... input=args.input, ^^^^^^^^^^^^^^^^^ ) ^ File "/app/./cli.py", line 628, in handle_generate raise ValueError("Generation failed.") from e ValueError: Generation failed. ```
1 parent 5ba8437 commit 22b9640

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

.generator/cli.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,13 @@ def _copy_files_needed_for_post_processing(
369369
path_to_library = f"packages/{library_id}" if is_mono_repo else "."
370370
source_dir = f"{input}/{path_to_library}"
371371

372-
shutil.copytree(
373-
source_dir,
374-
output,
375-
dirs_exist_ok=True,
376-
ignore=shutil.ignore_patterns("client-post-processing"),
377-
)
372+
if Path(source_dir).exists():
373+
shutil.copytree(
374+
source_dir,
375+
output,
376+
dirs_exist_ok=True,
377+
ignore=shutil.ignore_patterns("client-post-processing"),
378+
)
378379

379380
# We need to create these directories so that we can copy files necessary for post-processing.
380381
os.makedirs(

.generator/test_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ def test_copy_files_needed_for_post_processing_copies_files_from_generator_input
859859
"""Tests that .repo-metadata.json is copied if it exists."""
860860
mock_makedirs = mocker.patch("os.makedirs")
861861
mock_shutil_copytree = mocker.patch("shutil.copytree")
862+
mocker.patch("pathlib.Path.exists", return_value=True)
862863

863864
_copy_files_needed_for_post_processing(
864865
"output", "input", "library_id", is_mono_repo

0 commit comments

Comments
 (0)