Skip to content

Commit 4ff9dcc

Browse files
committed
Clarify import vs distribution package terms in using.rst
1 parent e622499 commit 4ff9dcc

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

docs/using.rst

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44
Using :mod:`!importlib_metadata`
55
=================================
66

7-
``importlib_metadata`` is a library that provides access to installed
8-
package metadata, such as its entry points or its
9-
top-level name. Built in part on Python's import system, this library
7+
``importlib_metadata`` is a library that provides access to
8+
the metadata of an installed distribution package, such as its entry points
9+
or its top-level import package name.
10+
Built in part on Python's import system, this library
1011
intends to replace similar functionality in the `entry point
1112
API`_ and `metadata API`_ of ``pkg_resources``. Along with
1213
:mod:`importlib.resources`,
1314
this package can eliminate the need to use the older and less efficient
1415
``pkg_resources`` package.
1516

16-
By "installed package" we generally mean a third-party package installed into
17-
Python's ``site-packages`` directory via tools such as `pip
17+
By "installed package", we generally mean a third-party distribution package
18+
installed into Python's ``site-packages`` directory via tools such as `pip
1819
<https://pypi.org/project/pip/>`_. Specifically,
19-
it means a package with either a discoverable ``dist-info`` or ``egg-info``
20+
it means a distribution with either a discoverable ``dist-info`` or ``egg-info``
2021
directory, and metadata defined by :pep:`566` or its older specifications.
21-
By default, package metadata can live on the file system or in zip archives on
22+
By default, distribution metadata can live on the file system
23+
or in zip archives on
2224
:data:`sys.path`. Through an extension mechanism, the metadata can live almost
2325
anywhere.
2426

@@ -33,7 +35,8 @@ anywhere.
3335
Overview
3436
========
3537

36-
Let's say you wanted to get the version string for a package you've installed
38+
Let's say you wanted to get the version string for a
39+
distribution package you've installed
3740
using ``pip``. We start by creating a virtual environment and installing
3841
something into it::
3942

@@ -151,7 +154,8 @@ interface to retrieve entry points by group.
151154
Distribution metadata
152155
---------------------
153156

154-
Every distribution includes some metadata, which you can extract using the
157+
Every distribution package includes some metadata,
158+
which you can extract using the
155159
``metadata()`` function::
156160

157161
>>> wheel_metadata = metadata('wheel')
@@ -182,7 +186,8 @@ all the metadata in a JSON-compatible form per PEP 566::
182186
Distribution versions
183187
---------------------
184188

185-
The ``version()`` function is the quickest way to get a distribution's version
189+
The ``version()`` function is the quickest way to get a
190+
distribution package's version
186191
number, as a string::
187192

188193
>>> version('wheel')
@@ -195,7 +200,8 @@ Distribution files
195200
------------------
196201

197202
You can also get the full set of files contained within a distribution. The
198-
``files()`` function takes a distribution package name and returns all of the
203+
``files()`` function takes a distribution package name
204+
and returns all of the
199205
files installed by this distribution. Each file object returned is a
200206
``PackagePath``, a :class:`pathlib.PurePath` derived object with additional ``dist``,
201207
``size``, and ``hash`` properties as indicated by the metadata. For example::
@@ -240,19 +246,24 @@ distribution is not known to have the metadata present.
240246
Distribution requirements
241247
-------------------------
242248

243-
To get the full set of requirements for a distribution, use the ``requires()``
249+
To get the full set of requirements for a distribution package,
250+
use the ``requires()``
244251
function::
245252

246253
>>> requires('wheel')
247254
["pytest (>=3.0.0) ; extra == 'test'", "pytest-cov ; extra == 'test'"]
248255

249256

250-
Package distributions
251-
---------------------
257+
.. _package-distributions:
258+
.. _import-distribution-package-mapping:
259+
260+
Mapping import to distribution packages
261+
---------------------------------------
252262

253-
A convenience method to resolve the distribution or
254-
distributions (in the case of a namespace package) for top-level
255-
Python packages or modules::
263+
A convenience method to resolve the distribution package
264+
name (or names, in the case of a namespace package)
265+
that provide each importable top-level
266+
Python module or import package::
256267

257268
>>> packages_distributions()
258269
{'importlib_metadata': ['importlib-metadata'], 'yaml': ['PyYAML'], 'jaraco': ['jaraco.classes', 'jaraco.functools'], ...}
@@ -264,7 +275,8 @@ Distributions
264275

265276
While the above API is the most common and convenient usage, you can get all
266277
of that information from the ``Distribution`` class. A ``Distribution`` is an
267-
abstract object that represents the metadata for a Python package. You can
278+
abstract object that represents the metadata for
279+
a Python distribution package. You can
268280
get the ``Distribution`` instance::
269281

270282
>>> from importlib_metadata import distribution
@@ -291,7 +303,9 @@ for additional details.
291303
Distribution Discovery
292304
======================
293305

294-
By default, this package provides built-in support for discovery of metadata for file system and zip file packages. This metadata finder search defaults to ``sys.path``, but varies slightly in how it interprets those values from how other import machinery does. In particular:
306+
By default, this package provides built-in support for discovery of metadata
307+
for file system and zip file distribution packages.
308+
This metadata finder search defaults to ``sys.path``, but varies slightly in how it interprets those values from how other import machinery does. In particular:
295309

296310
- ``importlib_metadata`` does not honor :class:`bytes` objects on ``sys.path``.
297311
- ``importlib_metadata`` will incidentally honor :py:class:`pathlib.Path` objects on ``sys.path`` even though such values will be ignored for imports.
@@ -300,15 +314,18 @@ By default, this package provides built-in support for discovery of metadata for
300314
Extending the search algorithm
301315
==============================
302316

303-
Because package metadata is not available through :data:`sys.path` searches, or
304-
package loaders directly, the metadata for a package is found through import
317+
Because distribution package metadata
318+
is not available through :data:`sys.path` searches, or
319+
package loaders directly,
320+
the metadata for a distribution is found through import
305321
system `finders`_. To find a distribution package's metadata,
306322
``importlib.metadata`` queries the list of :term:`meta path finders <meta path finder>` on
307323
:data:`sys.meta_path`.
308324

309325
By default ``importlib_metadata`` installs a finder for distribution packages
310-
found on the file system. This finder doesn't actually find any *packages*,
311-
but it can find the packages' metadata.
326+
found on the file system.
327+
This finder doesn't actually find any *distributions*,
328+
but it can find their metadata.
312329

313330
The abstract class :py:class:`importlib.abc.MetaPathFinder` defines the
314331
interface expected of finders by Python's import system.

0 commit comments

Comments
 (0)