Skip to content

Commit 697470b

Browse files
authored
PEP 829: Improve the guidelines for usage and build tools (#4918)
Improve the guidelines for usage and build tools
1 parent d6bcdaf commit 697470b

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

peps/pep-0829.rst

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -338,25 +338,34 @@ How to Teach This
338338

339339
The :mod:`site` module documentation will be updated to describe the operation
340340
and best practices for ``<name>.pth`` and ``<name>.start`` files. The
341-
following guidelines for package authors will be included:
341+
following migration guidelines for package authors will be included:
342342

343-
If your package currently ships a ``<name>.pth`` file, analyze whether you are
344-
using it for ``sys.path`` extension or start up code execution. You can keep
345-
all the ``sys.path`` extension lines unchanged.
343+
* If your package currently ships a ``<name>.pth`` file, analyze whether you
344+
are using it for ``sys.path`` extension or start up code execution. You can
345+
keep all the ``sys.path`` extension lines unchanged.
346346

347-
If you are using the code execution of ``import`` lines feature, create a
348-
callable (taking zero arguments) within an importable module inside your
349-
package. Name these as ``pkg.mod:callable`` entry points in a matching
350-
``<name>.start`` file.
347+
* If you are using the code execution of ``import`` lines feature, create a
348+
callable (taking zero arguments) within an importable module inside your
349+
package. Name these as ``pkg.mod:callable`` entry points in a matching
350+
``<name>.start`` file.
351351

352-
During the deprecation period, if your package has to straddle older Pythons
353-
that don't support this PEP and newer Pythons that do, leave the ``import``
354-
lines in your ``<name>.pth`` file for now. Older, non-supporting Pythons will
355-
execute the ``import`` lines, and newer, supporting Pythons will ignore these
356-
and use the entry points instead.
352+
* If your package has to straddle older Pythons that don't support this PEP
353+
and newer Pythons that do, change the ``import`` lines in your
354+
``<name>.pth`` to use the following form:
357355

358-
After the deprecation period, remove all ``import`` lines from your
359-
``<name>.pth`` file.
356+
``import pkg.mod; pkg.mod.callable()``
357+
358+
This way, older Pythons will execute these ``import`` lines, and newer
359+
Pythons will ignore them, using the ``<name>.start`` file instead. In both
360+
cases the same code is effectively used, so while there's *some*
361+
duplication, it is minimal.
362+
363+
* After your straddling period, remove all ``import`` lines from your
364+
``<name>.pth`` file.
365+
366+
Non-normatively, build tools may want to emit a warning if a package includes
367+
both a ``<name>.pth`` file and a ``<name>.start`` file where the former
368+
includes ``import`` lines that don't match lines in the latter.
360369

361370

362371
Reference Implementation

0 commit comments

Comments
 (0)