Skip to content

Commit 6d887c3

Browse files
committed
Address review comments
1 parent dc34ac7 commit 6d887c3

1 file changed

Lines changed: 66 additions & 38 deletions

File tree

source/specifications/dependency-specifiers.rst

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -248,43 +248,54 @@ The follow comparison operations are defined in the marker expression grammar:
248248

249249
For ``String`` fields, ``==``, ``!=``, ``in``, and ``not in`` are defined as
250250
they are for Python strings (case sensitive, with no value normalization of any
251-
kind). The use of ``~=`` or ``===`` with string fields is
252-
explicitly discouraged, and publishing tools SHOULD emit an error, while locking
253-
and installation tools MAY instead interpret them as equivalent to ``==``. The
254-
use of ordered comparisons (``<``, ``<=``, ``>``, ``>=``) with string fields is
255-
explicitly discouraged (as it makes no semantic sense in the packaging context),
256-
and publishing tools SHOULD emit an error, while locking and installation tools
251+
kind). The use of ``~=`` or ``===`` with string fields is explicitly
252+
discouraged and publishing tools SHOULD emit an error, index servers MAY
253+
disallow uploads containing such environment markers, while locking and
254+
installation tools MAY instead interpret them as equivalent to ``==``. The use
255+
of ordered comparisons (``<``, ``<=``, ``>``, ``>=``) with string fields is
256+
explicitly discouraged (as it makes no semantic sense in the packaging context)
257+
and publishing tools SHOULD emit an error, index servers MAY disallow uploads
258+
containing such environment markers, while locking and installation tools
257259
SHOULD implement the following behavior:
258260

259261
* treat ``>=`` and ``<=`` as equivalent to ``==``
260262
* treat ``>`` and ``<`` as always being False
261263

262264
For ``Set of String`` fields, as there is no marker syntax for set literals,
263265
the only valid operations are ``in`` and ``not in`` comparisons with a user
264-
supplied string literal as the left operand.
266+
supplied string literal as the left operand. Publishing tools SHOULD emit an
267+
error if environment markers attempt to use any other comparison operations on
268+
these fields and index servers MAY disallow uploads containing such environment
269+
markers, while locking and installation tools SHOULD treat such operations as
270+
always being False.
265271

266272
For ``Version`` fields, the comparison operations are defined by the
267273
:ref:`Version specifier specification <version-specifiers>` when either both
268274
the marker field value and the user supplied constant can be parsed as valid
269275
version specifiers or the ``===`` arbitrary equivalence comparison operator
270276
is used. When an operator other than ``===`` is used, publishing tools SHOULD
271277
emit an error if the user supplied constant cannot be parsed as a valid version
272-
specifier, while locking and installation tools MAY either emit an error or else
278+
specifier, index servers MAY disallow uploads containing such environment
279+
markers, while locking and installation tools MAY either emit an error or else
273280
fall back to ``String`` field comparison logic if either the marker field value
274281
or the user supplied constant cannot be parsed as a valid version specifier.
275282
Note that ``in`` and ``not in`` containment checks are NOT valid for ``Version``
276-
fields and publishing tools SHOULD emit an error, while locking and installation
283+
fields and publishing tools SHOULD emit an error, index servers MAY disallow
284+
uploads containing such environment markers, while locking and installation
277285
tools MAY treat them as always being False.
278286

279287
For ``Version | String`` fields, comparison operations are defined as they are
280288
for ``Version`` fields, while ``in`` and ``not in`` containment checks are
281-
defined as they are for ``String`` fields. However, there is no expectation
282-
that the parsing of the marker field value or the user supplied constant as a
283-
valid version will succeed, so tools MUST fall back to processing the field as
284-
a ``String`` field. Alternatively, tools MAY unconditionally treat such fields
285-
as ``String`` fields. Due to this potential for variation across clients,
286-
comparisons that rely on these fields being processed as ``Version`` fields
287-
SHOULD NOT be used in environment markers published to public index servers.
289+
defined as they are for ``String`` fields. However, there is no consistent
290+
cross-platform expectation that the parsing of the marker field value or the
291+
user supplied constant as a valid version will succeed, so tools SHOULD fall
292+
back to processing the field as a ``String`` field if parsing either value as a
293+
version fails. Tools MAY emit a warning if the field is expected to contain a
294+
valid version on a given platform but does not in fact do so. Tools SHOULD NOT
295+
unconditionally treat such fields as ``String`` fields, as doing so may give
296+
incorrect answers for environment markers that are appropriately scoped
297+
to the relevant platforms before performing a version based comparison.
298+
288299

289300
Composing marker expressions
290301
''''''''''''''''''''''''''''
@@ -323,8 +334,13 @@ contain non-ASCII text that users wish to perform comparisons against.
323334
Unknown marker fields
324335
'''''''''''''''''''''
325336

326-
References to unknown marker fields MUST raise an error rather than resulting
327-
in a comparison that evaluates to True or False.
337+
References to unknown marker fields SHOULD raise an error rather than resulting
338+
in a comparison that evaluates to True or False. This is so that attempted
339+
installations involving unknown marker fields result in a clear installation
340+
failure, rather than an apparently successful installation that then fails at
341+
runtime due to missing dependencies (if the unknown marker is treated as
342+
False) or a potentially cryptic installation failure of a dependency that is
343+
not valid for the current platform (if the unknown marker is treated as True)
328344

