Skip to content

Commit 2a32bc5

Browse files
authored
Merge branch 'main' into testpypi-onlydeps-comment
2 parents 956784b + 727c67b commit 2a32bc5

3 files changed

Lines changed: 57 additions & 37 deletions

File tree

‎source/guides/creating-and-discovering-plugins.rst‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,17 @@ but it's not recommended to make your project's main top-level package
100100
bad plugin could cause the entire namespace to break which would in turn make
101101
your project unimportable. For the "namespace sub-package" approach to work,
102102
the plugin packages must omit the :file:`__init__.py` for your top-level
103-
package directory (``myapp`` in this case) and include the namespace-package
104-
style :file:`__init__.py` in the namespace sub-package directory
105-
(``myapp/plugins``). This also means that plugins will need to explicitly pass
106-
a list of packages to :func:`setup`'s ``packages`` argument instead of using
107-
:func:`setuptools.find_packages`.
103+
package directory (``myapp`` in this case). In the namespace sub-package
104+
directory (``myapp/plugins``) they must either omit :file:`__init__.py`, if
105+
you use :ref:`native namespace packages <native-namespace-packages>`, or
106+
include a pkgutil-style :file:`__init__.py`, if you use the legacy approach.
107+
Plugins will also need to list their packages explicitly or use :func:`setuptools.find_namespace_packages`, as
108+
:func:`setuptools.find_packages` skips directories without an
109+
:file:`__init__.py`.
110+
111+
With native namespace packages, ``import myapp.plugins`` raises
112+
:exc:`ModuleNotFoundError` if no installed distribution provides the
113+
``myapp/plugins`` directory. Make sure your discovery code handles that case.
108114

109115
.. warning:: Namespace packages are a complex feature and there are several
110116
different ways to create them. It's highly recommended to read the

‎source/guides/writing-pyproject-toml.rst‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,22 +333,25 @@ You can also specify the format explicitly, like this:
333333
``license`` and ``license-files``
334334
---------------------------------
335335

336-
As per :pep:`639`, licenses should be declared with two fields:
336+
The :ref:`Core Metadata specification <core-metadata-license-expression>` defines
337+
two fields for modern license metadata. They serve different purposes and can be
338+
used independently:
337339

338-
- ``license`` is an :term:`SPDX license expression <License Expression>`
340+
- ``license`` declares an :term:`SPDX license expression <License Expression>`
339341
consisting of one or more :term:`license identifiers <License Identifier>`.
340-
- ``license-files`` is a list of license file glob patterns.
342+
- ``license-files`` specifies glob patterns matching license files and other
343+
legal notices to include in distribution archives.
341344

342345
A previous PEP had specified ``license`` to be a table with a ``file`` or a
343346
``text`` key, this format is now deprecated. Most :term:`build backends<build
344347
backend>` now support the new format as shown in the following table.
345348

346-
.. list-table:: build backend versions that introduced :pep:`639` support
349+
.. list-table:: build backend versions supporting the standardized license fields
347350
:header-rows: 1
348351

