@@ -17,9 +17,9 @@ This PEP proposes extending the core metadata specification for Python
17
17
packaging to include two new, repeatable fields named ``Import-Name `` and
18
18
``Import-Namespace `` to record the import names that a project provides once
19
19
installed. New keys named ``import-names `` and ``import-namespaces `` will be
20
- added to the ``[project] `` table in `` pyproject.toml `` for providing the values
21
- for the new core metadata fields. This also leads to the introduction of core
22
- metadata version 2.5.
20
+ added to the ``[project] `` table in :file: ` pyproject.toml ` for providing the
21
+ values for the new core metadata fields. This also leads to the introduction of
22
+ core metadata version 2.5.
23
23
24
24
25
25
Motivation
@@ -74,9 +74,19 @@ projects to only have to check a single file's core metadata to get all
74
74
possible import names instead of checking all the released files. This also
75
75
means one does not need to worry if a file is missing when reading the core
76
76
metadata or one can work solely from an sdist if the metadata is provided. As
77
- well, it simplifies having ``project.import-names `` and ``project.import-namespaces ``
78
- keys in ``pyproject.toml `` by having it be consistent for the entire project
79
- version and not unique per released file for the same version.
77
+ well, it simplifies having ``project.import-names `` and
78
+ ``project.import-namespaces `` keys in :file: `pyproject.toml ` by having it be
79
+ consistent for the entire project version and not unique per released file for
80
+ the same version.
81
+
82
+ A distribution file containing modules and packages can have any combination of
83
+ public and private APIs at the module/package level. Distribution files can also
84
+ contain no modules or packages of any kind. Being able to distinguish between
85
+ the situations all have various tool uses that could be beneficial to users. For
86
+ instance, knowing all import names regardless of whether they are public or
87
+ private helps detect clashes at install time. But knowing what is explicitly
88
+ public or private allows tools such as editors to not suggest private import
89
+ names as part of auto-complete.
80
90
81
91
This PEP is not overly strict on what to (not) list in the proposed metadata on
82
92
purpose. Having build back-ends verify that a project is accurately following
@@ -111,12 +121,17 @@ Because this PEP introduces a new field to the core metadata, it bumps the
111
121
latest core metadata version to 2.5.
112
122
113
123
The ``Import-Name `` and ``Import-Namespace `` fields are "multiple uses" fields.
114
- Each entry of both fields MUST be a valid import name. The names specified MUST
115
- be importable when the project is installed on *some * platform for the same
116
- version of the project (e.g. the metadata MUST be consistent across all sdists
117
- and wheels for a project release). This does imply that the information isn't
118
- specific to the distribution artifact it is found in, but to the release
119
- version the distribution artifact belongs to.
124
+ Each entry of both fields MUST be a valid import name or can be empty in the
125
+ case of ``Import-Name ``. Any names specified MUST be importable when the project
126
+ is installed on *some * platform for the same version of the project (e.g. the
127
+ metadata MUST be consistent across all sdists and wheels for a project release).
128
+ This does imply that the information isn't specific to the distribution artifact
129
+ it is found in, but to the release version the distribution artifact belongs to.
130
+
131
+ An import name MAY be followed by a semicolon and the term "private" (e.g.
132
+ ``; private ``). This signals to tools that the import name is not part of the
133
+ public API for the project. Any number of spaces surrounding the ``; `` is
134
+ allowed.
120
135
121
136
``Import-Name `` lists import names which a project, when installed, would
122
137
*exclusively * provide (i.e. if two projects were installed with the same import
@@ -142,7 +157,9 @@ name should also be listed appropriately in ``Import-Namespace`` and/or
142
157
``project.import-names = ["spam"] ``. A project that lists ``spam.bacon.eggs ``
143
158
would also need to account for ``spam `` and ``spam.bacon `` appropriately in
144
159
``import-names `` and ``import-namespaces ``. Listing all names acts as a check
145
- that the intent of the import names is as expected.
160
+ that the intent of the import names is as expected. As well, projects SHOULD
161
+ list all import names, public or private, using the ``; private `` modifier
162
+ as appropriate.
146
163
147
164
If a project lists the same name in both ``Import-Name `` and
148
165
``Import-Namespace ``, then tools MUST raise an error due to ambiguity; this also
@@ -158,7 +175,7 @@ a project has an entry in ``Import-Name`` that overlaps with another project's
158
175
Projects MAY leave ``Import-Name `` and ``Import-Namespace `` out of the core
159
176
metadata for a project. In that instance, tools SHOULD assume that when the
160
177
core metadata is 2.5 or newer, the normalized project name, when converted to
161
- an import name, would be an entry in ``Import-Name `` (i.e. ``- `` substituted for
178
+ an import name, would be an entry in ``Import-Name `` (i.e. ``- `` replaced with
162
179
``_ `` in the normalized project name). This is deemed reasonable as this will
163
180
only occur for projects that make a new release once their build back-end
164
181
supports core metadata 2.5 or newer as proposed by this PEP.
@@ -168,6 +185,13 @@ Projects MAY set ``import-names`` or ``import-namespaces`` -- as well as
168
185
import name of the project to explicitly declare that the project's name
169
186
is also the import name.
170
187
188
+ Projects MAY set ``import-names `` an empty array and not set
189
+ ``import-namespaces `` at all in a :file: `pyproject.toml ` file (e.g.
190
+ ``import-names = [] ``). To match this, projects MAY have an empty
191
+ ``Import-Name `` field in their metadata. This represents a project with NO
192
+ import names, public or private (i.e. there are no Python modules of any kind
193
+ in the distribution file).
194
+
171
195
172
196
Examples
173
197
--------
@@ -225,8 +249,8 @@ projects provide for importing. If their project name matches the module or
225
249
package name their project provides they don't have to do anything. If there is
226
250
a difference, though, they should record all the import names their project
227
251
provides, using the shortest names possible. If any of the names are implicit
228
- namespaces, those go into ``project.import-namespaces `` in `` pyproject.toml ``,
229
- otherwise the name goes into ``project.import-names ``.
252
+ namespaces, those go into ``project.import-namespaces `` in
253
+ :file: ` pyproject.toml `, otherwise the name goes into ``project.import-names ``.
230
254
231
255
Users of projects don't necessarily need to know about this new metadata.
232
256
While they may be exposed to it via tooling, the details of where that data
0 commit comments