Skip to content

Commit

Permalink
Remove use of pkg_resources from osrf_pycommon.
Browse files Browse the repository at this point in the history
Replace it with the use of the more modern importlib*
libraries.  There are a couple of reasons to do this:

1.  pkg_resources is quite slow to import; on my machine,
just firing up the python interpreter takes ~35ms, while
firing up the python interpreter and importing pkg_resources
takes ~175ms.  Firing up the python interpreter and importing
importlib_metadata takes ~70ms.  Removing 100ms per invocation
of the command-line both makes it speedier for users, and
will speed up our tests (which call out to the command-line
quite a lot).

2.  pkg_resources is somewhat deprecated and being replaced
by importlib.  https://importlib-metadata.readthedocs.io/en/latest/using.html
describes some of it

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Jun 24, 2020
1 parent ac6adfe commit dd283f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ python:
- "3.7"
- "3.8"
install:
- pip install coverage nose flake8 mock
- pip install coverage nose flake8 mock importlib-metadata
- pip install git+https://github.com/PyCQA/flake8-import-order.git
script:
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then COVER_INCLUSIVE=--cover-inclusive; fi
Expand Down
6 changes: 3 additions & 3 deletions osrf_pycommon/cli_utils/verb_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sys
import inspect

import pkg_resources
import importlib_metadata


def call_prepare_arguments(func, parser, sysargs=None):
Expand Down Expand Up @@ -149,7 +149,7 @@ def list_verbs(group):
:rtype: list of str
"""
verbs = []
for entry_point in pkg_resources.iter_entry_points(group=group):
for entry_point in importlib_metadata.entry_points().get(group, []):
verbs.append(entry_point.name)
return verbs

Expand All @@ -162,7 +162,7 @@ def load_verb_description(verb_name, group):
:returns: verb description
:rtype: dict
"""
for entry_point in pkg_resources.iter_entry_points(group=group):
for entry_point in importlib_metadata.entry_points().get(group, []):
if entry_point.name == verb_name:
return entry_point.load()

Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-mock</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-mock</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-importlib-metadata</exec_depend>

<export>
<build_type>ament_python</build_type>
Expand Down

0 comments on commit dd283f2

Please sign in to comment.