Skip to content

Commit 807bc42

Browse files
committed
safegaurd existing workflow
1 parent 49e3f0d commit 807bc42

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

.generator/cli.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,21 @@ def _copy_files_needed_for_post_processing(output: str, input: str, library_id:
307307
"""
308308

309309
path_to_library = f"packages/{library_id}"
310+
repo_metadata_path = f"{input}/{path_to_library}/.repo-metadata.json"
310311

311312
# We need to create these directories so that we can copy files necessary for post-processing.
312-
os.makedirs(f"{output}/{path_to_library}/scripts/client-post-processing", exist_ok=True)
313-
shutil.copy(
314-
f"{input}/{path_to_library}/.repo-metadata.json",
315-
f"{output}/{path_to_library}/.repo-metadata.json",
313+
os.makedirs(
314+
f"{output}/{path_to_library}/scripts/client-post-processing", exist_ok=True
316315
)
316+
# TODO(ohmayr): if `.repo-metadata.json` for a library exists in
317+
# ``.librarian/generator-input`, then we override the generated `.repo-metadata.json`
318+
# with what we have in `generator-input`. Remove this logic once the
319+
# generated `.repo-metadata.json` file is completely backfilled.
320+
if os.path.exists(repo_metadata_path):
321+
shutil.copy(
322+
repo_metadata_path,
323+
f"{output}/{path_to_library}/.repo-metadata.json",
324+
)
317325

318326
# copy post-procesing files
319327
for post_processing_file in glob.glob(

.generator/test_cli.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,28 @@ def test_invalid_json(mocker):
724724
_read_json_file("fake/path.json")
725725

726726

727-
def test_copy_files_needed_for_post_processing_success(mocker):
727+
def test_copy_files_needed_for_post_processing_copies_metadata_if_exists(mocker):
728+
"""Tests that .repo-metadata.json is copied if it exists."""
728729
mock_makedirs = mocker.patch("os.makedirs")
729730
mock_shutil_copy = mocker.patch("shutil.copy")
731+
mocker.patch("os.path.exists", return_value=True)
732+
730733
_copy_files_needed_for_post_processing("output", "input", "library_id")
731734

732-
mock_makedirs.assert_called()
733735
mock_shutil_copy.assert_called_once()
736+
mock_makedirs.assert_called()
737+
738+
739+
def test_copy_files_needed_for_post_processing_skips_metadata_if_not_exists(mocker):
740+
"""Tests that .repo-metadata.json is not copied if it does not exist."""
741+
mock_makedirs = mocker.patch("os.makedirs")
742+
mock_shutil_copy = mocker.patch("shutil.copy")
743+
mocker.patch("os.path.exists", return_value=False)
744+
745+
_copy_files_needed_for_post_processing("output", "input", "library_id")
746+
747+
mock_shutil_copy.assert_not_called()
748+
mock_makedirs.assert_called()
734749

735750

736751
def test_clean_up_files_after_post_processing_success(mocker):

0 commit comments

Comments
 (0)