diff --git a/eng/tools/azure-sdk-tools/packaging_tools/package_utils.py b/eng/tools/azure-sdk-tools/packaging_tools/package_utils.py index 1a756197bbb0..1b5f197de532 100644 --- a/eng/tools/azure-sdk-tools/packaging_tools/package_utils.py +++ b/eng/tools/azure-sdk-tools/packaging_tools/package_utils.py @@ -1,6 +1,7 @@ import re import sys import os +from packaging.version import Version import ast import shutil from importlib.util import find_spec @@ -68,6 +69,11 @@ def get_version_info(package_name: str, tag_is_stable: bool = False) -> Tuple[st _LOGGER.warning(f"Failed to get version info from PyPI for {package_name}: {e}") last_version = "" last_stable_release = "" + + # Ignore 0.0.0 when it appears on PyPI as a placeholder or name-reservation version. + if last_version and Version(last_version).base_version == "0.0.0": + return "", "" + return last_version, str(last_stable_release) diff --git a/eng/tools/azure-sdk-tools/tests/test_package_utils.py b/eng/tools/azure-sdk-tools/tests/test_package_utils.py index c68d436b78c5..53d73a52e705 100644 --- a/eng/tools/azure-sdk-tools/tests/test_package_utils.py +++ b/eng/tools/azure-sdk-tools/tests/test_package_utils.py @@ -1,5 +1,7 @@ from pathlib import Path import os +from unittest.mock import patch, MagicMock +from packaging.version import Version try: import tomllib as toml @@ -69,3 +71,39 @@ def test_check_file_sets_is_stable_false_for_beta(tmp_path, monkeypatch): assert data["packaging"]["is_stable"] is False # title still populated assert data["packaging"]["title"] == "FooClient" + + +def test_get_version_info_treats_0_0_0_as_invalid(): + """get_version_info should return empty strings when the latest PyPI version is 0.0.0.""" + with patch("pypi_tools.pypi.PyPIClient") as MockClient: + mock_client = MagicMock() + MockClient.return_value = mock_client + mock_client.get_ordered_versions.return_value = [Version("0.0.0")] + + result = pu.get_version_info("azure-some-package", tag_is_stable=False) + + assert result == ("", "") + + +def test_get_version_info_treats_0_0_0_prerelease_as_invalid(): + """get_version_info should return empty strings when the latest PyPI version is 0.0.0b1.""" + with patch("pypi_tools.pypi.PyPIClient") as MockClient: + mock_client = MagicMock() + MockClient.return_value = mock_client + mock_client.get_ordered_versions.return_value = [Version("0.0.0b1")] + + result = pu.get_version_info("azure-some-package", tag_is_stable=False) + + assert result == ("", "") + + +def test_get_version_info_does_not_filter_0_0_0_1(): + """get_version_info should NOT filter 0.0.0.1 — its base version is not 0.0.0.""" + with patch("pypi_tools.pypi.PyPIClient") as MockClient: + mock_client = MagicMock() + MockClient.return_value = mock_client + mock_client.get_ordered_versions.return_value = [Version("0.0.0.1")] + + result = pu.get_version_info("azure-some-package", tag_is_stable=False) + + assert result == ("0.0.0.1", "0.0.0.1")