@@ -22,15 +22,16 @@ Post-History:
2222Abstract
2323========
2424
25- This PEP defines using ABI features as environment markers for project
26- dependencies, through a new ``sys_abi_features `` environment marker. :pep: `508 `
27- (later moved to :ref: `packaging:dependency-specifiers `) introduced environment
28- markers to specify dependencies based on rules that describe when the
29- dependency should be used. This PEP extends the environment markers to allow
30- specifying dependencies based on specific ABI features of the Python
31- interpreter. For this, it defines a set of `ABI Features `_ and specifies how
32- they are made available for `environment markers <pep-780-sys_abi_features _>`_
33- as a new marker variable, ``sys_abi_features ``.
25+ This PEP defines the use of information about the interpreter ABI as
26+ environment markers for project dependencies through a new ``sys_abi_info ``
27+ environment marker variable. :pep: `508 ` (later moved to
28+ :ref: `packaging:dependency-specifiers `) introduced environment markers to
29+ specify dependencies based on rules that describe when the dependency should
30+ be used. This PEP extends environment markers to allow specifying dependencies
31+ based on specific information about the ABI of the Python interpreter. For
32+ this, it defines a set of `ABI Features `_ and specifies how they are made
33+ available for `environment markers <pep-780-sys_abi_info _>`_ via a new marker
34+ variable, ``sys_abi_info ``.
3435
3536Motivation
3637==========
@@ -57,23 +58,19 @@ marker for free-threading`_ Discourse thread:
5758 wheels. Picking up the wrong Cython version is causing a lot of obscure build
5859 failures and runtime crashes. It would be beneficial if the metadata could
5960 express that (c.f. `Require Cython Pre-release for Free-Threaded Python `_).
60- - CFFI has no support for free-threading yet, and `Armin Rigo, one of the
61- maintainers, has stated
62- <https://github.com/python-cffi/cffi/pull/143#issuecomment-2580781899> `__
63- that it may be a good idea to fork ``cffi ``, implement support for
64- free-threading, and only come back to the CFFI project with a single large PR
65- that adds support after the functionality "is reasonably well-tested (either
66- as tests or, better in this case, tested by being in use in various other
67- projects)". There are a lot of projects that depend on ``cffi ``. They are
68- likely fine to start depending on a fork for free-threading only, however
61+ - CFFI has only recently gained support for free-threading, and for a
62+ significant period of time, it looked likely that support would first be
63+ added in a fork. There are a lot of projects that depend on ``cffi ``, which
64+ are likely fine to start depending on a fork for free-threading only, however
6965 depending on a fork for >=3.13 or for all Python versions seems like a much
70- larger ask, and more disruptive for distribution packagers.
66+ larger ask, and more disruptive for distribution packagers. While the
67+ situation has been resolved with CFFI 2.0.0, other projects may face similar
68+ issues.
7169
72- While these concrete examples may be addressed later this year by Cython and
73- CFFI making compatible releases, the same issue is going to repeat further up
74- the stack. The free-threading rollout is expected to take several years, and an
75- environment marker for free-threading will make that rollout significantly
76- easier.
70+ While concrete examples may be addressed with compatible releases, the same
71+ issue is going to repeat further up the stack. The free-threading rollout is
72+ expected to take several years, and an environment marker for free-threading
73+ will make that rollout significantly easier.
7774
7875Another important ABI feature that is not yet covered by environment markers is
7976the bitness of the interpreter. In most cases, the ``sys_platform `` or
@@ -135,7 +132,7 @@ Relation to Other PEPs
135132This PEP extends environment markers with set semantics for ABI features.
136133:pep: `751#additions-to-marker-expression-syntax ` includes a similar extension
137134for lock file specific environment markers; although the two have been
138- developed indepedently , they are compatible where they overlap in terms of the
135+ developed independently , they are compatible where they overlap in terms of the
139136new set semantics.
140137
141138Specification
@@ -149,57 +146,65 @@ and "**OPTIONAL**"" in this document are to be interpreted as described in
149146ABI Features
150147------------
151148
152- ABI features are intrinsic properties of the Python interpreter, expressed as
153- simple, understandable strings. However, not all features are equally
154- applicable to all Python interpreters or Python versions. For example, the
155- distinction between free-threaded and GIL-enabled interpreters is only relevant
156- for CPython 3.13 onwards, but the bitness of the interpreter is relevant for
157- all interpreters.
149+ ABI features are intrinsic properties of the Python interpreter.
150+ However, not all features are equally applicable to all Python interpreters or
151+ Python versions. For example, the distinction between free-threaded and
152+ GIL-enabled interpreters is only relevant for CPython 3.13 onwards, but the
153+ bitness of the interpreter, i.e. the number of bits in a pointer, is relevant
154+ for all interpreters.
158155
159156All interpreters MUST handle the following ABI features as stated. ABI features
160157that are restricted to particular interpreters MUST NOT be provided by other
161- interpreters. The features are subdivided into groups and for each group there
162- MUST be exactly one feature present, except when the group is marked as
163- optional, in which case there MUST be at most one feature present.
158+ interpreters.
164159
165- ``free-threading `` or ``gil-enabled `` (only CPython)
166- If the Python interpreter is free-threaded, the ``free-threading `` feature
167- MUST be present and the ``gil-enabled `` feature MUST NOT be present.
168- Otherwise, the ``gil-enabled `` feature MUST be present and the
169- ``free-threading `` feature MUST NOT be present.
160+ In Python 3.15 and later, the ABI features are determined by the new
161+ ``sys.abi_info `` attribute. In earlier Python versions, the ABI features are
162+ the same as for Python 3.15 and given as follows:
170163
171- ``debug `` (only CPython, optional)
164+ ``pointer_bits ``
165+ The bitness of the interpreter, that is, the number of bits in a pointer,
166+ typically ``32 `` or ``64 `` [#bitness ]_.
167+
168+ ``free_threaded `` (only CPython)
169+ If the Python interpreter is free-threaded, ``free_threaded `` MUST be
170+ ``True ``, otherwise it MUST be ``False ``.
171+
172+ ``debug `` (only CPython)
172173 This ABI feature is reserved for the ``--with-pydebug `` build of CPython.
173174 If the interpreter is a CPython interpreter with ``Py_DEBUG `` capabilities,
174- the ``debug `` feature MUST be present . On POSIX systems, this corresponds
175+ the ``debug `` feature MUST be `` True `` . On POSIX systems, this corresponds
175176 to the Python expression ``"d" in sys.abiflags ``.
176177
177- ``32-bit `` or ``64-bit `` (optional)
178- The bitness of the interpreter, that is, whether it is a 32-bit or 64-bit
179- build [#bitness ]_. If the bitness is unknown or neither 32-bit nor 64-bit,
180- this feature MUST NOT be present.
178+ ``byteorder ``
179+ Indicates the byte order of the interpreter. The value MUST be either
180+ ``"little" `` or ``"big" ``.
181181
182- .. _pep-780-sys_abi_features :
182+ .. _pep-780-sys_abi_info :
183183
184- The ``sys_abi_features `` Environment Marker
184+ The ``sys_abi_info `` Environment Marker
185185-------------------------------------------
186186
187187To make ABI features available in dependency specifications, a new environment
188- marker variable, ``sys_abi_features ``, is added to the format of dependency
189- specifiers.
188+ marker variable, ``sys_abi_info ``, is added to the format of dependency
189+ specifiers. It is built to reflect the value of ``sys.abi_info ``, which is a
190+ new attribute of the ``sys `` module introduced in Python 3.15 as a simple
191+ namespace. To represent its fields in the environment marker variable, they are
192+ expressed as a frozen set of strings of the form ``f"{name}::{value}" ``, where
193+ ``name `` is the name of the field and ``value `` is the string representation of
194+ its value.
190195
191196To do this, we need to extend the grammar laid out in :pep: `508 ` and maintained
192197in the :ref: `packaging:dependency-specifiers ` and document the possible values.
193198
194- The grammar is extended to include the ``sys_abi_features `` marker variable by
199+ The grammar is extended to include the ``sys_abi_info `` marker variable by
195200augmenting the definition of ``env_var `` as follows::
196201
197202 env_var = ('python_version' | 'python_full_version' |
198203 'os_name' | 'sys_platform' | 'platform_release' |
199204 'platform_system' | 'platform_version' |
200205 'platform_machine' | 'platform_python_implementation' |
201206 'implementation_name' | 'implementation_version' |
202- 'sys_abi_features ' |
207+ 'sys_abi_info ' |
203208 'extra' # ONLY when defined by a containing layer
204209 )
205210
@@ -212,10 +217,10 @@ Like the grammar, also the overview table of environment markers in
212217 * - Marker
213218 - Python equivalent
214219 - Sample values
215- * - ``sys_abi_features ``
216- - no direct equivalent available
217- - ``{'free-threading ', '64-bit '} ``,
218- ``{'gil-enabled ', 'debug', '32-bit '} ``
220+ * - ``sys_abi_info ``
221+ - `` sys.abi_info ``
222+ - ``{'free_threaded::True ', 'pointer_bits::64 '} ``,
223+ ``{'free_threaded::False ', 'debug::True ', 'pointer_bits::32 '} ``
219224
220225With these additions, ABI features can be used in dependency specifications via
221226the ``in `` operator to test for the presence of a feature, or the ``not in ``
@@ -229,22 +234,22 @@ Require Cython Pre-release for Free-Threaded Python
229234To require a pre-release of Cython only for a free-threaded Python interpreter,
230235the following dependency specification can be used::
231236
232- cython >3.1.0a1; "free-threading " in sys_abi_features
233- cython ==3.0.*; "free-threading" not in sys_abi_features
237+ cython >3.1.0a1; "free_threaded::True " in sys_abi_info
238+ cython ==3.0.*; "free_threaded::False" in sys_abi_info
234239
235240Require SciPy Unless on 32-bit ``win32 ``
236241----------------------------------------
237242To require SciPy unless on a 32-bit interpreter on Windows, the following
238243dependency specification can be used::
239244
240- scipy; platform_system != "Windows" or "32-bit " not in sys_abi_features
245+ scipy; platform_system != "Windows" or "pointer_bits::32 " not in sys_abi_info
241246
242247Require NumPy for a Free-Threaded Interpreter With Debugging Capabilities
243248--------------------------------------------------------------------------
244249To require NumPy only for a free-threaded interpreter with debugging
245250capabilities, the following dependency can be used::
246251
247- numpy; "free-threading " in sys_abi_features and "debug" in sys_abi_features
252+ numpy; "free-threaded::True " in sys_abi_info and "debug::True " in sys_abi_info
248253
249254Backwards Compatibility
250255=======================
0 commit comments