From a9ea801a43fc62a569cf60e1c28e477ba510d8a0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 10 Feb 2022 21:58:57 -0500 Subject: [PATCH 1/6] Require jaraco.packaging 9 adding compatibility for projects with no setup.py file. --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 1b048af5..3b7ac309 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,7 +45,7 @@ testing = docs = # upstream sphinx - jaraco.packaging >= 8.2 + jaraco.packaging >= 9 rst.linker >= 1.9 # local From f22eb5b60adbe158e458614ea0380a9071c39347 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Sat, 12 Feb 2022 09:50:31 +0000 Subject: [PATCH 2/6] Ignore flake8/black warnings with pytest 7.0.1 (jaraco/skeleton#58) --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytest.ini b/pytest.ini index b6880c88..80e98cc9 100644 --- a/pytest.ini +++ b/pytest.ini @@ -9,7 +9,9 @@ filterwarnings= # shopkeep/pytest-black#55 ignore: is not using a cooperative constructor:pytest.PytestDeprecationWarning ignore:The \(fspath. py.path.local\) argument to BlackItem is deprecated.:pytest.PytestDeprecationWarning + ignore:BlackItem is an Item subclass and should not be a collector:pytest.PytestWarning # tholo/pytest-flake8#83 ignore: is not using a cooperative constructor:pytest.PytestDeprecationWarning ignore:The \(fspath. py.path.local\) argument to Flake8Item is deprecated.:pytest.PytestDeprecationWarning + ignore:Flake8Item is an Item subclass and should not be a collector:pytest.PytestWarning From 04fe68a96ee8e3d3ca521b4abbfe53203063f9d9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 19 Feb 2022 21:14:39 -0500 Subject: [PATCH 3/6] Ran pre-commit autoupdate --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f66bf563..edf6f55f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 22.1.0 hooks: - id: black From 590e31dad1afceb6e0d55908e876ef5d05ae721b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 26 Feb 2022 16:33:15 -0500 Subject: [PATCH 4/6] Add 'migrations' to the docs. Ref #368. --- docs/index.rst | 1 + docs/migration.rst | 84 ++++++++++++++++++++++++++++++++++++++++++++++ docs/using.rst | 1 + 3 files changed, 86 insertions(+) create mode 100644 docs/migration.rst diff --git a/docs/index.rst b/docs/index.rst index ef47c49c..168f7fbc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -25,6 +25,7 @@ The documentation here includes a general :ref:`usage ` guide. using api + migration history diff --git a/docs/migration.rst b/docs/migration.rst new file mode 100644 index 00000000..3c700778 --- /dev/null +++ b/docs/migration.rst @@ -0,0 +1,84 @@ +.. _migration: + +================= + Migration guide +================= + +The following guide will help you migrate common ``pkg_resources`` +APIs to ``importlib_metadata``. ``importlib_metadata`` aims to +replace the following ``pkg_resources`` APIs: + +* ``pkg_resources.iter_entry_points()`` +* ``pkg_resources.require()`` +* convenience functions +* ``pkg_resources.find_distributions()`` +* ``pkg_resources.get_distribution()`` + +Other functionality from ``pkg_resources`` is replaced by other +packages such as +`importlib_resources `_ +and `packaging `_. + + +pkg_resources.iter_entry_points() +================================= + +``importlib_metadata`` provides :ref:`entry-points`. + +Compatibility note: entry points provided by importlib_metadata +do not have the following implicit behaviors found in those +from ``pkg_resources``: + +- Each EntryPoint is not automatically validated to match. To + ensure each one is validated, invoke any property on the + object (e.g. ``ep.name``). + +- When invoking ``EntryPoint.load()``, no checks are performed + to ensure the declared extras are installed. If this behavior + is desired/required, it is left to the user to perform the + check and install any dependencies. See + `importlib_metadata#368 `_ + for more details. + +pkg_resources.require() +======================= + +``importlib_metadata`` does not provide support for dynamically +discovering or requiring distributions nor does it provide any +support for managing the "working set". Furthermore, +``importlib_metadata`` assumes that only one version of a given +distribution is discoverable at any time (no support for multi-version +installs). Any projects that require the above behavior needs to +provide that behavior independently. + +``importlib_metadata`` does aim to resolve metadata concerns late +such that any dynamic changes to package availability should be +reflected immediately. + +Convenience functions +===================== + +In addition to the support for direct access to ``Distribution`` +objects (below), ``importlib_metadata`` presents some top-level +functions for easy access to the most common metadata: + +- :ref:`metadata` queries the metadata fields from the distribution. +- :ref:`version` provides quick access to the distribution version. +- :ref:`requirements` presents the requirements of the distribution. +- :ref:`files` provides file-like access to the data blobs backing + the metadata. + +pkg_resources.find_distributions() +================================== + +``importlib_metadata`` provides functionality +similar to ``find_distributions()``. Both ``distributions(...)`` and +``Distribution.discover(...)`` return an iterable of :ref:`distributions` +matching the indicated parameters. + +pkg_resources.get_distribution() +================================= + +Similar to ``distributions``, the ``distribution()`` function provides +access to a single distribution by name. + diff --git a/docs/using.rst b/docs/using.rst index d60cfaa6..5d8f0a3c 100644 --- a/docs/using.rst +++ b/docs/using.rst @@ -243,6 +243,7 @@ Python packages or modules:: >>> packages_distributions() {'importlib_metadata': ['importlib-metadata'], 'yaml': ['PyYAML'], 'jaraco': ['jaraco.classes', 'jaraco.functools'], ...} +.. _distributions: Distributions ============= From b4661fd8988b4101d4042e4cc4a8ed74423ec410 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 26 Feb 2022 17:47:38 -0500 Subject: [PATCH 5/6] Add test capturing missed expectation on extras. Ref #369. --- importlib_metadata/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 989a461c..3717c8f3 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -157,6 +157,15 @@ class EntryPoint(DeprecatedTuple): See `the packaging docs on entry points `_ for more information. + + >>> ep = EntryPoint( + ... name=None, group=None, value='package.module:attr [extra1, extra2]') + >>> ep.module + 'package.module' + >>> ep.attr + 'attr' + >>> ep.extras + ['extra1', 'extra2'] """ pattern = re.compile( From 14cce75299645467adcd17352cb07caada32c444 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 26 Feb 2022 17:48:50 -0500 Subject: [PATCH 6/6] Prefer re.findall, which returns materialized results. Fixes #369. --- CHANGES.rst | 6 ++++++ importlib_metadata/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8499e422..fde89269 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v4.11.2 +======= + +* #369: Fixed bug where ``EntryPoint.extras`` was returning + match objects and not the extras strings. + v4.11.1 ======= diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 3717c8f3..045881b3 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -217,7 +217,7 @@ def attr(self): @property def extras(self): match = self.pattern.match(self.value) - return list(re.finditer(r'\w+', match.group('extras') or '')) + return re.findall(r'\w+', match.group('extras') or '') def _for(self, dist): vars(self).update(dist=dist)