Skip to content

Commit

Permalink
Use single call to importlib.metadata.entry_points for all groups
Browse files Browse the repository at this point in the history
  • Loading branch information
timonegk committed Sep 4, 2023
1 parent b49a395 commit 539c9be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
10 changes: 2 additions & 8 deletions catkin_tools/commands/catkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import argparse
import functools
import importlib.metadata
import os
import sys
Expand All @@ -31,20 +30,15 @@
CATKIN_COMMAND_VERB_GROUP = 'catkin_tools.commands.catkin.verbs'


@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_verb_entrypoints():
for entry_point in entry_points(group=CATKIN_COMMAND_VERB_GROUP):
verbs.append(entry_point.name)
return verbs


def load_verb_description(verb_name):
for entry_point in _get_verb_entrypoints():
for entry_point in entry_points(group=CATKIN_COMMAND_VERB_GROUP):
if entry_point.name == verb_name:
return entry_point.load()

Expand Down
18 changes: 11 additions & 7 deletions catkin_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import functools
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 entry_points(*, group):
@functools.lru_cache(maxsize=None)
def _entry_points():
from importlib.metadata import entry_points
return entry_points()

if sys.version_info >= (3, 10):
return _entry_points().select(group=group)
else:
return _entry_points().get(group, [])


def which(program):
Expand Down

0 comments on commit 539c9be

Please sign in to comment.