Skip to content

Commit 508f493

Browse files
committed
Update and refine PEP 829
1 parent ca6e4ed commit 508f493

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

Lib/site.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _read_site_toml(sitedir, name):
208208
return None
209209

210210
metadata = data.get("metadata", {})
211-
# Validate the TOML schema version. PEP XXX defines schema_version == 1. Both the [metadata]
211+
# Validate the TOML schema version. PEP 829 defines schema_version == 1. Both the [metadata]
212212
# section and [metadata].schema_version are optional, but if missing, future compatibility
213213
# cannot be guaranteed.
214214
if (schema_version := metadata.get("schema_version")) is not None:

pep-0829.rst

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ support two functions:
3333
anchored at the site-packages directory.
3434

3535
#. **Executing code** -- lines starting with ``import`` (or
36-
``import\\t``) are executed immediate by passing the source string
36+
``import\\t``) are executed immediately by passing the source string
3737
to ``exec()``.
3838

3939
This design has several problems:
@@ -107,7 +107,7 @@ File Naming and Discovery
107107
behavior.
108108

109109
* If both ``<package>.site.toml`` and ``<package>.pth`` exist in the same
110-
directory, only the ``.site.toml`` file is processed.
110+
directory, only the ``<package>.site.toml`` file is processed.
111111

112112

113113
Processing Model
@@ -152,7 +152,7 @@ entry point imports and ``<package>.pth`` import lines.
152152
A ``<package>.site.toml`` file is defined to have three sections, all of which
153153
are optional:
154154

155-
.. _code-block: toml
155+
.. code-block:: toml
156156
157157
[metadata]
158158
schema_version = 1
@@ -181,9 +181,9 @@ Defined keys:
181181
The TOML file schema version number. Must be the integer ``1`` for this
182182
specification. If present, Python guarantees forward-compatible handling:
183183
future versions will either process the file according to the declared
184-
schema or skip it with a clear diagnostic. It is an error if the
185-
``schema_version`` is present but has an unsupported value, the entire
186-
file is skipped. If ``schema_version`` is omitted, the file is processed
184+
schema or skip it with a clear diagnostic. If the
185+
``schema_version`` is present but has an unsupported value, the
186+
entire file is skipped. If ``schema_version`` is omitted, the file is processed
187187
on a best-effort basis with no forward-compatibility guarantees.
188188

189189
Recommended keys:
@@ -279,7 +279,15 @@ Errors are handled differently depending on the phase:
279279
Phase 1: Reading and Parsing
280280
If a ``<package>.site.toml`` file cannot be opened, decoded, or parsed as
281281
valid TOML, it is skipped and processing continues to the next file.
282-
Errors are reported only when ``-v`` (verbose) is given.
282+
Errors are reported only when ``-v`` (verbose) is given. Importantly,
283+
a ``<package>.site.toml`` file that fails to parse **still supersedes**
284+
its corresponding ``<package>.pth`` file. The existence of the
285+
``<package>.site.toml`` file is sufficient to suppress
286+
``<package>.pth`` processing, regardless of whether the TOML file
287+
parses successfully. This prevents confusing dual-execution
288+
scenarios and ensures that a broken ``<package>.site.toml`` is
289+
noticed rather than silently masked by fallback to the
290+
``<package>.pth`` file.
283291

284292
Phase 2: Execution
285293
If a path entry or entry point raises an exception during processing, the
@@ -404,23 +412,23 @@ If your package currently ships a ``<package>.pth`` file, you can migrate to a
404412
``<package>.site.toml`` file. The equivalent of a ``<package>.pth`` file
405413
containing a directory name is:
406414

407-
.. _code-block: toml
415+
.. code-block:: toml
408416
409417
[paths]
410418
dirs = ["my_directory"]
411419
412420
The equivalent of a ``<package>.pth`` file containing ``import my_package``
413421
is:
414422

415-
.. _code-block: toml
423+
.. code-block:: toml
416424
417425
[entrypoints]
418426
init = ["my_package"]
419427
420428
If your ``<package>.pth`` file calls a specific function, use the
421429
``module:callable`` syntax:
422430

423-
.. _code-block: toml
431+
.. code-block:: toml
424432
425433
[entrypoints]
426434
init = ["my_package.startup:initialize"]
@@ -429,7 +437,7 @@ If your ``<package>.pth`` file includes arbitrary code, put that code in a
429437
start up function and use the ``module:callable`` syntax.
430438

431439
Both ``<package>.pth`` and ``<package>.site.toml`` can coexist during
432-
migration. If both exist for the same package, only the ``.site.toml`` is
440+
migration. If both exist for the same package, only the ``<package>.site.toml`` is
433441
processed. Thus, it is recommended that packages compatible with older
434442
Pythons ship both files.
435443

0 commit comments

Comments
 (0)