diff --git a/.generator/cli.py b/.generator/cli.py index c6c93504bd12..5bf3906b0182 100644 --- a/.generator/cli.py +++ b/.generator/cli.py @@ -1199,7 +1199,8 @@ def _update_version_for_library( # Find and update version.py or gapic_version.py files search_base = Path(f"{repo}/{path_to_library}") - version_files = list(search_base.rglob("**/gapic_version.py")) + version_files = [] + patterns = ["**/gapic_version.py", "**/version.py"] excluded_dirs = { ".nox", ".venv", @@ -1209,14 +1210,16 @@ def _update_version_for_library( "build", "dist", "__pycache__", + "tests", } - version_files.extend( - [ - p - for p in search_base.rglob("**/version.py") - if not any(part in excluded_dirs for part in p.parts) - ] - ) + for pattern in patterns: + version_files.extend( + [ + p + for p in search_base.rglob(pattern) + if not any(part in excluded_dirs for part in p.parts) + ] + ) if not version_files: # Fallback to `pyproject.toml`` or `setup.py``. Proto-only libraries have @@ -1238,8 +1241,8 @@ def _update_version_for_library( _write_text_file(output_path, updated_content) # Find and update snippet_metadata.json files - snippet_metadata_files = Path(f"{repo}/{path_to_library}").rglob( - "samples/**/*snippet*.json" + snippet_metadata_files = Path(f"{repo}/{path_to_library}/samples").rglob( + "**/*snippet*.json" ) for metadata_file in snippet_metadata_files: output_path = f"{output}/{metadata_file.relative_to(repo)}" diff --git a/.generator/test_cli.py b/.generator/test_cli.py index 68d1a4078478..ecd75cd68df8 100644 --- a/.generator/test_cli.py +++ b/.generator/test_cli.py @@ -1037,18 +1037,19 @@ def test_update_version_for_library_success_gapic(mocker): mock_rglob = mocker.patch("pathlib.Path.rglob") mock_rglob.side_effect = [ - [pathlib.Path("repo/gapic_version.py")], # 1st call (gapic_version.py) + [pathlib.Path("repo/gapic_version.py"), pathlib.Path("repo/tests/gapic_version.py")], # 1st call (gapic_version.py) [pathlib.Path("repo/types/version.py")], # 2nd call (types/version.py). [pathlib.Path("repo/samples/snippet_metadata.json")], # 3rd call (snippets) ] - mock_rglob = mocker.patch("cli._read_text_file") - mock_rglob.side_effect = [ + mock_read_text_file = mocker.patch("cli._read_text_file") + mock_read_text_file.side_effect = [ mock_content, # 1st call (gapic_version.py) # Do not process version files in the `types` directory as some # GAPIC libraries have `version.py` which are generated from # `version.proto` and do not include SDK versions. # Leave the content as empty because it doesn't contain version information - "", # 2nd call (types/version.py) + "", # 2nd call (tests/gapic_version.py) + "", # 3rd call (types/version.py) ] with unittest.mock.patch("cli.open", m):