summaryrefslogtreecommitdiffstats
path: root/Lib/venv/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/venv/__init__.py')
-rw-r--r--Lib/venv/__init__.py58
1 files changed, 14 insertions, 44 deletions
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index 74245ab..0a094e3 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -3,28 +3,6 @@ Virtual environment (venv) package for Python. Based on PEP 405.
Copyright (C) 2011-2014 Vinay Sajip.
Licensed to the PSF under a contributor agreement.
-
-usage: python -m venv [-h] [--system-site-packages] [--symlinks] [--clear]
- [--upgrade]
- ENV_DIR [ENV_DIR ...]
-
-Creates virtual Python environments in one or more target directories.
-
-positional arguments:
- ENV_DIR A directory to create the environment in.
-
-optional arguments:
- -h, --help show this help message and exit
- --system-site-packages
- Give the virtual environment access to the system
- site-packages dir.
- --symlinks Attempt to symlink rather than copy.
- --clear Delete the contents of the environment directory if it
- already exists, before environment creation.
- --upgrade Upgrade the environment directory to use this version
- of Python, assuming Python has been upgraded in-place.
- --without-pip Skips installing or upgrading pip in the virtual
- environment (pip is bootstrapped by default)
"""
import logging
import os
@@ -58,15 +36,17 @@ class EnvBuilder:
:param upgrade: If True, upgrade an existing virtual environment.
:param with_pip: If True, ensure pip is installed in the virtual
environment
+ :param prompt: Alternative terminal prefix for the environment.
"""
def __init__(self, system_site_packages=False, clear=False,
- symlinks=False, upgrade=False, with_pip=False):
+ symlinks=False, upgrade=False, with_pip=False, prompt=None):
self.system_site_packages = system_site_packages
self.clear = clear
self.symlinks = symlinks
self.upgrade = upgrade
self.with_pip = with_pip
+ self.prompt = prompt
def create(self, env_dir):
"""
@@ -112,7 +92,8 @@ class EnvBuilder:
context = types.SimpleNamespace()
context.env_dir = env_dir
context.env_name = os.path.split(env_dir)[1]
- context.prompt = '(%s) ' % context.env_name
+ prompt = self.prompt if self.prompt is not None else context.env_name
+ context.prompt = '(%s) ' % prompt
create_if_needed(env_dir)
env = os.environ
if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in env:
@@ -348,26 +329,11 @@ class EnvBuilder:
def create(env_dir, system_site_packages=False, clear=False,
- symlinks=False, with_pip=False):
- """
- Create a virtual environment in a directory.
-
- By default, makes the system (global) site-packages dir *un*available to
- the created environment, and uses copying rather than symlinking for files
- obtained from the source Python installation.
-
- :param env_dir: The target directory to create an environment in.
- :param system_site_packages: If True, the system (global) site-packages
- dir is available to the environment.
- :param clear: If True, delete the contents of the environment directory if
- it already exists, before environment creation.
- :param symlinks: If True, attempt to symlink rather than copy files into
- virtual environment.
- :param with_pip: If True, ensure pip is installed in the virtual
- environment
- """
+ symlinks=False, with_pip=False, prompt=None):
+ """Create a virtual environment in a directory."""
builder = EnvBuilder(system_site_packages=system_site_packages,
- clear=clear, symlinks=symlinks, with_pip=with_pip)
+ clear=clear, symlinks=symlinks, with_pip=with_pip,
+ prompt=prompt)
builder.create(env_dir)
def main(args=None):
@@ -427,6 +393,9 @@ def main(args=None):
help='Skips installing or upgrading pip in the '
'virtual environment (pip is bootstrapped '
'by default)')
+ parser.add_argument('--prompt',
+ help='Provides an alternative prompt prefix for '
+ 'this environment.')
options = parser.parse_args(args)
if options.upgrade and options.clear:
raise ValueError('you cannot supply --upgrade and --clear together.')
@@ -434,7 +403,8 @@ def main(args=None):
clear=options.clear,
symlinks=options.symlinks,
upgrade=options.upgrade,
- with_pip=options.with_pip)
+ with_pip=options.with_pip,
+ prompt=options.prompt)
for d in options.dirs:
builder.create(d)