Skip to content

Commit

Permalink
[3.9] bpo-43958: Document importlib.metadata.PackagePath.locate method (
Browse files Browse the repository at this point in the history
GH-25669) (GH-27221)

(cherry picked from commit b38b2fa)


Co-authored-by: Paul Moore <p.f.moore@gmail.com>

Automerge-Triggered-By: GH:jaraco
  • Loading branch information
miss-islington committed Jul 18, 2021
1 parent 8187033 commit 049e98b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Doc/library/importlib.metadata.rst
Expand Up @@ -149,7 +149,7 @@ Distribution files
You can also get the full set of files contained within a distribution. The
``files()`` function takes a distribution package name and returns all of the
files installed by this distribution. Each file object returned is a
``PackagePath``, a :class:`pathlib.Path` derived object with additional ``dist``,
``PackagePath``, a :class:`pathlib.PurePath` derived object with additional ``dist``,
``size``, and ``hash`` properties as indicated by the metadata. For example::

>>> util = [p for p in files('wheel') if 'util.py' in str(p)][0] # doctest: +SKIP
Expand All @@ -173,6 +173,12 @@ Once you have the file, you can also read its contents::
return s.encode('utf-8')
return s

You can also use the ``locate`` method to get a the absolute path to the
file::

>>> util.locate() # doctest: +SKIP
PosixPath('/home/gustav/example/lib/site-packages/wheel/util.py')

In the case where the metadata file listing files
(RECORD or SOURCES.txt) is missing, ``files()`` will
return ``None``. The caller may wish to wrap calls to
Expand Down

0 comments on commit 049e98b

Please sign in to comment.