Skip to content

Commit 163f69f

Browse files
committed
feat: wip
1 parent b32d263 commit 163f69f

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

.generator/cli.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,6 @@ def _copy_files_needed_for_post_processing(output: str, input: str, library_id:
350350
f"{output}/{path_to_library}/.repo-metadata.json",
351351
)
352352

353-
source_readme_path = Path(output) / path_to_library / "README.rst"
354-
if source_readme_path.exists():
355-
destination_docs_dir = Path(output) / path_to_library / "docs"
356-
destination_readme_path = destination_docs_dir / "README.rst"
357-
358-
os.makedirs(destination_docs_dir, exist_ok=True)
359-
shutil.copy(source_readme_path, destination_readme_path)
360-
361353
# copy post-procesing files
362354
for post_processing_file in glob.glob(
363355
f"{input}/client-post-processing/*.yaml"
@@ -509,6 +501,24 @@ def _generate_repo_metadata_file(
509501
_write_json_file(output_repo_metadata, metadata_content)
510502

511503

504+
def _copy_readme_to_docs(output: str, library_id: str):
505+
"""Copies the generated README.rst to the docs directory.
506+
507+
Args:
508+
output(str): Path to the directory in the container where code
509+
should be generated.
510+
library_id(str): The library id.
511+
"""
512+
path_to_library = f"packages/{library_id}"
513+
source_readme_path = Path(output) / path_to_library / "README.rst"
514+
if source_readme_path.exists():
515+
destination_docs_dir = Path(output) / path_to_library / "docs"
516+
destination_readme_path = destination_docs_dir / "README.rst"
517+
518+
os.makedirs(destination_docs_dir, exist_ok=True)
519+
shutil.copy(source_readme_path, destination_readme_path)
520+
521+
512522
def handle_generate(
513523
librarian: str = LIBRARIAN_DIR,
514524
source: str = SOURCE_DIR,
@@ -550,6 +560,7 @@ def handle_generate(
550560
_copy_files_needed_for_post_processing(output, input, library_id)
551561
_generate_repo_metadata_file(output, library_id, source, apis_to_generate)
552562
_run_post_processor(output, library_id)
563+
_copy_readme_to_docs(output, library_id)
553564
_clean_up_files_after_post_processing(output, library_id)
554565
except Exception as e:
555566
raise ValueError("Generation failed.") from e

.generator/test_cli.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -640,12 +640,15 @@ def test_handle_generate_success(
640640
)
641641
mocker.patch("cli._generate_repo_metadata_file")
642642

643+
mock_copy_readme_to_docs = mocker.patch("cli._copy_readme_to_docs")
644+
643645
handle_generate()
644646

645647
mock_run_post_processor.assert_called_once_with("output", "google-cloud-language")
646648
mock_copy_files_needed_for_post_processing.assert_called_once_with(
647649
"output", "input", "google-cloud-language"
648650
)
651+
mock_copy_readme_to_docs.assert_called_once_with("output", "google-cloud-language")
649652
mock_clean_up_files_after_post_processing.assert_called_once_with(
650653
"output", "google-cloud-language"
651654
)
@@ -814,28 +817,6 @@ def test_copy_files_needed_for_post_processing_copies_metadata_if_exists(mocker)
814817
mock_makedirs.assert_called()
815818

816819

817-
def test_copy_files_needed_for_post_processing_copies_readme(mocker):
818-
"""Tests that README.rst is copied to the docs directory if it exists."""
819-
mock_makedirs = mocker.patch("os.makedirs")
820-
mock_shutil_copy = mocker.patch("shutil.copy")
821-
mock_path_exists = mocker.patch("pathlib.Path.exists", return_value=True)
822-
mocker.patch("os.path.exists", return_value=False) # for .repo-metadata.json
823-
824-
_copy_files_needed_for_post_processing("output", "input", "google-cloud-language")
825-
826-
mock_makedirs.assert_called_with(
827-
Path("output") / "packages" / "google-cloud-language" / "docs", exist_ok=True
828-
)
829-
mock_shutil_copy.assert_called_with(
830-
Path("output") / "packages" / "google-cloud-language" / "README.rst",
831-
Path("output")
832-
/ "packages"
833-
/ "google-cloud-language"
834-
/ "docs"
835-
/ "README.rst",
836-
)
837-
838-
839820
def test_copy_files_needed_for_post_processing_skips_metadata_if_not_exists(mocker):
840821
"""Tests that .repo-metadata.json is not copied if it does not exist."""
841822
mock_makedirs = mocker.patch("os.makedirs")

.librarian/state.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator:latest
1+
image: python-librarian-generator:latest
22
libraries:
33
- id: google-ads-admanager
44
version: 0.4.0

0 commit comments

Comments
 (0)