Skip to content

Commit 89b992d

Browse files
authored
chore(librarian): resolve issue where release init fails for version.py (#14809)
Fixes googleapis/librarian#2678 Fixes b/455360208
1 parent c3c2fbb commit 89b992d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.generator/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,11 @@ def _update_version_for_library(
11971197
version_files = [pyproject_toml if pyproject_toml.exists() else setup_py]
11981198

11991199
for version_file in version_files:
1200+
# Do not process version files in the types directory as some
1201+
# GAPIC libraries have `version.py` which are generated from
1202+
# `version.proto` and do not include SDK versions.
1203+
if version_file.parent.name == "types":
1204+
continue
12001205
updated_content = _process_version_file(
12011206
_read_text_file(version_file), version, version_file
12021207
)

.generator/test_cli.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,20 +1014,29 @@ def test_update_global_changelog(mocker, mock_release_init_request_file):
10141014

10151015

10161016
def test_update_version_for_library_success_gapic(mocker):
1017+
mock_content = '__version__ = "1.2.2"'
1018+
mock_json_metadata = {"clientLibrary": {"version": "0.1.0"}}
1019+
mock_shutil_copy = mocker.patch("shutil.copy")
1020+
10171021
m = mock_open()
10181022

10191023
mock_rglob = mocker.patch("pathlib.Path.rglob")
10201024
mock_rglob.side_effect = [
10211025
[pathlib.Path("repo/gapic_version.py")], # 1st call (gapic_version.py)
1022-
[], # 2nd call (version.py)
1026+
[pathlib.Path("repo/types/version.py")], # 2nd call (types/version.py).
10231027
[pathlib.Path("repo/samples/snippet_metadata.json")], # 3rd call (snippets)
10241028
]
1025-
mock_shutil_copy = mocker.patch("shutil.copy")
1026-
mock_content = '__version__ = "1.2.2"'
1027-
mock_json_metadata = {"clientLibrary": {"version": "0.1.0"}}
1029+
mock_rglob = mocker.patch("cli._read_text_file")
1030+
mock_rglob.side_effect = [
1031+
mock_content, # 1st call (gapic_version.py)
1032+
# Do not process version files in the `types` directory as some
1033+
# GAPIC libraries have `version.py` which are generated from
1034+
# `version.proto` and do not include SDK versions.
1035+
# Leave the content as empty because it doesn't contain version information
1036+
"", # 2nd call (types/version.py)
1037+
]
10281038

10291039
with unittest.mock.patch("cli.open", m):
1030-
mocker.patch("cli._read_text_file", return_value=mock_content)
10311040
mocker.patch("cli._read_json_file", return_value=mock_json_metadata)
10321041
_update_version_for_library(
10331042
"repo", "output", "packages/google-cloud-language", "1.2.3"

0 commit comments

Comments
 (0)