From 63bef03950475f6ac4bcbe5331435f695e377e38 Mon Sep 17 00:00:00 2001 From: Paul Moore Date: Fri, 24 Jun 2022 15:18:57 +0100 Subject: [PATCH 1/3] Add venv context.lib_path and document the context --- Doc/library/venv.rst | 39 +++++++++++++++++++++++++++++++++++++++ Lib/venv/__init__.py | 1 + 2 files changed, 40 insertions(+) diff --git a/Doc/library/venv.rst b/Doc/library/venv.rst index b40bd4102c2593..e537f65ea19f0d 100644 --- a/Doc/library/venv.rst +++ b/Doc/library/venv.rst @@ -177,6 +177,45 @@ creation according to their needs, the :class:`EnvBuilder` class. ``clear=True``, contents of the environment directory will be cleared and then all necessary subdirectories will be recreated. + The returned context object is a :type:`types.SimpleNamespace` with the + following attributes: + + * ``env_dir`` - The location of the virtual environment. Used for + ``__VENV_DIR__`` in activation scripts (see :meth:`install_scripts`). + + * ``env_name`` - The name of the virtual environment. Used for + ``__VENV_NAME__`` in activation scripts (see :meth:`install_scripts`). + + * ``prompt`` - The prompt to be used by the activation scripts. Used for + ``__VENV_PROMPT__`` in activation scripts (see :meth:`install_scripts`). + + * ``executable`` - The underlying Python executable used by the virtual + environment. This takes into account the case where a virtual environment + is created from another virtual environment. + + * ``inc_path`` - The include path for the virtual environment. + + * ``lib_path`` - The purelib path for the virtual environment. + + * ``bin_path`` - The script path for the virtual environment. + + * ``bin_name`` - The name of the script path relative to the virtual + environment location. Used for ``__VENV_BIN_NAME__`` in activation + scripts (see :meth:`install_scripts`). + + * ``env_exe`` - The name of the Python interpreter in the virtual + environment. Used for ``__VENV_PYTHON__`` in activation scripts + (see :meth:`install_scripts`). + + * ``env_exec_cmd`` - The name of the Python interpreter, taking into + account filesystem redirections. This can be used to run Python in + the virtual environment. + + + .. versionchanged:: 3.12 + The attribute ``lib_path`` was added to the context, and the context + object was documented. + .. versionchanged:: 3.11 The *venv* :ref:`sysconfig installation scheme ` diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 6032f3648e15ff..f6b790e1b71a13 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -138,6 +138,7 @@ def create_if_needed(d): context.inc_path = incpath create_if_needed(incpath) + context.lib_path = libpath create_if_needed(libpath) # Issue 21197: create lib64 as a symlink to lib on 64-bit non-OS X POSIX if ((sys.maxsize > 2**32) and (os.name == 'posix') and From 0de9eb3e92236b205285adbe6c8fb3753c3a86d5 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 24 Jun 2022 14:25:29 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-06-24-14-25-26.gh-issue-94214.03pXR5.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-06-24-14-25-26.gh-issue-94214.03pXR5.rst diff --git a/Misc/NEWS.d/next/Library/2022-06-24-14-25-26.gh-issue-94214.03pXR5.rst b/Misc/NEWS.d/next/Library/2022-06-24-14-25-26.gh-issue-94214.03pXR5.rst new file mode 100644 index 00000000000000..7dccc0abd4af8e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-06-24-14-25-26.gh-issue-94214.03pXR5.rst @@ -0,0 +1 @@ +Document the ``context`` object used in the ``venv.EnvBuilder`` class, and add the new environment's library path to it. From 4ab325f344c6e650c5bd836d762d0d8e75c3b399 Mon Sep 17 00:00:00 2001 From: Paul Moore Date: Fri, 24 Jun 2022 15:40:51 +0100 Subject: [PATCH 3/3] Fix the ReST markup --- Doc/library/venv.rst | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Doc/library/venv.rst b/Doc/library/venv.rst index e537f65ea19f0d..3cf143d552ac88 100644 --- a/Doc/library/venv.rst +++ b/Doc/library/venv.rst @@ -177,21 +177,21 @@ creation according to their needs, the :class:`EnvBuilder` class. ``clear=True``, contents of the environment directory will be cleared and then all necessary subdirectories will be recreated. - The returned context object is a :type:`types.SimpleNamespace` with the + The returned context object is a :class:`types.SimpleNamespace` with the following attributes: * ``env_dir`` - The location of the virtual environment. Used for - ``__VENV_DIR__`` in activation scripts (see :meth:`install_scripts`). + ``__VENV_DIR__`` in activation scripts (see :meth:`install_scripts`). * ``env_name`` - The name of the virtual environment. Used for - ``__VENV_NAME__`` in activation scripts (see :meth:`install_scripts`). + ``__VENV_NAME__`` in activation scripts (see :meth:`install_scripts`). * ``prompt`` - The prompt to be used by the activation scripts. Used for - ``__VENV_PROMPT__`` in activation scripts (see :meth:`install_scripts`). + ``__VENV_PROMPT__`` in activation scripts (see :meth:`install_scripts`). * ``executable`` - The underlying Python executable used by the virtual - environment. This takes into account the case where a virtual environment - is created from another virtual environment. + environment. This takes into account the case where a virtual environment + is created from another virtual environment. * ``inc_path`` - The include path for the virtual environment. @@ -200,16 +200,16 @@ creation according to their needs, the :class:`EnvBuilder` class. * ``bin_path`` - The script path for the virtual environment. * ``bin_name`` - The name of the script path relative to the virtual - environment location. Used for ``__VENV_BIN_NAME__`` in activation - scripts (see :meth:`install_scripts`). + environment location. Used for ``__VENV_BIN_NAME__`` in activation + scripts (see :meth:`install_scripts`). * ``env_exe`` - The name of the Python interpreter in the virtual - environment. Used for ``__VENV_PYTHON__`` in activation scripts - (see :meth:`install_scripts`). + environment. Used for ``__VENV_PYTHON__`` in activation scripts + (see :meth:`install_scripts`). * ``env_exec_cmd`` - The name of the Python interpreter, taking into - account filesystem redirections. This can be used to run Python in - the virtual environment. + account filesystem redirections. This can be used to run Python in + the virtual environment. .. versionchanged:: 3.12