Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pkg_resources by importlib.metadata #766

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions catkin_tools/commands/catkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from datetime import date
from shlex import quote as cmd_quote

import pkg_resources
from importlib.metadata import entry_points, version

from catkin_tools.common import is_tty
from catkin_tools.config import get_verb_aliases
Expand All @@ -29,16 +29,25 @@

CATKIN_COMMAND_VERB_GROUP = 'catkin_tools.commands.catkin.verbs'

ENTRY_POINTS = None


def _get_entry_points():
global ENTRY_POINTS
if ENTRY_POINTS is None:
ENTRY_POINTS = entry_points()
return ENTRY_POINTS


def list_verbs():
verbs = []
for entry_point in pkg_resources.iter_entry_points(group=CATKIN_COMMAND_VERB_GROUP):
for entry_point in _get_entry_points().select(CATKIN_COMMAND_VERB_GROUP):
verbs.append(entry_point.name)
return verbs


def load_verb_description(verb_name):
for entry_point in pkg_resources.iter_entry_points(group=CATKIN_COMMAND_VERB_GROUP):
for entry_point in _get_entry_points().select(CATKIN_COMMAND_VERB_GROUP):
if entry_point.name == verb_name:
return entry_point.load()

Expand Down Expand Up @@ -184,7 +193,7 @@ def catkin_main(sysargs):
# Check for version
if '--version' in sysargs:
print('catkin_tools {} (C) 2014-{} Open Source Robotics Foundation'.format(
pkg_resources.get_distribution('catkin_tools').version,
version('catkin_tools'),
date.today().year)
)
print('catkin_tools is released under the Apache License,'
Expand Down
4 changes: 2 additions & 2 deletions catkin_tools/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ class members and associated member functions based on available
if cls.KEYS:
return

from pkg_resources import iter_entry_points
from importlib.metadata import entry_points

for entry_point in iter_entry_points(group=cls.CATKIN_SPACES_GROUP):
for entry_point in entry_points().select(cls.CATKIN_SPACES_GROUP):
ep_dict = entry_point.load()
cls.STORED_KEYS.append(entry_point.name + '_space')
cls.SPACES[entry_point.name] = ep_dict
Expand Down
5 changes: 3 additions & 2 deletions catkin_tools/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import os
import shutil

import pkg_resources
from importlib.metadata import version

import yaml

from .common import mkdir_p
Expand Down Expand Up @@ -138,7 +139,7 @@ def migrate_metadata(workspace_path):

# Check metadata version
last_version = None
current_version = pkg_resources.require("catkin_tools")[0].version
current_version = version("catkin_tools")
version_file_path = os.path.join(metadata_root_path, 'VERSION')

# Read the VERSION file
Expand Down
5 changes: 3 additions & 2 deletions catkin_tools/verbs/catkin_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import traceback
from queue import Queue

import pkg_resources
from importlib.metadata import entry_points

import yaml

try:
Expand Down Expand Up @@ -480,7 +481,7 @@ def build_isolated_workspace(
# Get all build type plugins
build_job_creators = {
ep.name: ep.load()['create_build_job']
for ep in pkg_resources.iter_entry_points(group='catkin_tools.jobs')
for ep in entry_points().select('catkin_tools.jobs')
}

# It's a problem if there aren't any build types available
Expand Down
4 changes: 2 additions & 2 deletions catkin_tools/verbs/catkin_clean/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import traceback
from queue import Queue

import pkg_resources
from importlib.metadata import entry_points

from catkin_tools.terminal_color import fmt

Expand Down Expand Up @@ -126,7 +126,7 @@ def clean_packages(
# Get all build type plugins
clean_job_creators = {
ep.name: ep.load()['create_clean_job']
for ep in pkg_resources.iter_entry_points(group='catkin_tools.jobs')
for ep in entry_points().select('catkin_tools.jobs')
}

# It's a problem if there aren't any build types available
Expand Down
5 changes: 3 additions & 2 deletions catkin_tools/verbs/catkin_test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import traceback
from queue import Queue

import pkg_resources
from importlib.metadata import entry_points

from catkin_pkg.package import InvalidPackage
from catkin_pkg.packages import find_packages
from catkin_pkg.topological_order import topological_order_packages
Expand Down Expand Up @@ -86,7 +87,7 @@ def test_workspace(
# Get all build type plugins
test_job_creators = {
ep.name: ep.load()['create_test_job']
for ep in pkg_resources.iter_entry_points(group='catkin_tools.jobs')
for ep in entry_points().select('catkin_tools.jobs')
}

# It's a problem if there aren't any build types available
Expand Down
3 changes: 1 addition & 2 deletions docs/development/adding_build_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Regardless of what package the ``entry_point`` is defined in, it will be defined
This entry in the ``setup.py`` places a file in the ``PYTHONPATH`` when either the ``install`` or the ``develop`` verb is given to ``setup.py``.
This file relates the key (in this case ``mybuild``) to a module and attribute (in this case ``my_package.some.module`` and ``description``).

Then the ``catkin`` command will use the ``pkg_resources`` modules to retrieve these mapping at run time.
Then the ``catkin`` command will use the ``importlib.metadata`` modules to retrieve these mapping at run time.
Any entry for the ``catkin_tools.jobs`` group must point to a ``description`` attribute of a module, where the ``description`` attribute is a ``dict``.
The ``description`` ``dict`` should take this form:

Expand Down Expand Up @@ -63,4 +63,3 @@ The signature of the factory callable should be similar to the following:
jid=package.name,
deps=dependencies,
stages=stages)

2 changes: 1 addition & 1 deletion docs/development/extending_the_catkin_command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Regardless of what package the ``entry_point`` is defined in, it will be defined

This entry in the ``setup.py`` places a file in the ``PYTHONPATH`` when either the ``install`` or the ``develop`` verb is given to ``setup.py``.
This file relates the key (in this case ``my_verb``) to a module and attribute (in this case ``my_package.some.module`` and ``description``).
Then the ``catkin`` command will use the ``pkg_resources`` modules to retrieve these mapping at run time.
Then the ``catkin`` command will use the ``importlib.metadata`` modules to retrieve these mapping at run time.
Any entry for the ``catkin_tools.commands.catkin.verbs`` group must point to a ``description`` attribute of a module, where the ``description`` attribute is a ``dict``.
The ``description`` ``dict`` should take this form (the description from the ``build`` verb for example):

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def run(self):
setup(
name='catkin_tools',
version='0.9.4',
python_requires='>=3.5',
python_requires='>=3.8',
packages=find_packages(exclude=['tests*', 'docs']),
package_data={
'catkin_tools': [
Expand Down
Loading