Skip to content

Commit 6937f74

Browse files
msyycCopilotCopilot
authored
Treat 0.0.0 as invalid version in get_version_info (#46549)
* Treat 0.0.0 as invalid version in get_version_info * Update eng/tools/azure-sdk-tools/packaging_tools/package_utils.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Use packaging.version.Version for 0.0.0 check; add unit tests Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/4ebec9df-c06c-4b15-a0a9-97e80d6dc045 Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> * Improve assertion in 0.0.0.1 test to check specific return value Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/4ebec9df-c06c-4b15-a0a9-97e80d6dc045 Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 3f5c89f commit 6937f74

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

eng/tools/azure-sdk-tools/packaging_tools/package_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import sys
33
import os
4+
from packaging.version import Version
45
import ast
56
import shutil
67
from importlib.util import find_spec
@@ -68,6 +69,11 @@ def get_version_info(package_name: str, tag_is_stable: bool = False) -> Tuple[st
6869
_LOGGER.warning(f"Failed to get version info from PyPI for {package_name}: {e}")
6970
last_version = ""
7071
last_stable_release = ""
72+
73+
# Ignore 0.0.0 when it appears on PyPI as a placeholder or name-reservation version.
74+
if last_version and Version(last_version).base_version == "0.0.0":
75+
return "", ""
76+
7177
return last_version, str(last_stable_release)
7278

7379

eng/tools/azure-sdk-tools/tests/test_package_utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pathlib import Path
22
import os
3+
from unittest.mock import patch, MagicMock
4+
from packaging.version import Version
35

46
try:
57
import tomllib as toml
@@ -69,3 +71,39 @@ def test_check_file_sets_is_stable_false_for_beta(tmp_path, monkeypatch):
6971
assert data["packaging"]["is_stable"] is False
7072
# title still populated
7173
assert data["packaging"]["title"] == "FooClient"
74+
75+
76+
def test_get_version_info_treats_0_0_0_as_invalid():
77+
"""get_version_info should return empty strings when the latest PyPI version is 0.0.0."""
78+
with patch("pypi_tools.pypi.PyPIClient") as MockClient:
79+
mock_client = MagicMock()
80+
MockClient.return_value = mock_client
81+
mock_client.get_ordered_versions.return_value = [Version("0.0.0")]
82+
83+
result = pu.get_version_info("azure-some-package", tag_is_stable=False)
84+
85+
assert result == ("", "")
86+
87+
88+
def test_get_version_info_treats_0_0_0_prerelease_as_invalid():
89+
"""get_version_info should return empty strings when the latest PyPI version is 0.0.0b1."""
90+
with patch("pypi_tools.pypi.PyPIClient") as MockClient:
91+
mock_client = MagicMock()
92+
MockClient.return_value = mock_client
93+
mock_client.get_ordered_versions.return_value = [Version("0.0.0b1")]
94+
95+
result = pu.get_version_info("azure-some-package", tag_is_stable=False)
96+
97+
assert result == ("", "")
98+
99+
100+
def test_get_version_info_does_not_filter_0_0_0_1():
101+
"""get_version_info should NOT filter 0.0.0.1 — its base version is not 0.0.0."""
102+
with patch("pypi_tools.pypi.PyPIClient") as MockClient:
103+
mock_client = MagicMock()
104+
MockClient.return_value = mock_client
105+
mock_client.get_ordered_versions.return_value = [Version("0.0.0.1")]
106+
107+
result = pu.get_version_info("azure-some-package", tag_is_stable=False)
108+
109+
assert result == ("0.0.0.1", "0.0.0.1")

0 commit comments

Comments
 (0)