diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-05-26 02:45:29 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-05-26 02:45:29 (GMT) |
commit | 7ded1f0f694f0f99252ea19eca18b74ea5e36cb0 (patch) | |
tree | 1f07c57fddc9627f3d506b7a8d25ded561f5a2e0 /Lib/venv/scripts | |
parent | f2bdc3690a59ca2af3f2fa82f506350874ff1467 (diff) | |
download | cpython-7ded1f0f694f0f99252ea19eca18b74ea5e36cb0.zip cpython-7ded1f0f694f0f99252ea19eca18b74ea5e36cb0.tar.gz cpython-7ded1f0f694f0f99252ea19eca18b74ea5e36cb0.tar.bz2 |
Implemented PEP 405 (Python virtual environments).
Diffstat (limited to 'Lib/venv/scripts')
-rw-r--r-- | Lib/venv/scripts/nt/Activate.ps1 | 34 | ||||
-rw-r--r-- | Lib/venv/scripts/nt/Deactivate.ps1 | 19 | ||||
-rw-r--r-- | Lib/venv/scripts/nt/activate.bat | 31 | ||||
-rw-r--r-- | Lib/venv/scripts/nt/deactivate.bat | 17 | ||||
-rw-r--r-- | Lib/venv/scripts/nt/pysetup3-script.py | 11 | ||||
-rw-r--r-- | Lib/venv/scripts/nt/pysetup3.exe | bin | 0 -> 6144 bytes | |||
-rw-r--r-- | Lib/venv/scripts/posix/activate | 76 | ||||
-rw-r--r-- | Lib/venv/scripts/posix/pysetup3 | 11 |
8 files changed, 199 insertions, 0 deletions
diff --git a/Lib/venv/scripts/nt/Activate.ps1 b/Lib/venv/scripts/nt/Activate.ps1 new file mode 100644 index 0000000..967ba5c --- /dev/null +++ b/Lib/venv/scripts/nt/Activate.ps1 @@ -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"
diff --git a/Lib/venv/scripts/nt/Deactivate.ps1 b/Lib/venv/scripts/nt/Deactivate.ps1 new file mode 100644 index 0000000..3d1e96b --- /dev/null +++ b/Lib/venv/scripts/nt/Deactivate.ps1 @@ -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
+}
diff --git a/Lib/venv/scripts/nt/activate.bat b/Lib/venv/scripts/nt/activate.bat new file mode 100644 index 0000000..c45e65a --- /dev/null +++ b/Lib/venv/scripts/nt/activate.bat @@ -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
diff --git a/Lib/venv/scripts/nt/deactivate.bat b/Lib/venv/scripts/nt/deactivate.bat new file mode 100644 index 0000000..62da5b1 --- /dev/null +++ b/Lib/venv/scripts/nt/deactivate.bat @@ -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
diff --git a/Lib/venv/scripts/nt/pysetup3-script.py b/Lib/venv/scripts/nt/pysetup3-script.py new file mode 100644 index 0000000..cfc6661 --- /dev/null +++ b/Lib/venv/scripts/nt/pysetup3-script.py @@ -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)
diff --git a/Lib/venv/scripts/nt/pysetup3.exe b/Lib/venv/scripts/nt/pysetup3.exe Binary files differnew file mode 100644 index 0000000..3f3c09e --- /dev/null +++ b/Lib/venv/scripts/nt/pysetup3.exe diff --git a/Lib/venv/scripts/posix/activate b/Lib/venv/scripts/posix/activate new file mode 100644 index 0000000..c241450 --- /dev/null +++ b/Lib/venv/scripts/posix/activate @@ -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 diff --git a/Lib/venv/scripts/posix/pysetup3 b/Lib/venv/scripts/posix/pysetup3 new file mode 100644 index 0000000..900f50e --- /dev/null +++ b/Lib/venv/scripts/posix/pysetup3 @@ -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) |