Skip to content

Commit 3e99f25

Browse files
committed
Fix docs and tests for PEP 829
1 parent 8454716 commit 3e99f25

File tree

2 files changed

+286
-62
lines changed

2 files changed

+286
-62
lines changed

Doc/library/site.rst

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ with ``import`` (followed by space or tab) are executed.
9696
The :file:`.pth` files are now decoded by UTF-8 at first and then by the
9797
:term:`locale encoding` if it fails.
9898

99+
.. versionchanged:: 3.15
100+
Lines starting with ``import`` are deprecated. During the deprecation
101+
period, such lines are still executed, but a diagnostic message is
102+
emitted when the :option:`-v` flag is given. If a :file:`{name}.start`
103+
file with the same base name exists, ``import`` lines are silently
104+
ignored. See :ref:`site-start-files` and :pep:`829`.
105+
106+
.. versionchanged:: 3.15
107+
Errors on individual lines no longer abort processing of the rest of
108+
the file. Each error is reported and the remaining lines continue to
109+
be processed.
110+
99111
.. index::
100112
single: package
101113
triple: path; configuration; file
@@ -131,6 +143,47 @@ directory precedes the :file:`foo` directory because :file:`bar.pth` comes
131143
alphabetically before :file:`foo.pth`; and :file:`spam` is omitted because it is
132144
not mentioned in either path configuration file.
133145

146+
.. _site-start-files:
147+
148+
Startup entry points (:file:`.start` files)
149+
--------------------------------------------
150+
151+
.. versionadded:: 3.15
152+
153+
A startup entry point file is a file whose name has the form
154+
:file:`{name}.start` and exists in one of the site-packages directories
155+
described above. Each file specifies entry points to be called during
156+
interpreter startup, using the ``pkg.mod:callable`` syntax understood by
157+
:func:`pkgutil.resolve_name`.
158+
159+
Each non-blank line that does not begin with ``#`` must contain an entry
160+
point reference in the form ``pkg.mod:callable``. The colon and callable
161+
portion are mandatory. Each callable is invoked with no arguments, and
162+
any return value is discarded.
163+
164+
:file:`.start` files are processed after all :file:`.pth` path extensions
165+
have been applied to :data:`sys.path`, ensuring that paths are available
166+
before any startup code runs. Within each site-packages directory, files
167+
are sorted alphabetically by filename.
168+
169+
Unlike :data:`sys.path` extensions from :file:`.pth` files, duplicate entry
170+
points are **not** deduplicated --- if an entry point appears more than once,
171+
it will be called more than once.
172+
173+
If an exception occurs during resolution or invocation of an entry point,
174+
a traceback is printed to :data:`sys.stderr` and processing continues with
175+
the remaining entry points.
176+
177+
See :pep:`829` for the full specification.
178+
179+
.. note::
180+
181+
If a :file:`{name}.start` file exists alongside a :file:`{name}.pth`
182+
file with the same base name, any ``import`` lines in the :file:`.pth`
183+
file are ignored in favour of the entry points in the :file:`.start`
184+
file.
185+
186+
134187
:mod:`!sitecustomize`
135188
---------------------
136189

@@ -238,8 +291,19 @@ Module contents
238291

239292
.. function:: addsitedir(sitedir, known_paths=None)
240293

241-
Add a directory to sys.path and process its :file:`.pth` files. Typically
242-
used in :mod:`sitecustomize` or :mod:`usercustomize` (see above).
294+
Add a directory to sys.path and process its :file:`.pth` and
295+
:file:`.start` files. Typically used in :mod:`sitecustomize` or
296+
:mod:`usercustomize` (see above).
297+
298+
The *known_paths* argument is an optional set of case-normalized paths
299+
used to prevent duplicate :data:`sys.path` entries. When ``None`` (the
300+
default), the set is built from the current :data:`sys.path`.
301+
302+
.. versionchanged:: 3.15
303+
Also processes :file:`.start` files. See :ref:`site-start-files`.
304+
All :file:`.pth` and :file:`.start` files are now read and
305+
accumulated before any path extensions, ``import`` line execution,
306+
or entry point invocations take place.
243307

244308

245309
.. function:: getsitepackages()

0 commit comments

Comments
 (0)