Skip to content

Commit 3121664

Browse files
committed
PEP 627: Recording installed projects
1 parent f3bbb2c commit 3121664

2 files changed

Lines changed: 159 additions & 8 deletions

File tree

source/specifications/distribution-formats.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ There is also the legacy source distribution format, implicitly defined by
1717
the behaviour of ``distutils`` module in the standard library,
1818
when executing ``setup.py sdist``.
1919

20+
.. _binary-distribution-format:
21+
2022
Binary distribution format
2123
==========================
2224

Lines changed: 157 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,161 @@
1-
21
.. _recording-installed-packages:
32

4-
=================================
5-
Recording installed distributions
6-
=================================
3+
============================
4+
Recording installed projects
5+
============================
6+
7+
This document specifies a common format of recording information
8+
about Python :term:`projects <project>` installed in an environment.
9+
A common metadata format allows tools to query, manage or uninstall projects,
10+
regardless of how they were installed.
11+
12+
Almost all information is optional.
13+
This allows tools outside the Python ecosystem, such as Linux package managers,
14+
to integrate with Python tooling as much as possible.
15+
For example, even if an installer cannot easily provide a list of installed
16+
files in a format specific to Python tooling, it should still record the name
17+
and version of the installed project.
18+
19+
20+
History and change workflow
21+
===========================
22+
23+
The metadata described here was first specified in :pep:`376`, and later
24+
ammended in :pep:`627`.
25+
It was formerly known as *Database of Installed Python Distributions*.
26+
Further amendments (except trivial language or typography fixes) must be made
27+
through the PEP process (see :pep:`1`).
28+
29+
While this document is the normative specification, these PEPs that introduce
30+
changes to it may include additional information such as rationales and
31+
backwards compatibility considerations.
32+
33+
34+
The .dist-info directory
35+
========================
36+
37+
Each project installed from a distribution shall, in addition to files,
38+
install a "``.dist-info``" directory located alongside Importable modules and
39+
packages (commonly, the ``site-packages`` directory).
40+
41+
This directory is named as ``{name}-{version}.dist-info``, with `name` and
42+
`version` fields corresponding to :ref:`core-metadata`.
43+
44+
This ``.dist-info`` directory can contain these files, described in detail
45+
below:
46+
47+
* ``METADATA``: contains project metadata
48+
* ``RECORD``: records the list of installed files.
49+
* ``INSTALLER``: records the name of the tool used to install the project.
50+
51+
Only the ``METADATA`` file is mandatory.
52+
Additional installer-specific files may be present.
53+
54+
.. note::
55+
56+
The :ref:`binary-distribution-format` specification describes additional
57+
files that may appear in the ``.dist-info`` directory of a :term:`wheel`.
58+
Such files may be copied to the ``.dist-info`` directory of an
59+
installed project.
60+
61+
62+
The METADATA file
63+
=================
64+
65+
The ``METADATA`` file contains metadata as described in the :ref:`core-metadata`
66+
specification, version 1.1 or greater.
67+
68+
The ``METADATA`` file is mandatory.
69+
If it cannot be created, or if required core metadata is not available,
70+
no ``.dist-info`` directory should be created at all.
71+
72+
73+
The RECORD file
74+
===============
75+
76+
The ``RECORD`` file holds the list of installed files.
77+
It is a CSV file containing one record (line) per installed file.
78+
79+
The CSV dialect must be readable with the default `reader` of Python's `csv` module:
80+
81+
* field delimiter: ``,`` (comma),
82+
* quoting char: ``"`` (straight double quote),
83+
* line terminator: either ``\r\n`` or ``\n``.
84+
85+
Each record is composed of three elements: the file's **path**, the **hash**
86+
of the contents, and its **size**.
87+
88+
The *path* may be either absolute, or relative to the directory containing
89+
the ``.dist-info`` directory (commonly, the ``site-packages`` directory).
90+
On Windows, directories may be separated either by forward- or backslashes
91+
(``/`` or ``\``).
92+
93+
The *hash* is either an empty string or the name of a hash algorithm from
94+
``hashlib.algorithms_guaranteed``, followed by the equals character ``=`` and
95+
the digest of the file's contents, encoded with the urlsafe-base64-nopad
96+
encoding (``base64.urlsafe_b64encode(digest)`` with trailing ``=`` removed).
97+
98+
The *size* is either the empty string, or file's size in bytes,
99+
as a base 10 integer.
100+
101+
For any file, either or both of the *hash* and *size* fields may be left empty.
102+
Commonly, entries for ``.pyc`` files and the ``RECORD`` file itself have empty
103+
*hash* and *size*.
104+
For other files, leaving the information out is not recommended, as it
105+
prevents verifying the integrity of the installed project.
106+
107+
If the ``RECORD`` file is present, it must list all installed files of the
108+
project, except `.pyc` files corresponding to `.py` files listed in
109+
``RECORD``, which are optional.
110+
Notably, the contents of the ``.dist-info`` directory (including the ``RECORD``
111+
file itself) must be listed.
112+
Directories should not be listed.
113+
114+
To completely uninstall a package, a tool needs to remove all
115+
files listed in ``RECORD``, all ``.pyc`` files (of all optimization levels)
116+
corresponding to removed ``.py`` files, and any directories emptied by
117+
the uninstallation.
118+
119+
Here is an example snippet of a possible ``RECORD`` file::
120+
121+
/usr/bin/black,sha256=iFlOnL32lIa-RKk-MDihcbJ37wxmRbE4xk6eVYVTTeU,220
122+
../../../bin/blackd,sha256=lCadt4mcU-B67O1gkQVh7-vsKgLpx6ny1le34Jz6UVo,221
123+
__pycache__/black.cpython-38.pyc,,
124+
__pycache__/blackd.cpython-38.pyc,,
125+
black-19.10b0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
126+
black-19.10b0.dist-info/LICENSE,sha256=nAQo8MO0d5hQz1vZbhGqqK_HLUqG1KNiI9erouWNbgA,1080
127+
black-19.10b0.dist-info/METADATA,sha256=UN40nGoVVTSpvLrTBwNsXgZdZIwoKFSrrDDHP6B7-A0,58841
128+
black-19.10b0.dist-info/RECORD,,
129+
black.py,sha256=45IF72OgNfF8WpeNHnxV2QGfbCLubV5Xjl55cI65kYs,140161
130+
blackd.py,sha256=JCxaK4hLkMRwVfZMj8FRpRRYC0172-juKqbN22bISLE,6672
131+
blib2to3/__init__.py,sha256=9_8wL9Scv8_Cs8HJyJHGvx1vwXErsuvlsAqNZLcJQR0,8
132+
blib2to3/__pycache__/__init__.cpython-38.pyc,,
133+
blib2to3/__pycache__/pygram.cpython-38.pyc,sha256=zpXgX4FHDuoeIQKO_v0sRsB-RzQFsuoKoBYvraAdoJw,1512
134+
blib2to3/__pycache__/pytree.cpython-38.pyc,sha256=LYLplXtG578ZjaFeoVuoX8rmxHn-BMAamCOsJMU1b9I,24910
135+
blib2to3/pygram.py,sha256=mXpQPqHcamFwch0RkyJsb92Wd0kUP3TW7d-u9dWhCGY,2085
136+
blib2to3/pytree.py,sha256=RWj3IL4U-Ljhkn4laN0C3p7IRdfvT3aIRjTV-x9hK1c,28530
137+
138+
139+
The INSTALLER file
140+
==================
141+
142+
If present, ``INSTALLER`` is a single-line text file naming the tool used to
143+
install the project.
144+
If the installer is executable from the command line, ``INSTALLER``
145+
should contain the command name.
146+
Otherwise, it should contain a printable ASCII string.
147+
148+
The file can be terminated by zero or more ASCII whitespace characters.
149+
150+
Here are examples of two possible ``INSTALLER`` files::
151+
152+
pip
153+
154+
::
7155

8-
The format used to record installed packages and their contents is defined in
9-
:pep:`376`.
156+
MegaCorp Cloud Install-O-Matic
10157

11-
Note that only the ``dist-info`` directory and the ``RECORD`` file format from
12-
that PEP are currently implemented in the default packaging toolchain.
158+
This value should be used for informational purposes only.
159+
For example, if a tool is asked to uninstall a project but finds no ``RECORD``
160+
file, it may suggest that the tool named in ``INSTALLER`` may be able to do the
161+
uninstallation.

0 commit comments

Comments
 (0)