Skip to content

Commit

Permalink
fix: pkg_resources deprecated warning (#926)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott K Logan <[email protected]>
  • Loading branch information
SubaruArai and cottsay authored Apr 11, 2024
1 parent e48589c commit 3481576
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 8 additions & 3 deletions src/rosdep2/platforms/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion stdeb.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions test/test_rosdep_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3481576

Please sign in to comment.