349352
* - hatchling
350353
- setuptools
351-
- flit-core [#flit-core-pep639]_
354+
- flit-core
352355
- pdm-backend
353356
- poetry-core
354357
- uv-build
@@ -359,6 +362,9 @@ backend>` now support the new format as shown in the following table.
359362
- 2.2.0
360363
- 0.7.19
361364

365+
The table lists minimum backend versions for these fields; prefer a current
366+
supported backend release when possible.
367+
362368

363369
.. _license:
364370

@@ -618,9 +624,6 @@ A full example
618624
like ``requires-python = "<= 3.10"`` here. `This blog post <requires-python-blog-post_>`_
619625
contains some information regarding possible problems.
620626
621-
.. [#flit-core-pep639] flit-core `does not yet <flit-issue-735_>`_ support WITH in SPDX license expressions.
622-
623-
.. _flit-issue-735: https://github.com/pypa/flit/issues/735
624627
.. _gfm: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax
625628
.. _setuptools: https://setuptools.pypa.io
626629
.. _poetry: https://python-poetry.org
Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11

22
.. _virtual-environments:
33

4-
===========================
5-
Python Virtual Environments
6-
===========================
4+
====================
5+
Virtual Environments
6+
====================
77

8-
For Python 3.3 and later versions, :pep:`405` introduced interpreter level support
9-
for the concept of "Python Virtual Environments". Each virtual environment has
10-
its own Python binary (allowing creation of environments with various Python
11-
versions) and can have its own independent set of installed Python packages in
12-
its site directories, but shares the standard library with the base installed
13-
Python. While the concept of virtual environments existed prior to this update,
14-
there was no previously standardised mechanism for declaring or discovering them.
8+
A virtual environment isolates a Python interpreter and its packages. The
9+
virtual environment has its own Python binary (allowing creation of
10+
environments with various Python versions) and can have its own independent set
11+
of installed Python packages in its site directories, but shares the standard
12+
library with the base installed Python.
13+
14+
A Python interpreter detects whether it is in a virtual environment by looking
15+
for a ``pyvenv.cfg`` file in the directory containing its executable or in that
16+
directory's parent, without resolving symlinks to the executable. The
17+
``pyvenv.cfg`` needs to have at least a ``home`` key to declare a virtual
18+
environment.
1519

1620

1721
Runtime detection of virtual environments
1822
=========================================
1923

2024
At runtime, virtual environments can be identified by virtue of
2125
:py:data:`sys.prefix` (the filesystem location of the running interpreter)
22-
having a different value from :py:data:`sys.base_prefix` (the default filesystem
23-
location of the standard library directories).
26+
having a different value from :py:data:`sys.base_prefix` (the default
27+
filesystem location of the standard library directories).
2428

2529
:ref:`venv-explanation` in the Python standard library documentation for the
2630
:py:mod:`venv` module covers this along with the concept of "activating" a
@@ -29,28 +33,35 @@ step is optional and hence the changes it makes can't be reliably used to
2933
detect whether a Python program is running in a virtual environment or not).
3034

3135

32-
Declaring installation environments as Python virtual environments
33-
==================================================================
36+
``pyvenv.cfg``
37+
==============
38+
39+
The ``pyvenv.cfg`` has lines in the form ``key = value``. The following keys
40+
are defined:
3441

35-
As described in :pep:`405`, a Python virtual environment in its simplest form
36-
consists of nothing more than a copy or symlink of the Python binary accompanied
37-
by a ``site-packages`` directory and a ``pyvenv.cfg`` file with a ``home`` key
38-
that indicates where to find the Python standard library modules.
42+
* ``home``: The directory containing the Python executable used to create this
43+
virtual environment.
44+
* ``include-system-site-packages``: When ``true`` or absent, the ``site``
45+
module will also add the system site directories to ``sys.path`` after the
46+
virtual environment site directories. If ``false``, the system site
47+
directories are not included. It is RECOMMENDED to set it to ``false`` when
48+
creating a virtual environments. The value is not case sensitive.
3949

40-
While designed to meet the needs of the standard :py:mod:`venv` module, this
41-
split installation and ``pyvenv.cfg`` file approach can be used by *any*
42-
Python installation provider that desires Python-specific tools to be aware that
43-
they are already operating in a virtual environment and no further environment
44-
nesting is required or desired.
50+
51+
Declaring installation environments as Python virtual environments
52+
==================================================================
4553

4654
Even in the absence of a ``pyvenv.cfg`` file, any approach (e.g.
4755
``sitecustomize.py``, patching the installed Python runtime) that results in
4856
:py:data:`sys.prefix` and :py:data:`sys.base_prefix` having different values,
4957
while still providing a matching default package installation scheme in
50-
:py:mod:`sysconfig`, will be detected and behave as a Python virtual environment.
58+
:py:mod:`sysconfig`, will be detected and behave as a Python virtual
59+
environment.
5160

5261

5362
History
5463
=======
5564

5665
- May 2012: This specification was approved through :pep:`405`.
66+
- Nov 2026: Removed PEP 405 references and clarified that
67+
``include-system-site-packages`` defaults to ``true``.

0 commit comments

Comments
 (0)