Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# - src/rosdistro/__init__.py
# - stdeb.cfg
'version': '1.0.1',
'install_requires': ['PyYAML', 'setuptools'],
'install_requires': ['packaging>=16.8.0', 'PyYAML', 'setuptools'],
'python_requires': '>=3.6',
'packages': find_packages('src'),
'package_dir': {'': 'src'},
Expand Down
38 changes: 36 additions & 2 deletions src/rosdistro/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,40 @@
import re
import subprocess

from distutils.version import LooseVersion
from packaging.version import parse, InvalidVersion
try:
from packaging.version import LegacyVersion
packaging_lte_22 = True
except ImportError:
packaging_lte_22 = False


def _version_gte(version: str, required_version: str) -> bool:
"""Check if a version string is greater than or equal to a required version.

Args:
version: The version string to check.
required_version: The required version string.

Returns:
True if the version is greater than or equal to the required version, False otherwise.
"""
try:
parsed_version = parse(version)
if packaging_lte_22:
# In packaging 22.0 and earlier, parse() returns a LegacyVersion for non-standard version strings,
# which will compare greater than any valid version. We want to raise an error instead.
if isinstance(parsed_version, LegacyVersion):
raise InvalidVersion
except InvalidVersion:
if "windows" in version.lower():
# Git for Windows uses a non-standard version string
version = version.lower().replace("windows", "post").strip()
parsed_version = parse(version)
else:
raise

return parsed_version >= parse(required_version)


class Git(object):
Expand All @@ -57,7 +90,8 @@ def version_gte(cls, version):
if not cls._client_version:
result = cls().command('--version')
cls._client_version = result['output'].split()[-1]
return LooseVersion(cls._client_version) >= LooseVersion(version)

return _version_gte(cls._client_version, version)


def ref_is_hash(ref):
Expand Down
4 changes: 2 additions & 2 deletions stdeb.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Debian-Version: 100
; rosdistro-modules same version as in:
; - setup.py
; - src/rosdistro/__init__.py
Depends3: ca-certificates, python3-rosdistro-modules (>= 1.0.1), python3-setuptools, python3-yaml
Depends3: ca-certificates, python3-packaging (>=16.8.0), python3-rosdistro-modules (>= 1.0.1), python3-setuptools, python3-yaml
Conflicts3: python-rosdistro
Copyright-File: LICENSE.txt
Suite3: focal jammy noble bookworm trixie
Expand All @@ -12,7 +12,7 @@ X-Python3-Version: >= 3.6
Setup-Env-Vars: SKIP_PYTHON_MODULES=1

[rosdistro_modules]
Depends3: ca-certificates, python3-catkin-pkg-modules, python3-rospkg-modules, python3-setuptools, python3-yaml
Depends3: ca-certificates, python3-catkin-pkg-modules, python3-packaging (>=16.8.0), python3-rospkg-modules, python3-setuptools, python3-yaml
Conflicts3: python3-rosdistro (<< 0.6.0)
Replaces3: python3-rosdistro (<< 0.6.0)
Copyright-File: LICENSE.txt
Expand Down
20 changes: 20 additions & 0 deletions test/test_vcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from rosdistro.vcs import _version_gte

import pytest

@pytest.mark.parametrize("version, required_version, expected", [
("2.50.0", "2.51.0", False),
("2.51.0", "2.51.0", True),
("2.52.0", "2.51.0", True),
("2.51.0-rc1", "2.51.0", False),
("2.51.0-rc1", "2.51.0-rc1", True),
("2.51.0-rc1", "2.51.0-rc2", False),
("2.51.0-rc1", "2.51.0-rc0", True),
("2.51.0-rc1", "2.51.0-rc0+post1", True),
("2.51.0-rc1", "2.51.0-rc1+post1", False),
("2.51.0.windows.1", "2.50.0", True),
("2.51.0.windows.1", "2.51.0", True),
("2.51.0.windows.1", "2.52", False),
])
def test_version_gte(version: str, required_version: str, expected: bool):
assert _version_gte(version, required_version) == expected