@@ -18,7 +18,7 @@ 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
20
added to the ``[project] `` table in ``pyproject.toml `` for providing the values
21
- for the new core metadata field . This also leads to the introduction of core
21
+ for the new core metadata fields . This also leads to the introduction of core
22
22
metadata version 2.5.
23
23
24
24
@@ -27,7 +27,7 @@ Motivation
27
27
28
28
In Python packaging there is no requirement that a project name match the
29
29
name(s) that you can import for that project. As such, there is no clean,
30
- easy, accurate way to go from import name to project name and vice- versa.
30
+ easy, accurate way to go from import name to project name and vice versa.
31
31
This can make it difficult for tools that try to help people in discovering
32
32
the right project to install when they know the import name or knowing what
33
33
import names a project will provide once installed.
@@ -48,7 +48,7 @@ There is also no easy way to know whether installing two projects will conflict
48
48
with one another based on the import names they provide. For instance, if two
49
49
different projects have a ``_utils `` module, installing both projects will lead
50
50
to a clash as one project's ``_utils `` module would take precedence over the
51
- other project's version by overwriting the other project's file; this issue
51
+ other's, by overwriting the other project's file; this issue
52
52
has been `seen in the wild <https://github.com/astral-sh/uv/pull/13437 >`__.
53
53
54
54
It may also help with spam detection. If a project specifies the same import
@@ -80,16 +80,16 @@ version and not unique per released file for the same version.
80
80
81
81
This PEP is not overly strict on what to (not) list in the proposed metadata on
82
82
purpose. Having build back-ends verify that a project is accurately following
83
- a specification that is somehow strict about what can be listed would be near
83
+ a specification that is somehow strict about what can be listed would be nearly
84
84
impossible to get right due to how flexible Python's import system is. As such,
85
85
this PEP only requires that valid import names be used and that projects don't
86
- lie (and it is acknowledged the latter requirements cannot be validated
86
+ lie (and it is acknowledged the latter requirement cannot be validated
87
87
programmatically). Projects do, though, need to account for all levels of the
88
88
names they list (e.g. you can't list ``a.b.c `` and not account for ``a `` and
89
89
``a.b ``).
90
90
91
91
Various other attempts have been made to solve this, but they all have to
92
- make various trade-offs. For instance, one could download every wheel for
92
+ make trade-offs. For instance, one could download every wheel for
93
93
every project release and look at what files are provided via the
94
94
:ref: `packaging:binary-distribution-format `, but that's a lot of CPU and
95
95
bandwidth for something that is static information (although tricks can be
@@ -99,10 +99,9 @@ currently repeated by everyone independently instead of having the metadata
99
99
hosted by a central index server like PyPI. It also doesn't work for sdists
100
100
as the structure of the wheel isn't known yet, and so inferring the structure
101
101
of the code installed isn't possible. As well, these solutions are not
102
- necessarily accurate as it is based on inference instead of being explicitly
102
+ necessarily accurate as they are based on inference instead of being explicitly
103
103
provided by the project owners. All of these accuracy issues affect even having
104
- an index hosting the information to avoid the compute costs of gathering the
105
- information.
104
+ an index host the information to avoid the compute costs of gathering it.
106
105
107
106
108
107
Specification
@@ -116,7 +115,7 @@ Each entry of both fields MUST be a valid import name. The names specified MUST
116
115
be importable when the project is installed on *some * platform for the same
117
116
version of the project (e.g. the metadata MUST be consistent across all sdists
118
117
and wheels for a project release). This does imply that the information isn't
119
- specific to the distribution artifact it is found in, but for the release
118
+ specific to the distribution artifact it is found in, but to the release
120
119
version the distribution artifact belongs to.
121
120
122
121
``Import-Name `` lists import names which a project, when installed, would
@@ -138,27 +137,37 @@ Projects SHOULD list all the shortest import names that are exclusively provided
138
137
by a project which would cover all import name scenarios. If any of the shortest
139
138
names are dotted names, all intervening names from that name to the top-level
140
139
name should also be listed appropriately in ``Import-Namespace `` and/or
141
- ``Import-Names ``. For instance, a project which is a single package named
140
+ ``Import-Name ``. For instance, a project which is a single package named
142
141
``spam `` with multiple submodules would only list
143
142
``project.import-names = ["spam"] ``. A project that lists ``spam.bacon.eggs ``
144
143
would also need to account for ``spam `` and ``spam.bacon `` appropriately in
145
144
``import-names `` and ``import-namespaces ``. Listing all names acts as a check
146
145
that the intent of the import names is as expected.
147
146
147
+ If a project lists the same name in both ``Import-Name `` and
148
+ ``Import-Namespace ``, then tools MUST raise an error due to ambiguity; this also
149
+ applies to ``import-names `` and ``import-namespaces ``, respectively.
150
+
148
151
Tools SHOULD raise an error when two projects that are to be installed list
149
- names that overlap in each others' ``Import-Name `` entries. This is to avoid
152
+ names that overlap in each other's ``Import-Name `` entries. This is to avoid
150
153
projects unexpectedly shadowing another project's code. The same applies to when
151
154
a project has an entry in ``Import-Name `` that overlaps with another project's
152
- ``Import-Namespace `` entries.
155
+ ``Import-Namespace `` entries. This does not apply to overlapping
156
+ ``Import-Namespace `` entries as that's the purpose of namespace packages.
153
157
154
158
Projects MAY leave ``Import-Name `` and ``Import-Namespace `` out of the core
155
159
metadata for a project. In that instance, tools SHOULD assume that when the
156
- core metadata is 2.5 or newer that the normalized project name when converted to
157
- an import name would be an entry in ``Import-Name `` (i.e. ``- `` substituted for
158
- ``- `` in the normalized project name). This is deemed reasonable as this will
160
+ 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
162
+ ``_ `` in the normalized project name). This is deemed reasonable as this will
159
163
only occur for projects that make a new release once their build back-end
160
164
supports core metadata 2.5 or newer as proposed by this PEP.
161
165
166
+ Projects MAY set ``import-names `` or ``import-namespaces `` -- as well as
167
+ ``Import-Name `` or ``Import-Namespace ``, respectively -- to the normalized
168
+ import name of the project to explicitly declare that the project's name
169
+ is also the import name.
170
+
162
171
163
172
Examples
164
173
--------
@@ -222,8 +231,8 @@ otherwise the name goes into ``project.import-names``.
222
231
Users of projects don't necessarily need to know about this new metadata.
223
232
While they may be exposed to it via tooling, the details of where that data
224
233
came from isn't critical. It's possible they may come across it if an index
225
- server exposed it (e.g., listed the values from ``Import-Name `` and marked
226
- whether the file structure backed up the claims the metadata makes), but that
234
+ server exposes it (e.g., lists the values from ``Import-Name `` and marks
235
+ whether the file structure backs up the claims the metadata makes), but that
227
236
still wouldn't require users to know the technical details of this PEP.
228
237
229
238
@@ -242,7 +251,7 @@ Infer the value for ``Import-Namespace``
242
251
243
252
A previous version of this PEP inferred what would have been the values for
244
253
``Import-Namespace `` based on dotted names in ``Import-Name ``. It was decided
245
- that it would better to be explicit not only to avoid mistakes by accidentally
254
+ that it would be better to be explicit not only to avoid mistakes by accidentally
246
255
listing something that would be interpreted as an implicit namespace, but it
247
256
also made the data more self-documenting.
248
257
@@ -251,7 +260,7 @@ Require that names listed in ``Import-Namespace`` never be contained by a name i
251
260
-------------------------------------------------------------------------------------------------
252
261
253
262
The way Python's import system works by default means that it isn't possible to
254
- have an import name contain an namespace. But Python's import system is flexible
263
+ have an import name contain a namespace. But Python's import system is flexible
255
264
enough that user code could make that possible. As such, the requirement that
256
265
tools error out if an import name contained a namespace name --
257
266
``import-names = ["spam"] `` and ``import-namespaces = ["spam.bacon"] `` -- was
@@ -272,7 +281,7 @@ made to go with a new field.
272
281
Name the field ``Namespace ``
273
282
----------------------------
274
283
275
- While the term "namespace" name is technically accurate from an import
284
+ While the term "namespace" is technically accurate from an import
276
285
perspective, it could be confused with implicit namespace packages.
277
286
278
287
@@ -284,7 +293,7 @@ During `discussions about a pre-PEP version
284
293
PEP, it was suggested that the ``RECORD `` file from wheels be served from
285
294
index servers instead of this new metadata. That would have the benefit of
286
295
being implementable immediately. But in order to provide the equivalent
287
- information there would be necessary inference based on the file structure of
296
+ information, inference would be necessary based on the file structure of
288
297
what would be installed by the wheel. That could lead to inaccurate
289
298
information. It also doesn't support sdists.
290
299
@@ -300,7 +309,7 @@ An earlier version of this PEP was much more strict in what could be put into
300
309
``Import-Name ``. This included turning some "SHOULD" guidelines into "MUST"
301
310
requirements and being specific about how to calculate what a project "owned".
302
311
In the end it was decided that was too restrictive and risked being implemented
303
- incorrectly or the spec being unexpectedy too strict.
312
+ incorrectly or the spec being unexpectedly too strict.
304
313
305
314
Since the metadata was never expected to be exhaustive as it can't be verified
306
315
to be, the looser spec that is currently in this PEP was chosen instead.
315
324
Acknowledgments
316
325
===============
317
326
318
- Thanks to HeeJae Chang for ~~complaining about~~ bringing up regularly the
327
+ Thanks to HeeJae Chang for ~~complaining about~~ regularly bringing up the
319
328
usefulness that this metadata would provide. Thanks to Josh Cannon (no
320
329
relation) for reviewing drafts of this PEP and providing feedback. Also,
321
330
thanks to everyone who participated in a `previous discussion
0 commit comments