Commit 2f224a07 authored by Brett Cannon's avatar Brett Cannon Committed by GitHub

Touch up venv docs (GH-14922)

parent c6fd6c83
...@@ -47,7 +47,7 @@ Creating virtual environments ...@@ -47,7 +47,7 @@ Creating virtual environments
A virtual environment is a directory tree which contains Python executable A virtual environment is a directory tree which contains Python executable
files and other files which indicate that it is a virtual environment. files and other files which indicate that it is a virtual environment.
Common installation tools such as ``Setuptools`` and ``pip`` work as Common installation tools such as setuptools_ and pip_ work as
expected with virtual environments. In other words, when a virtual expected with virtual environments. In other words, when a virtual
environment is active, they install Python packages into the virtual environment is active, they install Python packages into the virtual
environment without needing to be told to do so explicitly. environment without needing to be told to do so explicitly.
...@@ -64,24 +64,25 @@ Creating virtual environments ...@@ -64,24 +64,25 @@ Creating virtual environments
Python installation). Python installation).
When a virtual environment is active, any options that change the When a virtual environment is active, any options that change the
installation path will be ignored from all distutils configuration files to installation path will be ignored from all :mod:`distutils` configuration
prevent projects being inadvertently installed outside of the virtual files to prevent projects being inadvertently installed outside of the
environment. virtual environment.
When working in a command shell, users can make a virtual environment active When working in a command shell, users can make a virtual environment active
by running an ``activate`` script in the virtual environment's executables by running an ``activate`` script in the virtual environment's executables
directory (the precise filename is shell-dependent), which prepends the directory (the precise filename and command to use the file is
virtual environment's directory for executables to the ``PATH`` environment shell-dependent), which prepends the virtual environment's directory for
variable for the running shell. There should be no need in other executables to the ``PATH`` environment variable for the running shell. There
circumstances to activate a virtual environment—scripts installed into should be no need in other circumstances to activate a virtual
virtual environments have a "shebang" line which points to the virtual environment; scripts installed into virtual environments have a "shebang"
environment's Python interpreter. This means that the script will run with line which points to the virtual environment's Python interpreter. This means
that interpreter regardless of the value of ``PATH``. On Windows, "shebang" that the script will run with that interpreter regardless of the value of
line processing is supported if you have the Python Launcher for Windows ``PATH``. On Windows, "shebang" line processing is supported if you have the
installed (this was added to Python in 3.3 - see :pep:`397` for more Python Launcher for Windows installed (this was added to Python in 3.3 - see
details). Thus, double-clicking an installed script in a Windows Explorer :pep:`397` for more details). Thus, double-clicking an installed script in a
window should run the script with the correct interpreter without there Windows Explorer window should run the script with the correct interpreter
needing to be any reference to its virtual environment in ``PATH``. without there needing to be any reference to its virtual environment in
``PATH``.
.. _venv-api: .. _venv-api:
...@@ -135,20 +136,20 @@ creation according to their needs, the :class:`EnvBuilder` class. ...@@ -135,20 +136,20 @@ creation according to their needs, the :class:`EnvBuilder` class.
Added the ``upgrade_deps`` parameter Added the ``upgrade_deps`` parameter
Creators of third-party virtual environment tools will be free to use the Creators of third-party virtual environment tools will be free to use the
provided ``EnvBuilder`` class as a base class. provided :class:`EnvBuilder` class as a base class.
The returned env-builder is an object which has a method, ``create``: The returned env-builder is an object which has a method, ``create``:
.. method:: create(env_dir) .. method:: create(env_dir)
This method takes as required argument the path (absolute or relative to Create a virtual environment by specifying the target directory
the current directory) of the target directory which is to contain the (absolute or relative to the current directory) which is to contain the
virtual environment. The ``create`` method will either create the virtual environment. The ``create`` method will either create the
environment in the specified directory, or raise an appropriate environment in the specified directory, or raise an appropriate
exception. exception.
The ``create`` method of the ``EnvBuilder`` class illustrates the hooks The ``create`` method of the :class:`EnvBuilder` class illustrates the
available for subclass customization:: hooks available for subclass customization::
def create(self, env_dir): def create(self, env_dir):
""" """
...@@ -476,3 +477,7 @@ subclass which installs setuptools and pip into a created virtual environment:: ...@@ -476,3 +477,7 @@ subclass which installs setuptools and pip into a created virtual environment::
This script is also available for download `online This script is also available for download `online
<https://gist.github.com/vsajip/4673395>`_. <https://gist.github.com/vsajip/4673395>`_.
.. _setuptools: https://pypi.org/project/setuptools/
.. _pip: https://pypi.org/project/pip/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment