11.. _using :
22
3- ==========================
4- Using importlib.metadata
5- ==========================
3+ =================================
4+ Using :mod: ` ! importlib.metadata`
5+ =================================
66
77.. note ::
88 This functionality is provisional and may deviate from the usual
1212package metadata. Built in part on Python's import system, this library
1313intends to replace similar functionality in the `entry point
1414API `_ and `metadata API `_ of ``pkg_resources ``. Along with
15- `` importlib.resources `` in ` Python 3.7
16- and newer `_ (backported as `importlib_resources `_ for older versions of
15+ :mod: ` importlib.resources ` in Python 3.7
16+ and newer (backported as `importlib_resources `_ for older versions of
1717Python), this can eliminate the need to use the older and less efficient
1818``pkg_resources `` package.
1919
2020By "installed package" we generally mean a third-party package installed into
2121Python's ``site-packages `` directory via tools such as `pip
2222<https://pypi.org/project/pip/> `_. Specifically,
2323it means a package with either a discoverable ``dist-info `` or ``egg-info ``
24- directory, and metadata defined by ` PEP 566 `_ or its older specifications.
24+ directory, and metadata defined by :pep: ` 566 ` or its older specifications.
2525By default, package metadata can live on the file system or in zip archives on
26- `` sys.path ` `. Through an extension mechanism, the metadata can live almost
26+ :data: ` sys.path `. Through an extension mechanism, the metadata can live almost
2727anywhere.
2828
2929
@@ -134,7 +134,7 @@ Distribution files
134134You can also get the full set of files contained within a distribution. The
135135``files() `` function takes a distribution package name and returns all of the
136136files installed by this distribution. Each file object returned is a
137- ``PackagePath ``, a `pathlib.Path `_ derived object with additional ``dist ``,
137+ ``PackagePath ``, a :class: `pathlib.Path ` derived object with additional ``dist ``,
138138``size ``, and ``hash `` properties as indicated by the metadata. For example::
139139
140140 >>> util = [p for p in files('wheel') if 'util.py' in str(p)][0] # doctest: +SKIP
@@ -203,18 +203,18 @@ instance::
203203 >>> d.metadata['License'] # doctest: +SKIP
204204 'MIT'
205205
206- The full set of available metadata is not described here. See ` PEP 566
207- <https://www.python.org/dev/peps/pep-0566/> `_ for additional details.
206+ The full set of available metadata is not described here. See :pep: ` 566 `
207+ for additional details.
208208
209209
210210Extending the search algorithm
211211==============================
212212
213- Because package metadata is not available through `` sys.path ` ` searches, or
213+ Because package metadata is not available through :data: ` sys.path ` searches, or
214214package loaders directly, the metadata for a package is found through import
215- system `finders `_ . To find a distribution package's metadata,
216- ``importlib.metadata `` queries the list of `meta path finders `_ on
217- `sys.meta_path `_ .
215+ system :ref: `finders < finders-and-loaders >` . To find a distribution package's metadata,
216+ ``importlib.metadata `` queries the list of :term: `meta path finders <meta path finder> ` on
217+ :data: `sys.meta_path `.
218218
219219The default ``PathFinder `` for Python includes a hook that calls into
220220``importlib.metadata.MetadataPathFinder `` for finding distributions
@@ -224,7 +224,7 @@ The abstract class :py:class:`importlib.abc.MetaPathFinder` defines the
224224interface expected of finders by Python's import system.
225225``importlib.metadata `` extends this protocol by looking for an optional
226226``find_distributions `` callable on the finders from
227- `` sys.meta_path ` ` and presents this extended interface as the
227+ :data: ` sys.meta_path ` and presents this extended interface as the
228228``DistributionFinder `` abstract base class, which defines this abstract
229229method::
230230
@@ -247,20 +247,13 @@ a custom finder, return instances of this derived ``Distribution`` in the
247247
248248.. _`entry point API` : https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points
249249.. _`metadata API` : https://setuptools.readthedocs.io/en/latest/pkg_resources.html#metadata-api
250- .. _`Python 3.7 and newer` : https://docs.python.org/3/library/importlib.html#module-importlib.resources
251250.. _`importlib_resources` : https://importlib-resources.readthedocs.io/en/latest/index.html
252- .. _`PEP 566` : https://www.python.org/dev/peps/pep-0566/
253- .. _`finders` : https://docs.python.org/3/reference/import.html#finders-and-loaders
254- .. _`meta path finders` : https://docs.python.org/3/glossary.html#term-meta-path-finder
255- .. _`sys.meta_path` : https://docs.python.org/3/library/sys.html#sys.meta_path
256- .. _`pathlib.Path` : https://docs.python.org/3/library/pathlib.html#pathlib.Path
257251
258252
259253.. rubric :: Footnotes
260254
261255.. [#f1 ] Technically, the returned distribution metadata object is an
262- `email.message.Message
263- <https://docs.python.org/3/library/email.message.html#email.message.EmailMessage> `_
256+ :class: `email.message.EmailMessage `
264257 instance, but this is an implementation detail, and not part of the
265258 stable API. You should only use dictionary-like methods and syntax
266259 to access the metadata contents.
0 commit comments