From 9bde7faf6f051d4a7306ac8629d915ce069392f7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 8 May 2019 11:13:07 -0400 Subject: [PATCH] Update with latest changes from importlib_metadata --- Doc/library/importlib.metadata.rst | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Doc/library/importlib.metadata.rst b/Doc/library/importlib.metadata.rst index ecf0986ce079..ad17d939d715 100644 --- a/Doc/library/importlib.metadata.rst +++ b/Doc/library/importlib.metadata.rst @@ -1,10 +1,10 @@ .. _using: ========================== - Using importlib_metadata + Using importlib.metadata ========================== -``importlib_metadata`` is a library that provides for access to installed +``importlib.metadata`` is a library that provides for access to installed package metadata. Built in part on Python's import system, this library intends to replace similar functionality in the `entry point API`_ and `metadata API`_ of ``pkg_resources``. Along with @@ -37,15 +37,18 @@ Let's say you wanted to get the version string for a package you've installed using ``pip``. We start by creating a virtual environment and installing something into it:: +.. highlight:: none + $ python3 -m venv example $ source example/bin/activate - (example) $ pip install importlib_metadata (example) $ pip install wheel You can get the version string for ``wheel`` by running the following:: +.. highlight:: none + (example) $ python - >>> from importlib_metadata import version + >>> from importlib.metadata import version >>> version('wheel') '0.32.3' @@ -143,7 +146,7 @@ files installed by this distribution. Each file object returned is a >>> util.size 859 >>> util.dist - + >>> util.hash @@ -179,7 +182,7 @@ of that information from the ``Distribution`` class. A ``Distribution`` is an abstract object that represents the metadata for a Python package. You can get the ``Distribution`` instance:: - >>> from importlib_metadata import distribution + >>> from importlib.metadata import distribution >>> dist = distribution('wheel') Thus, an alternative way to get the version number is through the @@ -206,16 +209,16 @@ Extending the search algorithm Because package metadata is not available through ``sys.path`` searches, or package loaders directly, the metadata for a package is found through import system `finders`_. To find a distribution package's metadata, -``importlib_metadata`` queries the list of `meta path finders`_ on +``importlib.metadata`` queries the list of `meta path finders`_ on `sys.meta_path`_. -By default ``importlib_metadata`` installs a finder for distribution packages +By default ``importlib.metadata`` installs a finder for distribution packages found on the file system. This finder doesn't actually find any *packages*, but it can find the packages' metadata. The abstract class :py:class:`importlib.abc.MetaPathFinder` defines the interface expected of finders by Python's import system. -``importlib_metadata`` extends this protocol by looking for an optional +``importlib.metadata`` extends this protocol by looking for an optional ``find_distributions`` callable on the finders from ``sys.meta_path``. If the finder has this method, it must return an iterator over instances of the ``Distribution`` abstract class. This -- 2.47.3