Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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)}"
Expand Down
9 changes: 5 additions & 4 deletions .generator/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading