Skip to content

Commit 6dcefad

Browse files
committed
chore: update to using importlib.metadata for entry_points
1 parent 20ac086 commit 6dcefad

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@
393393
nitpick_ignore = [
394394
('envvar', 'PATH'),
395395
('py:func', 'find_packages'),
396-
('py:func', 'pkg_resources.iter_entry_points'),
397396
('py:func', 'setup'),
397+
('py:func', 'importlib.metadata.entry_points'), # remove when 3.10 is released
398398
('py:func', 'setuptools.find_namespace_packages'),
399399
('py:func', 'setuptools.find_packages'),
400400
('py:func', 'setuptools.setup'),

source/guides/creating-and-discovering-plugins.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,19 @@ in its :file:`setup.py`:
136136
)
137137
138138
Then you can discover and load all of the registered entry points by using
139-
:func:`pkg_resources.iter_entry_points`:
139+
:func:`importlib.metadata.entry_points` (or the `backport`_
140+
``importlib_metadata >= 3.6`` for Python 3.6-3.9):
140141

141142
.. code-block:: python
142143
143-
import pkg_resources
144+
import sys
145+
if sys.version_info < (3, 10):
146+
from importlib_metadata import entry_points
147+
else:
148+
from importlib.metadata import entry_points
149+
150+
discovered_plugins = entry_points(group='myapp.plugins')
144151
145-
discovered_plugins = {
146-
entry_point.name: entry_point.load()
147-
for entry_point
148-
in pkg_resources.iter_entry_points('myapp.plugins')
149-
}
150152
151153
In this example, ``discovered_plugins`` would be:
152154

@@ -160,7 +162,9 @@ In this example, ``discovered_plugins`` would be:
160162
flexible and has a lot of options. It's recommended to read over the entire
161163
section on `entry points`_.
162164

163-
.. _Setuptools: http://setuptools.readthedocs.io
165+
.. _Setuptools: https://setuptools.readthedocs.io
164166
.. _special support:
165167
.. _entry points:
166-
http://setuptools.readthedocs.io/en/latest/setuptools.html#dynamic-discovery-of-services-and-plugins
168+
https://setuptools.readthedocs.io/en/latest/setuptools.html#dynamic-discovery-of-services-and-plugins
169+
.. _backport: https://importlib-metadata.readthedocs.io/en/latest/
170+

source/specifications/entry-points.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ example:
1818

1919
The entry point file format was originally developed to allow packages built
2020
with setuptools to provide integration point metadata that would be read at
21-
runtime with ``pkg_resources``. It is now defined as a PyPA interoperability
21+
runtime with ``importlib.metadata``. It is now defined as a PyPA interoperability
2222
specification in order to allow build tools other than setuptools to publish
23-
``pkg_resources`` compatible entry point metadata, and runtime libraries other
24-
than ``pkg_resources`` to portably read published entry point metadata
23+
``importlib.metadata`` compatible entry point metadata, and runtime libraries other
24+
than ``importlib.metadata`` to portably read published entry point metadata
2525
(potentially with different caching and conflict resolution strategies).
2626

2727
Data model

0 commit comments

Comments
 (0)