Skip to content

Commit

Permalink
Switch from pkg_resources to packaging for version comparison (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
cottsay authored Jul 11, 2023
1 parent bed6cee commit 7b70e61
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
14 changes: 10 additions & 4 deletions colcon_core/package_identification/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,17 @@ def get_configuration(setup_cfg):
except ImportError:
from setuptools.config import read_configuration
except ImportError as e:
from pkg_resources import get_distribution
from pkg_resources import parse_version
setuptools_version = get_distribution('setuptools').version
try:
from importlib.metadata import distribution
except ImportError:
from importlib_metadata import distribution
from packaging.version import Version
try:
setuptools_version = distribution('setuptools').version
except ModuleNotFoundError:
setuptools_version = '0'
minimum_version = '30.3.0'
if parse_version(setuptools_version) < parse_version(minimum_version):
if Version(setuptools_version) < Version(minimum_version):
e.msg += ', ' \
"'setuptools' needs to be at least version " \
f'{minimum_version}, if a newer version is not available ' \
Expand Down
8 changes: 4 additions & 4 deletions colcon_core/plugin_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from colcon_core.entry_point import load_entry_points
from colcon_core.logging import colcon_logger
from pkg_resources import parse_version
from packaging.version import Version

logger = colcon_logger.getChild(__name__)

Expand Down Expand Up @@ -166,8 +166,8 @@ def satisfies_version(version, caret_range):
:raises RuntimeError: if the version doesn't match the caret range
"""
assert caret_range.startswith('^'), 'Only supports caret ranges'
extension_point_version = parse_version(version)
extension_version = parse_version(caret_range[1:])
extension_point_version = Version(version)
extension_version = Version(caret_range[1:])
next_extension_version = _get_upper_bound_caret_version(
extension_version)

Expand All @@ -192,4 +192,4 @@ def _get_upper_bound_caret_version(version):
minor = 0
else:
minor += 1
return parse_version('%d.%d.0' % (major, minor))
return Version('%d.%d.0' % (major, minor))
6 changes: 3 additions & 3 deletions colcon_core/task/python/test/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from colcon_core.task.python.test import has_test_dependency
from colcon_core.task.python.test import PythonTestingStepExtensionPoint
from colcon_core.verb.test import logger
from pkg_resources import parse_version
from packaging.version import Version


class PytestPythonTestingStep(PythonTestingStepExtensionPoint):
Expand Down Expand Up @@ -64,7 +64,7 @@ async def step(self, context, env, setup_py_data): # noqa: D102
# use -o option only when available
# https://github.com/pytest-dev/pytest/blob/3.3.0/CHANGELOG.rst
from pytest import __version__ as pytest_version
if parse_version(pytest_version) >= parse_version('3.3.0'):
if Version(pytest_version) >= Version('3.3.0'):
args += [
'-o', 'cache_dir=' + str(PurePosixPath(
*(Path(context.args.build_base).parts)) / '.pytest_cache'),
Expand Down Expand Up @@ -95,7 +95,7 @@ async def step(self, context, env, setup_py_data): # noqa: D102
]
# use --cov-branch option only when available
# https://github.com/pytest-dev/pytest-cov/blob/v2.5.0/CHANGELOG.rst
if parse_version(pytest_cov_version) >= parse_version('2.5.0'):
if Version(pytest_cov_version) >= Version('2.5.0'):
args += [
'--cov-branch',
]
Expand Down
6 changes: 3 additions & 3 deletions debian/patches/setup.cfg.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Author: Dirk Thomas <web@dirk-thomas.net>

--- setup.cfg 2018-05-27 11:22:33.000000000 -0700
+++ setup.cfg.patched 2018-05-27 11:22:33.000000000 -0700
@@ -31,9 +31,12 @@
distlib
EmPy
@@ -33,9 +33,12 @@
importlib-metadata; python_version < "3.8"
packaging
pytest
- pytest-cov
- pytest-repeat
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ install_requires =
coloredlogs; sys_platform == 'win32'
distlib
EmPy
importlib-metadata; python_version < "3.8"
packaging
# the pytest dependency and its extensions are provided for convenience
# even though they are only conditional
pytest
Expand Down
1 change: 1 addition & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ hardcodes
hookimpl
hookwrapper
https
importlib
isatty
iterdir
junit
Expand Down

0 comments on commit 7b70e61

Please sign in to comment.