diff --git a/setup.py b/setup.py index 3605adbf7..135822ae6 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,10 @@ 'version': '0.22.2', 'packages': ['rosdep2', 'rosdep2.ament_packages', 'rosdep2.platforms'], 'package_dir': {'': 'src'}, - 'install_requires': ['PyYAML >= 3.1', 'setuptools'], + 'install_requires': [ + 'PyYAML >= 3.1', + 'importlib_metadata; python_version<"3.8"' + ], 'extras_require': { 'test': [ 'flake8 < 6', diff --git a/src/rosdep2/platforms/pip.py b/src/rosdep2/platforms/pip.py index 8dfbb6927..8ca4ba03a 100644 --- a/src/rosdep2/platforms/pip.py +++ b/src/rosdep2/platforms/pip.py @@ -30,10 +30,14 @@ from __future__ import print_function import os -import pkg_resources import subprocess import sys +try: + import importlib.metadata as importlib_metadata +except ImportError: + import importlib_metadata + from ..core import InstallFailed from ..installers import PackageManagerInstaller from ..shell_utils import read_stdout @@ -130,8 +134,9 @@ def __init__(self): super(PipInstaller, self).__init__(pip_detect, supports_depends=True) def get_version_strings(self): - pip_version = pkg_resources.get_distribution('pip').version - setuptools_version = pkg_resources.get_distribution('setuptools').version + pip_version = importlib_metadata.version('pip') + # keeping the name "setuptools" for backward compatibility + setuptools_version = importlib_metadata.version('setuptools') version_strings = [ 'pip {}'.format(pip_version), 'setuptools {}'.format(setuptools_version), diff --git a/stdeb.cfg b/stdeb.cfg index 64ccdd45b..67d1bb204 100644 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -18,7 +18,7 @@ Setup-Env-Vars: SKIP_PYTHON_MODULES=1 [rosdep_modules] Depends: ca-certificates, python-rospkg-modules (>= 1.4.0), python-yaml, python-catkin-pkg-modules (>= 0.4.0), python-rosdistro-modules (>= 0.7.5), python-setuptools, sudo -Depends3: ca-certificates, python3-rospkg-modules (>= 1.4.0), python3-yaml, python3-catkin-pkg-modules (>= 0.4.0), python3-rosdistro-modules (>= 0.7.5), python3-setuptools, sudo +Depends3: ca-certificates, python3-rospkg-modules (>= 1.4.0), python3-yaml, python3-catkin-pkg-modules (>= 0.4.0), python3-rosdistro-modules (>= 0.7.5), python3 (>= 3.8) | python3-importlib-metadata, sudo Conflicts: python-rosdep (<< 0.18.0), python-rosdep2 Conflicts3: python3-rosdep (<< 0.18.0), python3-rosdep2 Replaces: python-rosdep (<< 0.18.0) diff --git a/test/test_rosdep_pip.py b/test/test_rosdep_pip.py index 34840ce1c..2b3a3ba88 100644 --- a/test/test_rosdep_pip.py +++ b/test/test_rosdep_pip.py @@ -114,6 +114,13 @@ def test(expected_prefix, mock_method, mock_get_pip_command): raise +def test_PipInstaller_get_version_strings(): + from rosdep2.platforms.pip import PipInstaller + + installer = PipInstaller() + assert installer.get_version_strings() + + def test_get_pip_command(): from rosdep2.platforms.pip import get_pip_command