Skip to content

Commit aedb519

Browse files
authored
gh-94214: Add venv context.lib_path and document the context (GH-94221)
1 parent bb8b931 commit aedb519

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

Doc/library/venv.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,45 @@ creation according to their needs, the :class:`EnvBuilder` class.
177177
``clear=True``, contents of the environment directory will be cleared
178178
and then all necessary subdirectories will be recreated.
179179

180+
The returned context object is a :class:`types.SimpleNamespace` with the
181+
following attributes:
182+
183+
* ``env_dir`` - The location of the virtual environment. Used for
184+
``__VENV_DIR__`` in activation scripts (see :meth:`install_scripts`).
185+
186+
* ``env_name`` - The name of the virtual environment. Used for
187+
``__VENV_NAME__`` in activation scripts (see :meth:`install_scripts`).
188+
189+
* ``prompt`` - The prompt to be used by the activation scripts. Used for
190+
``__VENV_PROMPT__`` in activation scripts (see :meth:`install_scripts`).
191+
192+
* ``executable`` - The underlying Python executable used by the virtual
193+
environment. This takes into account the case where a virtual environment
194+
is created from another virtual environment.
195+
196+
* ``inc_path`` - The include path for the virtual environment.
197+
198+
* ``lib_path`` - The purelib path for the virtual environment.
199+
200+
* ``bin_path`` - The script path for the virtual environment.
201+
202+
* ``bin_name`` - The name of the script path relative to the virtual
203+
environment location. Used for ``__VENV_BIN_NAME__`` in activation
204+
scripts (see :meth:`install_scripts`).
205+
206+
* ``env_exe`` - The name of the Python interpreter in the virtual
207+
environment. Used for ``__VENV_PYTHON__`` in activation scripts
208+
(see :meth:`install_scripts`).
209+
210+
* ``env_exec_cmd`` - The name of the Python interpreter, taking into
211+
account filesystem redirections. This can be used to run Python in
212+
the virtual environment.
213+
214+
215+
.. versionchanged:: 3.12
216+
The attribute ``lib_path`` was added to the context, and the context
217+
object was documented.
218+
180219
.. versionchanged:: 3.11
181220
The *venv*
182221
:ref:`sysconfig installation scheme <installation_paths>`

Lib/venv/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def create_if_needed(d):
138138

139139
context.inc_path = incpath
140140
create_if_needed(incpath)
141+
context.lib_path = libpath
141142
create_if_needed(libpath)
142143
# Issue 21197: create lib64 as a symlink to lib on 64-bit non-OS X POSIX
143144
if ((sys.maxsize > 2**32) and (os.name == 'posix') and
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document the ``context`` object used in the ``venv.EnvBuilder`` class, and add the new environment's library path to it.

0 commit comments

Comments
 (0)