Skip to content

Commit

Permalink
fix deprecation warnings on 3.10+
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Sep 4, 2023
1 parent 6c9377c commit 2855861
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
17 changes: 7 additions & 10 deletions catkin_tools/commands/catkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.

import argparse
import functools
import os
import sys
from datetime import date
from shlex import quote as cmd_quote

from importlib.metadata import distribution, entry_points
import importlib.metadata

from catkin_tools.common import is_tty
Expand All @@ -27,28 +27,25 @@
from catkin_tools.terminal_color import fmt
from catkin_tools.terminal_color import set_color
from catkin_tools.terminal_color import test_colors
from catkin_tools.utils import entry_points

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
@functools.lru_cache(maxsize=None)
def _get_verb_entrypoints():
return list(entry_points(group=CATKIN_COMMAND_VERB_GROUP))


def list_verbs():
verbs = []
for entry_point in _get_entry_points().get(CATKIN_COMMAND_VERB_GROUP, []):
for entry_point in _get_verb_entrypoints():
verbs.append(entry_point.name)
return verbs


def load_verb_description(verb_name):
for entry_point in _get_entry_points().get(CATKIN_COMMAND_VERB_GROUP, []):
for entry_point in _get_verb_entrypoints():
if entry_point.name == verb_name:
return entry_point.load()

Expand Down
3 changes: 2 additions & 1 deletion catkin_tools/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .metadata import find_enclosing_workspace
from .resultspace import get_resultspace_environment
from .terminal_color import ColorMapper
from .utils import entry_points

color_mapper = ColorMapper()
clr = color_mapper.clr
Expand Down Expand Up @@ -122,7 +123,7 @@ class members and associated member functions based on available

from importlib.metadata import entry_points

for entry_point in entry_points().get(cls.CATKIN_SPACES_GROUP, []):
for entry_point in entry_points(group=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
11 changes: 11 additions & 0 deletions catkin_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
# limitations under the License.

import os
import sys


if sys.version_info >= (3, 10):
from importlib.metadata import entry_points
else:
import importlib.metadata

def entry_points(*, group):
for ep in importlib.metadata.entry_points().get(group, []):
yield ep


def which(program):
Expand Down
5 changes: 2 additions & 3 deletions catkin_tools/verbs/catkin_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import traceback
from queue import Queue

from importlib.metadata import entry_points

import yaml

try:
Expand All @@ -49,6 +47,7 @@
from catkin_tools.jobs.catkin import create_catkin_build_job
from catkin_tools.jobs.catkin import create_catkin_clean_job
from catkin_tools.jobs.catkin import get_prebuild_package
from catkin_tools.utils import entry_points

from .color import clr

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

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

from importlib.metadata import entry_points

from catkin_tools.terminal_color import fmt

try:
Expand All @@ -39,6 +37,7 @@
from catkin_tools.execution.controllers import ConsoleStatusController
from catkin_tools.execution.executor import execute_jobs
from catkin_tools.execution.executor import run_until_complete
from catkin_tools.utils import entry_points


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

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

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 All @@ -27,6 +25,7 @@
from catkin_tools.execution.controllers import ConsoleStatusController
from catkin_tools.execution.executor import execute_jobs
from catkin_tools.execution.executor import run_until_complete
from catkin_tools.utils import entry_points


def test_workspace(
Expand Down Expand Up @@ -87,7 +86,7 @@ def test_workspace(
# Get all build type plugins
test_job_creators = {
ep.name: ep.load()['create_test_job']
for ep in entry_points.get('catkin_tools.jobs', [])
for ep in entry_points(group='catkin_tools.jobs')
}

# It's a problem if there aren't any build types available
Expand Down

0 comments on commit 2855861

Please sign in to comment.