Skip to content

Commit 590e31d

Browse files
committed
Add 'migrations' to the docs. Ref #368.
1 parent 4360304 commit 590e31d

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The documentation here includes a general :ref:`usage <using>` guide.
2525

2626
using
2727
api
28+
migration
2829
history
2930

3031

docs/migration.rst

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
.. _migration:
2+
3+
=================
4+
Migration guide
5+
=================
6+
7+
The following guide will help you migrate common ``pkg_resources``
8+
APIs to ``importlib_metadata``. ``importlib_metadata`` aims to
9+
replace the following ``pkg_resources`` APIs:
10+
11+
* ``pkg_resources.iter_entry_points()``
12+
* ``pkg_resources.require()``
13+
* convenience functions
14+
* ``pkg_resources.find_distributions()``
15+
* ``pkg_resources.get_distribution()``
16+
17+
Other functionality from ``pkg_resources`` is replaced by other
18+
packages such as
19+
`importlib_resources <https://pypi.org/project/importlib_resources>`_
20+
and `packaging <https://pypi.org/project/packaging>`_.
21+
22+
23+
pkg_resources.iter_entry_points()
24+
=================================
25+
26+
``importlib_metadata`` provides :ref:`entry-points`.
27+
28+
Compatibility note: entry points provided by importlib_metadata
29+
do not have the following implicit behaviors found in those
30+
from ``pkg_resources``:
31+
32+
- Each EntryPoint is not automatically validated to match. To
33+
ensure each one is validated, invoke any property on the
34+
object (e.g. ``ep.name``).
35+
36+
- When invoking ``EntryPoint.load()``, no checks are performed
37+
to ensure the declared extras are installed. If this behavior
38+
is desired/required, it is left to the user to perform the
39+
check and install any dependencies. See
40+
`importlib_metadata#368 <https://github.com/python/importlib_metadata/issues/368>`_
41+
for more details.
42+
43+
pkg_resources.require()
44+
=======================
45+
46+
``importlib_metadata`` does not provide support for dynamically
47+
discovering or requiring distributions nor does it provide any
48+
support for managing the "working set". Furthermore,
49+
``importlib_metadata`` assumes that only one version of a given
50+
distribution is discoverable at any time (no support for multi-version
51+
installs). Any projects that require the above behavior needs to
52+
provide that behavior independently.
53+
54+
``importlib_metadata`` does aim to resolve metadata concerns late
55+
such that any dynamic changes to package availability should be
56+
reflected immediately.
57+
58+
Convenience functions
59+
=====================
60+
61+
In addition to the support for direct access to ``Distribution``
62+
objects (below), ``importlib_metadata`` presents some top-level
63+
functions for easy access to the most common metadata:
64+
65+
- :ref:`metadata` queries the metadata fields from the distribution.
66+
- :ref:`version` provides quick access to the distribution version.
67+
- :ref:`requirements` presents the requirements of the distribution.
68+
- :ref:`files` provides file-like access to the data blobs backing
69+
the metadata.
70+
71+
pkg_resources.find_distributions()
72+
==================================
73+
74+
``importlib_metadata`` provides functionality
75+
similar to ``find_distributions()``. Both ``distributions(...)`` and
76+
``Distribution.discover(...)`` return an iterable of :ref:`distributions`
77+
matching the indicated parameters.
78+
79+
pkg_resources.get_distribution()
80+
=================================
81+
82+
Similar to ``distributions``, the ``distribution()`` function provides
83+
access to a single distribution by name.
84+

docs/using.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ Python packages or modules::
243243
>>> packages_distributions()
244244
{'importlib_metadata': ['importlib-metadata'], 'yaml': ['PyYAML'], 'jaraco': ['jaraco.classes', 'jaraco.functools'], ...}
245245

246+
.. _distributions:
246247

247248
Distributions
248249
=============

0 commit comments

Comments
 (0)