Skip to content

Commit d252f4d

Browse files
committed
address feedback
1 parent bcc4f13 commit d252f4d

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
@@ -1147,7 +1147,23 @@ def _update_version_for_library(
11471147
# Find and update version.py or gapic_version.py files
11481148
search_base = Path(f"{repo}/{path_to_library}")
11491149
version_files = list(search_base.rglob("**/gapic_version.py"))
1150-
version_files.extend(list(search_base.glob("google/**/version.py")))
1150+
excluded_dirs = {
1151+
".nox",
1152+
".venv",
1153+
"venv",
1154+
"site-packages",
1155+
".git",
1156+
"build",
1157+
"dist",
1158+
"__pycache__",
1159+
}
1160+
version_files.extend(
1161+
[
1162+
p
1163+
for p in search_base.rglob("**/version.py")
1164+
if not any(part in excluded_dirs for part in p.parts)
1165+
]
1166+
)
11511167

11521168
if not version_files:
11531169
# 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
@@ -988,9 +988,12 @@ def test_update_global_changelog(mocker, mock_release_init_request_file):
988988
def test_update_version_for_library_success_gapic(mocker):
989989
m = mock_open()
990990

991-
mock_rglob = mocker.patch(
992-
"pathlib.Path.rglob", return_value=[pathlib.Path("repo/gapic_version.py")]
993-
)
991+
mock_rglob = mocker.patch("pathlib.Path.rglob")
992+
mock_rglob.side_effect = [
993+
[pathlib.Path("repo/gapic_version.py")], # 1st call (gapic_version.py)
994+
[], # 2nd call (version.py)
995+
[pathlib.Path("repo/samples/snippet_metadata.json")] # 3rd call (snippets)
996+
]
994997
mock_shutil_copy = mocker.patch("shutil.copy")
995998
mock_content = '__version__ = "1.2.2"'
996999
mock_json_metadata = {"clientLibrary": {"version": "0.1.0"}}
@@ -1020,7 +1023,11 @@ def test_update_version_for_library_success_proto_only_setup_py(mocker):
10201023
m = mock_open()
10211024

10221025
mock_rglob = mocker.patch("pathlib.Path.rglob")
1023-
mock_rglob.side_effect = [[], [pathlib.Path("repo/setup.py")]]
1026+
mock_rglob.side_effect = [
1027+
[],
1028+
[pathlib.Path("repo/setup.py")],
1029+
[pathlib.Path("repo/samples/snippet_metadata.json")]
1030+
]
10241031
mock_shutil_copy = mocker.patch("shutil.copy")
10251032
mock_content = 'version = "1.2.2"'
10261033
mock_json_metadata = {"clientLibrary": {"version": "0.1.0"}}
@@ -1051,7 +1058,11 @@ def test_update_version_for_library_success_proto_only_py_project_toml(mocker):
10511058

10521059
mock_path_exists = mocker.patch("pathlib.Path.exists")
10531060
mock_rglob = mocker.patch("pathlib.Path.rglob")
1054-
mock_rglob.side_effect = [[], [pathlib.Path("repo/pyproject.toml")]]
1061+
mock_rglob.side_effect = [
1062+
[],
1063+
[pathlib.Path("repo/pyproject.toml")],
1064+
[pathlib.Path("repo/samples/snippet_metadata.json")]
1065+
]
10551066
mock_shutil_copy = mocker.patch("shutil.copy")
10561067
mock_content = 'version = "1.2.2"'
10571068
mock_json_metadata = {"clientLibrary": {"version": "0.1.0"}}

0 commit comments

Comments
 (0)