mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Document importlib.metadata.PackagePath.locate method (GH-25669)
This commit is contained in:
parent
4a85718212
commit
b38b2fa021
1 changed files with 7 additions and 1 deletions
|
@ -191,7 +191,7 @@ Distribution files
|
||||||
You can also get the full set of files contained within a distribution. The
|
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()`` function takes a distribution package name and returns all of the
|
||||||
files installed by this distribution. Each file object returned is a
|
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::
|
``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
|
>>> util = [p for p in files('wheel') if 'util.py' in str(p)][0] # doctest: +SKIP
|
||||||
|
@ -215,6 +215,12 @@ Once you have the file, you can also read its contents::
|
||||||
return s.encode('utf-8')
|
return s.encode('utf-8')
|
||||||
return s
|
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
|
In the case where the metadata file listing files
|
||||||
(RECORD or SOURCES.txt) is missing, ``files()`` will
|
(RECORD or SOURCES.txt) is missing, ``files()`` will
|
||||||
return ``None``. The caller may wish to wrap calls to
|
return ``None``. The caller may wish to wrap calls to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue