mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Implemented PEP 405 (Python virtual environments).
This commit is contained in:
parent
f2bdc3690a
commit
7ded1f0f69
41 changed files with 1454 additions and 66 deletions
34
Lib/venv/scripts/nt/Activate.ps1
Normal file
34
Lib/venv/scripts/nt/Activate.ps1
Normal file
|
@ -0,0 +1,34 @@
|
|||
$env:VIRTUAL_ENV="__VENV_DIR__"
|
||||
|
||||
# Revert to original values
|
||||
if (Test-Path function:_OLD_VIRTUAL_PROMPT) {
|
||||
copy-item function:_OLD_VIRTUAL_PROMPT function:prompt
|
||||
remove-item function:_OLD_VIRTUAL_PROMPT
|
||||
}
|
||||
|
||||
if (Test-Path env:_OLD_VIRTUAL_PYTHONHOME) {
|
||||
copy-item env:_OLD_VIRTUAL_PYTHONHOME env:PYTHONHOME
|
||||
remove-item env:_OLD_VIRTUAL_PYTHONHOME
|
||||
}
|
||||
|
||||
if (Test-Path env:_OLD_VIRTUAL_PATH) {
|
||||
copy-item env:_OLD_VIRTUAL_PATH env:PATH
|
||||
remove-item env:_OLD_VIRTUAL_PATH
|
||||
}
|
||||
|
||||
# Set the prompt to include the env name
|
||||
copy-item function:prompt function:_OLD_VIRTUAL_PROMPT
|
||||
function prompt {
|
||||
Write-Host -NoNewline -ForegroundColor Green [__VENV_NAME__]
|
||||
_OLD_VIRTUAL_PROMPT
|
||||
}
|
||||
|
||||
# Clear PYTHONHOME
|
||||
if (Test-Path env:PYTHONHOME) {
|
||||
copy-item env:PYTHONHOME env:_OLD_VIRTUAL_PYTHONHOME
|
||||
remove-item env:PYTHONHOME
|
||||
}
|
||||
|
||||
# Add the venv to the PATH
|
||||
copy-item env:PATH env:_OLD_VIRTUAL_PATH
|
||||
$env:PATH = "$env:VIRTUAL_ENV\__VENV_BIN_NAME__;$env:PATH"
|
19
Lib/venv/scripts/nt/Deactivate.ps1
Normal file
19
Lib/venv/scripts/nt/Deactivate.ps1
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Revert to original values
|
||||
if (Test-Path function:_OLD_VIRTUAL_PROMPT) {
|
||||
copy-item function:_OLD_VIRTUAL_PROMPT function:prompt
|
||||
remove-item function:_OLD_VIRTUAL_PROMPT
|
||||
}
|
||||
|
||||
if (Test-Path env:_OLD_VIRTUAL_PYTHONHOME) {
|
||||
copy-item env:_OLD_VIRTUAL_PYTHONHOME env:PYTHONHOME
|
||||
remove-item env:_OLD_VIRTUAL_PYTHONHOME
|
||||
}
|
||||
|
||||
if (Test-Path env:_OLD_VIRTUAL_PATH) {
|
||||
copy-item env:_OLD_VIRTUAL_PATH env:PATH
|
||||
remove-item env:_OLD_VIRTUAL_PATH
|
||||
}
|
||||
|
||||
if (Test-Path env:VIRTUAL_ENV) {
|
||||
remove-item env:VIRTUAL_ENV
|
||||
}
|
31
Lib/venv/scripts/nt/activate.bat
Normal file
31
Lib/venv/scripts/nt/activate.bat
Normal file
|
@ -0,0 +1,31 @@
|
|||
@echo off
|
||||
set VIRTUAL_ENV=__VENV_DIR__
|
||||
|
||||
if not defined PROMPT (
|
||||
set PROMPT=$P$G
|
||||
)
|
||||
|
||||
if defined _OLD_VIRTUAL_PROMPT (
|
||||
set PROMPT=%_OLD_VIRTUAL_PROMPT%
|
||||
)
|
||||
|
||||
if defined _OLD_VIRTUAL_PYTHONHOME (
|
||||
set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%
|
||||
)
|
||||
|
||||
set _OLD_VIRTUAL_PROMPT=%PROMPT%
|
||||
set PROMPT=__VENV_NAME__%PROMPT%
|
||||
|
||||
if defined PYTHONHOME (
|
||||
set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
|
||||
set PYTHONHOME=
|
||||
)
|
||||
|
||||
if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%; goto SKIPPATH
|
||||
|
||||
set _OLD_VIRTUAL_PATH=%PATH%
|
||||
|
||||
:SKIPPATH
|
||||
set PATH=%VIRTUAL_ENV%\__VENV_BIN_NAME__;%PATH%
|
||||
|
||||
:END
|
17
Lib/venv/scripts/nt/deactivate.bat
Normal file
17
Lib/venv/scripts/nt/deactivate.bat
Normal file
|
@ -0,0 +1,17 @@
|
|||
@echo off
|
||||
|
||||
if defined _OLD_VIRTUAL_PROMPT (
|
||||
set PROMPT=%_OLD_VIRTUAL_PROMPT%
|
||||
)
|
||||
set _OLD_VIRTUAL_PROMPT=
|
||||
|
||||
if defined _OLD_VIRTUAL_PYTHONHOME (
|
||||
set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%
|
||||
set _OLD_VIRTUAL_PYTHONHOME=
|
||||
)
|
||||
|
||||
if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%
|
||||
|
||||
set _OLD_VIRTUAL_PATH=
|
||||
|
||||
:END
|
11
Lib/venv/scripts/nt/pysetup3-script.py
Normal file
11
Lib/venv/scripts/nt/pysetup3-script.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!__VENV_PYTHON__
|
||||
if __name__ == '__main__':
|
||||
rc = 1
|
||||
try:
|
||||
import sys, re, packaging.run
|
||||
sys.argv[0] = re.sub('-script.pyw?$', '', sys.argv[0])
|
||||
rc = packaging.run.main() # None interpreted as 0
|
||||
except Exception:
|
||||
# use syntax which works with either 2.x or 3.x
|
||||
sys.stderr.write('%s\n' % sys.exc_info()[1])
|
||||
sys.exit(rc)
|
BIN
Lib/venv/scripts/nt/pysetup3.exe
Normal file
BIN
Lib/venv/scripts/nt/pysetup3.exe
Normal file
Binary file not shown.
76
Lib/venv/scripts/posix/activate
Normal file
76
Lib/venv/scripts/posix/activate
Normal file
|
@ -0,0 +1,76 @@
|
|||
# This file must be used with "source bin/activate" *from bash*
|
||||
# you cannot run it directly
|
||||
|
||||
deactivate () {
|
||||
# reset old environment variables
|
||||
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
|
||||
PATH="$_OLD_VIRTUAL_PATH"
|
||||
export PATH
|
||||
unset _OLD_VIRTUAL_PATH
|
||||
fi
|
||||
if [ -n "$_OLD_VIRTUAL_PYTHONHOME" ] ; then
|
||||
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
|
||||
export PYTHONHOME
|
||||
unset _OLD_VIRTUAL_PYTHONHOME
|
||||
fi
|
||||
|
||||
# This should detect bash and zsh, which have a hash command that must
|
||||
# be called to get it to forget past commands. Without forgetting
|
||||
# past commands the $PATH changes we made may not be respected
|
||||
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
|
||||
hash -r
|
||||
fi
|
||||
|
||||
if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
|
||||
PS1="$_OLD_VIRTUAL_PS1"
|
||||
export PS1
|
||||
unset _OLD_VIRTUAL_PS1
|
||||
fi
|
||||
|
||||
unset VIRTUAL_ENV
|
||||
if [ ! "$1" = "nondestructive" ] ; then
|
||||
# Self destruct!
|
||||
unset -f deactivate
|
||||
fi
|
||||
}
|
||||
|
||||
# unset irrelavent variables
|
||||
deactivate nondestructive
|
||||
|
||||
VIRTUAL_ENV="__VENV_DIR__"
|
||||
export VIRTUAL_ENV
|
||||
|
||||
_OLD_VIRTUAL_PATH="$PATH"
|
||||
PATH="$VIRTUAL_ENV/__VENV_BIN_NAME__:$PATH"
|
||||
export PATH
|
||||
|
||||
# unset PYTHONHOME if set
|
||||
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
||||
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
||||
if [ -n "$PYTHONHOME" ] ; then
|
||||
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
|
||||
unset PYTHONHOME
|
||||
fi
|
||||
|
||||
if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
|
||||
_OLD_VIRTUAL_PS1="$PS1"
|
||||
if [ "x__VENV_NAME__" != x ] ; then
|
||||
PS1="__VENV_NAME__$PS1"
|
||||
else
|
||||
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
|
||||
# special case for Aspen magic directories
|
||||
# see http://www.zetadev.com/software/aspen/
|
||||
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
|
||||
else
|
||||
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
|
||||
fi
|
||||
fi
|
||||
export PS1
|
||||
fi
|
||||
|
||||
# This should detect bash and zsh, which have a hash command that must
|
||||
# be called to get it to forget past commands. Without forgetting
|
||||
# past commands the $PATH changes we made may not be respected
|
||||
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
|
||||
hash -r
|
||||
fi
|
11
Lib/venv/scripts/posix/pysetup3
Normal file
11
Lib/venv/scripts/posix/pysetup3
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!__VENV_PYTHON__
|
||||
if __name__ == '__main__':
|
||||
rc = 1
|
||||
try:
|
||||
import sys, re, packaging.run
|
||||
sys.argv[0] = re.sub('-script.pyw?$', '', sys.argv[0])
|
||||
rc = packaging.run.main() # None interpreted as 0
|
||||
except Exception:
|
||||
# use syntax which works with either 2.x or 3.x
|
||||
sys.stderr.write('%s\n' % sys.exc_info()[1])
|
||||
sys.exit(rc)
|
Loading…
Add table
Add a link
Reference in a new issue