329345
Variables whose value cannot be calculated on a given Python implementation
330346
should evaluate to ``0`` for ``Version`` fields, and an empty string for all
@@ -345,72 +361,83 @@ of the following marker fields:
345361
* - Marker
346362
- Python equivalent
347363
- Type
348-
- Sample values
364+
- Sample values & notes
349365
* - ``os_name``
350366
- :py:data:`os.name`
351367
- String
352368
- ``posix``, ``java``
353369
* - ``sys_platform``
354370
- :py:data:`sys.platform`
355371
- String
356-
- ``linux``, ``linux2``, ``darwin``, ``java1.8.0_51`` (note that "linux"
357-
is from Python3 and "linux2" from Python2)
372+
- ``linux``, ``win32``, ``darwin``, ``java1.8.0_51``
373+
(note that this is the most well defined field for use when declaring
374+
platform specific dependencies)
358375
* - ``platform_machine``
359376
- :py:func:`platform.machine()`
360377
- String
361-
- ``x86_64``
378+
- ``x86_64``, ``aarch64``, ``AMD64``, ``arm64``
379+
(note that this value is provided by the operating system, so the same
380+
CPU architecture may use different strings on different platforms)
362381
* - ``platform_python_implementation``
363382
- :py:func:`platform.python_implementation()`
364383
- String
365-
- ``CPython``, ``Jython``
384+
- ``CPython``, ``PyPy``, ``Jython``
366385
* - ``platform_release``
367386
- :py:func:`platform.release()`
368387
- Version | String
369388
- ``3.14.1-x86_64-linode39``, ``14.5.0``, ``1.8.0_51``
389+
(may be a valid version field, for example on macOS/darwin)
370390
* - ``platform_system``
371391
- :py:func:`platform.system()`
372392
- String
373393
- ``Linux``, ``Windows``, ``Java``
374394
* - ``platform_version``
375395
- :py:func:`platform.version()`
376-
- String
396+
- Version | String
377397
- ``#1 SMP Fri Apr 25 13:07:35 EDT 2014``
378398
``Java HotSpot(TM) 64-Bit Server VM, 25.51-b03, Oracle Corporation``
379399
``Darwin Kernel Version 14.5.0: Wed Jul 29 02:18:53 PDT 2015; root:xnu-2782.40.9~2/RELEASE_X86_64``
400+
``13``
401+
(may be a valid version field, for example on iOS or Android)
380402
* - ``python_version``
381403
- ``'.'.join(platform.python_version_tuple()[:2])``
382404
- :ref:`Version <version-specifiers>`
383-
- ``3.4``, ``2.7``
405+
- ``3.9``, ``3.15``
384406
* - ``python_full_version``
385407
- :py:func:`platform.python_version()`
386408
- :ref:`Version <version-specifiers>`
387-
- ``3.4.0``, ``3.5.0b1``
409+
- ``3.10.12``, ``3.15.0a1``
388410
* - ``implementation_name``
389411
- :py:data:`sys.implementation.name <sys.implementation>`
390412
- String
391-
- ``cpython``
413+
- ``cpython``, ``pypy``
392414
* - ``implementation_version``
393415
- see definition below
394416
- :ref:`Version <version-specifiers>`
395-
- ``3.4.0``, ``3.5.0b1``
417+
- ``3.10.12``, ``7.3.17``
418+
(examples are for CPython and PyPy respectively)
396419
* - ``extra``
397420
- Used to indicate optional dependencies in project dependency metadata.
398421
An error except when defined by the context interpreting the
399-
specifier. Publishing tools SHOULD permit use of this field.
422+
specifier.
400423
- Special (see below)
401424
- ``toml``
425+
(publishing tools SHOULD permit use of this field)
402426
* - ``extras``
403427
- Used to indicate optional public dependencies in lock files. An error
404428
except when defined by the context interpreting the specifier.
405-
Publishing tools SHOULD NOT permit use of this field.
406429
- Set of strings
407430
- ``{"toml"}``
431+
(publishing tools SHOULD NOT permit use of this field and index servers
432+
SHOULD NOT accept uploads containing such environment markers)
408433
* - ``dependency_groups``
409434
- Used to indicate optional project internal dependencies in lock files.
410435
An error except when defined by the context interpreting the
411-
specifier. Publishing tools SHOULD NOT permit use of this field.
436+
specifier.
412437
- Set of strings
413438
- ``{"test"}``
439+
(publishing tools SHOULD NOT permit use of this field and index servers
440+
SHOULD NOT accept uploads containing such environment markers)
414441

415442
For backwards compatibility with older locking and installation tools, the
416443
``extras`` and ``dependency_groups`` fields are currently only considered
@@ -426,13 +453,14 @@ predates the addition of ``Set of strings`` as a defined marker field type.
426453
Accordingly, for this field only, ``extra == "name"`` is equivalent to
427454
``"name" in extras``, while ``extra != "name"`` is equivalent to
428455
``"name" not in extras``. Other comparison operations on ``extra`` are not
429-
defined and publishing tools SHOULD emit an error, while locking and
430-
installation tools may evaluate them as False. Unlike the newer ``extras``
431-
field, this field SHOULD be accepted by both publishing tools and index
432-
servers. Marker evaluation environments intended for project dependency
433-
declarations will typically need to handle evaluation of ``extra`` field
434-
comparisons, while other evaluations of environment markers will not generally
435-
need to do so.
456+
defined and publishing tools SHOULD emit an error, index servers MAY disallow
457+
uploads containing such environment markers, while locking and
458+
installation tools SHOULD evaluate them as False. Unlike the newer ``extras``
459+
field, environment markers using this field SHOULD be accepted by both
460+
publishing tools and index servers. Marker evaluation environments intended
461+
for project dependency declarations will typically need to handle evaluation
462+
of ``extra`` field comparisons, while other evaluations of environment markers
463+
will not generally need to do so.
436464

437465
The ``implementation_version`` marker variable is derived from
438466
:py:data:`sys.implementation.version <sys.implementation>`:

0 commit comments

Comments
 (0)