Skip to content

Commit 92d75be

Browse files
committed
address PR feedback
1 parent a34b3e5 commit 92d75be

2 files changed

Lines changed: 7 additions & 73 deletions

File tree

.generator/cli.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -187,40 +187,16 @@ def _get_new_library_config(request_data: Dict) -> Dict:
187187
return {}
188188

189189

190-
def _get_library_version(library_id: str, repo: str) -> str:
191-
"""Gets the library version from its gapic_version.py file.
192-
193-
Args:
194-
library_id(str): The id of the library.
195-
repo(str): The path to the repository.
196-
197-
Returns:
198-
str: The version of the library.
199-
"""
200-
library_path = Path(f"{repo}/packages/{library_id}")
201-
gapic_version_files = list(library_path.rglob("**/gapic_version.py"))
202-
if not gapic_version_files:
203-
raise ValueError(f"Could not find gapic_version.py for {library_id}")
204-
205-
content = _read_text_file(gapic_version_files[0])
206-
match = re.search(r"__version__\s*=\s*[\"']([^\"']+)[\"']", content)
207-
if not match:
208-
raise ValueError(f"Could not extract version from {gapic_version_files[0]}")
209-
return match.group(1)
210-
211-
212190
def _add_new_library_version(
213-
library_config: Dict, library_id: str, repo: str
191+
library_config: Dict
214192
) -> None:
215193
"""Adds the library version to the configuration if it's not present.
216194
217195
Args:
218196
library_config(Dict): The library configuration.
219-
library_id(str): The id of the library.
220-
repo(str): The path to the repository.
221197
"""
222198
if "version" not in library_config or not library_config["version"]:
223-
library_config["version"] = _get_library_version(library_id, repo)
199+
library_config["version"] = "0.0.0"
224200

225201

226202
def _prepare_new_library_config(library_config: Dict, repo: str) -> Dict:
@@ -246,7 +222,7 @@ def _prepare_new_library_config(library_config: Dict, repo: str) -> Dict:
246222
_add_new_library_preserve_regex(library_config, library_id)
247223
_add_new_library_remove_regex(library_config, library_id)
248224
_add_new_library_tag_format(library_config)
249-
_add_new_library_version(library_config, library_id, repo)
225+
_add_new_library_version(library_config)
250226

251227
return library_config
252228

.generator/test_cli.py

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
_get_library_dist_name,
4545
_get_library_id,
4646
_get_libraries_to_prepare_for_release,
47-
_get_library_version,
4847
_get_new_library_config,
4948
_get_previous_version,
5049
_add_new_library_version,
@@ -322,7 +321,6 @@ def test_get_new_library_config_empty_input():
322321

323322
def test_prepare_new_library_config(mocker):
324323
"""Tests the preparation of a new library's configuration."""
325-
mocker.patch("cli._get_library_version", return_value="1.2.3")
326324
raw_config = {
327325
"id": "google-cloud-language",
328326
"apis": [{"path": "google/cloud/language/v1", "status": "new"}],
@@ -341,12 +339,11 @@ def test_prepare_new_library_config(mocker):
341339
assert "packages/google-cloud-language/CHANGELOG.md" in prepared_config["preserve_regex"]
342340
assert prepared_config["remove_regex"] == ["packages/google-cloud-language"]
343341
assert prepared_config["tag_format"] == "{{id}}-v{{version}}"
344-
assert prepared_config["version"] == "1.2.3"
342+
assert prepared_config["version"] == "0.0.0"
345343

346344

347345
def test_prepare_new_library_config_preserves_existing_values(mocker):
348346
"""Tests that existing values in the config are not overwritten."""
349-
mocker.patch("cli._get_library_version", return_value="1.2.3")
350347
raw_config = {
351348
"id": "google-cloud-language",
352349
"apis": [{"path": "google/cloud/language/v1", "status": "new"}],
@@ -369,59 +366,20 @@ def test_prepare_new_library_config_preserves_existing_values(mocker):
369366
assert prepared_config["version"] == "4.5.6"
370367

371368

372-
def test_get_library_version_success(mocker):
373-
"""Tests successful extraction of a version from a file."""
374-
mock_rglob = mocker.patch(
375-
"pathlib.Path.rglob", return_value=[pathlib.Path("repo/gapic_version.py")]
376-
)
377-
mocker.patch("cli._read_text_file", return_value='__version__ = "1.2.3"')
378-
version = _get_library_version("google-cloud-language", "repo")
379-
assert version == "1.2.3"
380-
mock_rglob.assert_called_once_with("**/gapic_version.py")
381-
382-
383-
def test_get_library_version_no_file(mocker):
384-
"""Tests failure when gapic_version.py is not found."""
385-
mocker.patch("pathlib.Path.rglob", return_value=[])
386-
with pytest.raises(ValueError, match="Could not find gapic_version.py"):
387-
_get_library_version("google-cloud-language", "repo")
388-
389-
390-
def test_get_library_version_no_version_in_file(mocker):
391-
"""Tests failure when the version string is not in the file."""
392-
mocker.patch(
393-
"pathlib.Path.rglob", return_value=[pathlib.Path("repo/gapic_version.py")]
394-
)
395-
mocker.patch("cli._read_text_file", return_value="some_other_content = 'foo'")
396-
with pytest.raises(ValueError, match="Could not extract version"):
397-
_get_library_version("google-cloud-language", "repo")
398-
399-
400369
def test_add_new_library_version_populates_version(mocker):
401370
"""Tests that the version is populated if it's missing."""
402-
mock_get_version = mocker.patch("cli._get_library_version", return_value="1.2.3")
403371
config = {"version": ""}
404-
_add_new_library_version(config, "google-cloud-language", "repo")
405-
assert config["version"] == "1.2.3"
406-
mock_get_version.assert_called_once_with("google-cloud-language", "repo")
372+
_add_new_library_version(config)
373+
assert config["version"] == "0.0.0"
407374

408375

409376
def test_add_new_library_version_preserves_version():
410377
"""Tests that an existing version is preserved."""
411378
config = {"version": "4.5.6"}
412-
_add_new_library_version(config, "google-cloud-language", "repo")
379+
_add_new_library_version(config)
413380
assert config["version"] == "4.5.6"
414381

415382

416-
def test_add_new_library_version_populates_missing_key(mocker):
417-
"""Tests that the version is populated if the key is missing."""
418-
mock_get_version = mocker.patch("cli._get_library_version", return_value="1.2.3")
419-
config = {} # No 'version' key
420-
_add_new_library_version(config, "google-cloud-language", "repo")
421-
assert config["version"] == "1.2.3"
422-
mock_get_version.assert_called_once_with("google-cloud-language", "repo")
423-
424-
425383
def test_get_library_id_success():
426384
"""Tests that _get_library_id returns the correct ID when present."""
427385
request_data = {"id": "test-library", "name": "Test Library"}

0 commit comments

Comments
 (0)