Skip to content

Commit 0417d24

Browse files
committed
address feedback
1 parent 0c27e87 commit 0417d24

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

.generator/cli.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,23 @@ def _update_version_for_library(
10961096
# Find and update version.py or gapic_version.py files
10971097
search_base = Path(f"{repo}/{path_to_library}")
10981098
version_files = list(search_base.rglob("**/gapic_version.py"))
1099-
version_files.extend(list(search_base.glob("google/**/version.py")))
1099+
excluded_dirs = {
1100+
".nox",
1101+
".venv",
1102+
"venv",
1103+
"site-packages",
1104+
".git",
1105+
"build",
1106+
"dist",
1107+
"__pycache__",
1108+
}
1109+
version_files.extend(
1110+
[
1111+
p
1112+
for p in search_base.rglob("**/version.py")
1113+
if not any(part in excluded_dirs for part in p.parts)
1114+
]
1115+
)
11001116

11011117
if not version_files:
11021118
# Fallback to `pyproject.toml`` or `setup.py``. Proto-only libraries have

.generator/test_cli.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,12 @@ def test_update_global_changelog(mocker, mock_release_init_request_file):
986986
def test_update_version_for_library_success_gapic(mocker):
987987
m = mock_open()
988988

989-
mock_rglob = mocker.patch(
990-
"pathlib.Path.rglob", return_value=[pathlib.Path("repo/gapic_version.py")]
991-
)
989+
mock_rglob = mocker.patch("pathlib.Path.rglob")
990+
mock_rglob.side_effect = [
991+
[pathlib.Path("repo/gapic_version.py")], # 1st call (gapic_version.py)
992+
[], # 2nd call (version.py)
993+
[pathlib.Path("repo/samples/snippet_metadata.json")] # 3rd call (snippets)
994+
]
992995
mock_shutil_copy = mocker.patch("shutil.copy")
993996
mock_content = '__version__ = "1.2.2"'
994997
mock_json_metadata = {"clientLibrary": {"version": "0.1.0"}}
@@ -1018,7 +1021,11 @@ def test_update_version_for_library_success_proto_only_setup_py(mocker):
10181021
m = mock_open()
10191022

10201023
mock_rglob = mocker.patch("pathlib.Path.rglob")
1021-
mock_rglob.side_effect = [[], [pathlib.Path("repo/setup.py")]]
1024+
mock_rglob.side_effect = [
1025+
[],
1026+
[pathlib.Path("repo/setup.py")],
1027+
[pathlib.Path("repo/samples/snippet_metadata.json")]
1028+
]
10221029
mock_shutil_copy = mocker.patch("shutil.copy")
10231030
mock_content = 'version = "1.2.2"'
10241031
mock_json_metadata = {"clientLibrary": {"version": "0.1.0"}}
@@ -1049,7 +1056,11 @@ def test_update_version_for_library_success_proto_only_py_project_toml(mocker):
10491056

10501057
mock_path_exists = mocker.patch("pathlib.Path.exists")
10511058
mock_rglob = mocker.patch("pathlib.Path.rglob")
1052-
mock_rglob.side_effect = [[], [pathlib.Path("repo/pyproject.toml")]]
1059+
mock_rglob.side_effect = [
1060+
[],
1061+
[pathlib.Path("repo/pyproject.toml")],
1062+
[pathlib.Path("repo/samples/snippet_metadata.json")]
1063+
]
10531064
mock_shutil_copy = mocker.patch("shutil.copy")
10541065
mock_content = 'version = "1.2.2"'
10551066
mock_json_metadata = {"clientLibrary": {"version": "0.1.0"}}

0 commit comments

Comments
 (0)