Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
fd0f84bd
Commit
fd0f84bd
authored
Aug 06, 2016
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #22829: Added --prompt option to venv.
parent
c0752011
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
6 deletions
+41
-6
Doc/library/venv.rst
Doc/library/venv.rst
+9
-1
Doc/whatsnew/3.6.rst
Doc/whatsnew/3.6.rst
+8
-0
Lib/test/test_venv.py
Lib/test/test_venv.py
+11
-0
Lib/venv/__init__.py
Lib/venv/__init__.py
+13
-5
No files found.
Doc/library/venv.rst
View file @
fd0f84bd
...
...
@@ -89,7 +89,8 @@ mechanisms for third-party virtual environment creators to customize environment
creation according to their needs, the :class:`EnvBuilder` class.
.. class:: EnvBuilder(system_site_packages=False, clear=False, \
symlinks=False, upgrade=False, with_pip=False)
symlinks=False, upgrade=False, with_pip=False, \
prompt=None)
The :class:`EnvBuilder` class accepts the following keyword arguments on
instantiation:
...
...
@@ -113,9 +114,16 @@ creation according to their needs, the :class:`EnvBuilder` class.
installed in the virtual environment. This uses :mod:`ensurepip` with
the ``--default-pip`` option.
* ``prompt`` -- a String to be used after virtual environment is activated
(defaults to ``None`` which means directory name of the environment would
be used).
.. versionchanged:: 3.4
Added the ``with_pip`` parameter
.. versionadded:: 3.6
Added the ``prompt`` parameter
Creators of third-party virtual environment tools will be free to use the
provided ``EnvBuilder`` class as a base class.
...
...
Doc/whatsnew/3.6.rst
View file @
fd0f84bd
...
...
@@ -284,6 +284,14 @@ class has been added to the :mod:`typing` module as
(Contributed by Brett Cannon in :issue:`25609`.)
venv
----
:mod:`venv` accepts a new parameter ``--prompt``. This parameter provides an
alternative prefix for the virtual environment. (Proposed by Łukasz.Balcerzak
and ported to 3.6 by Stéphane Wirtel in :issue:`22829`.)
datetime
--------
...
...
Lib/test/test_venv.py
View file @
fd0f84bd
...
...
@@ -114,6 +114,17 @@ class BasicTest(BaseTest):
print
(
' %r'
%
os
.
listdir
(
bd
))
self
.
assertTrue
(
os
.
path
.
exists
(
fn
),
'File %r should exist.'
%
fn
)
def
test_prompt
(
self
):
env_name
=
os
.
path
.
split
(
self
.
env_dir
)[
1
]
builder
=
venv
.
EnvBuilder
()
context
=
builder
.
ensure_directories
(
self
.
env_dir
)
self
.
assertEqual
(
context
.
prompt
,
'(%s) '
%
env_name
)
builder
=
venv
.
EnvBuilder
(
prompt
=
'My prompt'
)
context
=
builder
.
ensure_directories
(
self
.
env_dir
)
self
.
assertEqual
(
context
.
prompt
,
'(My prompt) '
)
@
skipInVenv
def
test_prefixes
(
self
):
"""
...
...
Lib/venv/__init__.py
View file @
fd0f84bd
...
...
@@ -36,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
):
"""
...
...
@@ -90,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
:
...
...
@@ -326,10 +329,11 @@ class EnvBuilder:
def
create
(
env_dir
,
system_site_packages
=
False
,
clear
=
False
,
symlinks
=
False
,
with_pip
=
False
):
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
):
...
...
@@ -389,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.'
)
...
...
@@ -396,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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment