Skip to content

Commit

Permalink
Touch up venv docs (pythonGH-14922)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcannon authored Jul 23, 2019
1 parent c6fd6c8 commit 2f224a0
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions Doc/library/venv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Creating virtual environments
A virtual environment is a directory tree which contains Python executable
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
environment is active, they install Python packages into the virtual
environment without needing to be told to do so explicitly.
Expand All @@ -64,24 +64,25 @@ Creating virtual environments
Python installation).

When a virtual environment is active, any options that change the
installation path will be ignored from all distutils configuration files to
prevent projects being inadvertently installed outside of the virtual
environment.
installation path will be ignored from all :mod:`distutils` configuration
files to prevent projects being inadvertently installed outside of the
virtual environment.

When working in a command shell, users can make a virtual environment active
by running an ``activate`` script in the virtual environment's executables
directory (the precise filename is shell-dependent), which prepends the
virtual environment's directory for executables to the ``PATH`` environment
variable for the running shell. There should be no need in other
circumstances to activate a virtual environment—scripts installed into
virtual environments have a "shebang" line which points to the virtual
environment's Python interpreter. This means that the script will run with
that interpreter regardless of the value of ``PATH``. On Windows, "shebang"
line processing is supported if you have the Python Launcher for Windows
installed (this was added to Python in 3.3 - see :pep:`397` for more
details). Thus, double-clicking an installed script in a Windows Explorer
window should run the script with the correct interpreter without there
needing to be any reference to its virtual environment in ``PATH``.
directory (the precise filename and command to use the file is
shell-dependent), which prepends the virtual environment's directory for
executables to the ``PATH`` environment variable for the running shell. There
should be no need in other circumstances to activate a virtual
environment; scripts installed into virtual environments have a "shebang"
line which points to the virtual environment's Python interpreter. This means
that the script will run with that interpreter regardless of the value of
``PATH``. On Windows, "shebang" line processing is supported if you have the
Python Launcher for Windows installed (this was added to Python in 3.3 - see
:pep:`397` for more details). Thus, double-clicking an installed script in a
Windows Explorer window should run the script with the correct interpreter
without there needing to be any reference to its virtual environment in
``PATH``.


.. _venv-api:
Expand Down Expand Up @@ -135,20 +136,20 @@ creation according to their needs, the :class:`EnvBuilder` class.
Added the ``upgrade_deps`` parameter

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``:

.. method:: create(env_dir)

This method takes as required argument the path (absolute or relative to
the current directory) of the target directory which is to contain the
Create a virtual environment by specifying the target directory
(absolute or relative to the current directory) which is to contain the
virtual environment. The ``create`` method will either create the
environment in the specified directory, or raise an appropriate
exception.

The ``create`` method of the ``EnvBuilder`` class illustrates the hooks
available for subclass customization::
The ``create`` method of the :class:`EnvBuilder` class illustrates the
hooks available for subclass customization::

def create(self, env_dir):
"""
Expand Down Expand Up @@ -476,3 +477,7 @@ subclass which installs setuptools and pip into a created virtual environment::

This script is also available for download `online
<https://gist.github.com/vsajip/4673395>`_.


.. _setuptools: https://pypi.org/project/setuptools/
.. _pip: https://pypi.org/project/pip/

0 comments on commit 2f224a0

Please sign in to comment.