From ab3aa90387ebe9823160dcf828c0a7f1f1a461ab Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Thu, 23 Apr 2020 14:20:18 +0000 Subject: [PATCH 1/5] Remove use of pkg_resources from osrf_pycommon. 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 --- .travis.yml | 2 +- osrf_pycommon/cli_utils/verb_pattern.py | 6 +++--- package.xml | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f27d8a..c988426 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,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: - PYTHONASYNCIODEBUG=1 python setup.py nosetests -s --with-coverage --cover-inclusive diff --git a/osrf_pycommon/cli_utils/verb_pattern.py b/osrf_pycommon/cli_utils/verb_pattern.py index 8259db9..22fe6d0 100644 --- a/osrf_pycommon/cli_utils/verb_pattern.py +++ b/osrf_pycommon/cli_utils/verb_pattern.py @@ -17,7 +17,7 @@ import sys import inspect -import pkg_resources +import importlib_metadata def call_prepare_arguments(func, parser, sysargs=None): @@ -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 @@ -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() diff --git a/package.xml b/package.xml index 605b7f4..95d3e8c 100644 --- a/package.xml +++ b/package.xml @@ -10,6 +10,7 @@ Apache License 2.0 + python3-importlib-metadata python3-mock From fd238ad726c74050ef63575eb3ca4f6e074edf2e Mon Sep 17 00:00:00 2001 From: William Woodall Date: Tue, 27 Jul 2021 18:53:50 -0700 Subject: [PATCH 2/5] depend on importlib-metadata everywhere Signed-off-by: William Woodall --- setup.py | 4 ++++ stdeb.cfg | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ef27a87..2fe9ed9 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +import sys + from setuptools import find_packages from setuptools import setup @@ -5,6 +7,8 @@ install_requires = [ 'setuptools', ] +if sys.version_info < (3, 8): + install_requires.append('importlib-metadata') package_excludes = ['tests*', 'docs*'] packages = find_packages(exclude=package_excludes) diff --git a/stdeb.cfg b/stdeb.cfg index 4477cac..89ffe79 100644 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -1,5 +1,5 @@ [DEFAULT] -Depends3: python3-setuptools +Depends3: python3-setuptools, python3-importlib-metadata Conflicts3: python-osrf-pycommon Suite3: xenial yakkety zesty artful bionic cosmic disco eoan focal stretch buster X-Python3-Version: >= 3.5 From 9e2ffde2f9e257a8932a04646b9b11f6cd2f7e5f Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Mon, 29 Nov 2021 20:47:54 +0000 Subject: [PATCH 3/5] Fixes from review. Signed-off-by: Chris Lalancette --- osrf_pycommon/cli_utils/verb_pattern.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osrf_pycommon/cli_utils/verb_pattern.py b/osrf_pycommon/cli_utils/verb_pattern.py index 22fe6d0..a992388 100644 --- a/osrf_pycommon/cli_utils/verb_pattern.py +++ b/osrf_pycommon/cli_utils/verb_pattern.py @@ -17,7 +17,10 @@ import sys import inspect -import importlib_metadata +try: + import importlib.metadata as importlib_metadata +except ModuleNotFoundError: + import importlib_metadata def call_prepare_arguments(func, parser, sysargs=None): From 87f674aa8f0019265741425f45dfb9f1a0b48483 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Tue, 1 Feb 2022 14:47:30 -0800 Subject: [PATCH 4/5] restrict suites to only include ones that have python3-importlib-metadata Signed-off-by: William Woodall --- stdeb.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdeb.cfg b/stdeb.cfg index ac9d491..8bb9ed1 100644 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -1,6 +1,6 @@ [DEFAULT] Depends3: python3-setuptools, python3-importlib-metadata Conflicts3: python-osrf-pycommon -Suite3: bionic cosmic disco eoan focal jammy buster bullseye -X-Python3-Version: >= 3.5 +Suite3: focal jammy buster bullseye +X-Python3-Version: >= 3.8 No-Python2: From 77cee0791f1952d9e7fdc346c169decb1079a101 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Tue, 1 Feb 2022 14:54:20 -0800 Subject: [PATCH 5/5] add note to README about release changes Signed-off-by: William Woodall --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 9b034e8..20f1695 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,9 @@ osrf_pycommon Commonly needed Python modules, used by Python software developed at OSRF. +Branches +======== + +If you are releasing (using ``stdeb`` or on the ROS buildfarm) for any Ubuntu < ``focal``, or for any OS that doesn't have a key for ``python3-importlib-metadata``, then you need to use the ``1.0.x`` branch, or the latest ``1.`` branch, because starting with ``2.0.0``, that dependency will be required. + If you are using Python 2, then you should use the ``python2`` branch.