Skip to content

Commit b32d263

Browse files
committed
feat: create docs README file
1 parent 2eaa21d commit b32d263

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

.generator/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ 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+
353361
# copy post-procesing files
354362
for post_processing_file in glob.glob(
355363
f"{input}/client-post-processing/*.yaml"

.generator/test_cli.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,28 @@ def test_copy_files_needed_for_post_processing_copies_metadata_if_exists(mocker)
814814
mock_makedirs.assert_called()
815815

816816

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+
817839
def test_copy_files_needed_for_post_processing_skips_metadata_if_not_exists(mocker):
818840
"""Tests that .repo-metadata.json is not copied if it does not exist."""
819841
mock_makedirs = mocker.patch("os.makedirs")

0 commit comments

Comments
 (0)