Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Implementation of activate.bat portability #371

Open
wants to merge 1 commit into from

1 participant

@juntalis

I saw that there was another pull request implementing similar changes, so I figured there wouldn't be any harm in putting forward my own. I think this implementation is a bit more beneficial, since it effectively results in the same environment variables as the current script, and because it doesn't rely on the use of temporary files or make any assumptions on what environment variables are currently set for the end user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 29, 2012
  1. Implementation of activate.bat portability

    Charles Grunwald (Juntalis) authored
This page is out of date. Refresh to see the latest.
Showing with 51 additions and 23 deletions.
  1. +11 −4 virtualenv.py
  2. +40 −19 virtualenv_embedded/activate.bat
View
15 virtualenv.py
@@ -2265,10 +2265,17 @@ def convert(s):
##file activate.bat
ACTIVATE_BAT = convert("""
-eJx9UdEKgjAUfW6wfxjiIH+hEDKUFHSKLCMI7kNOEkIf9P9pTJ3OLJ/03HPPPed4Es9XS9qqwqgT
-PbGKKOdXL4aAFS7A4gvAwgijuiKlqOpGlATS2NeMLE+TjJM9RkQ+SmqAXLrBo1LLIeLdiWlD6jZt
-r7VNubWkndkXaxg5GO3UaOOKS6drO3luDDiO5my3iA0YAKGzPRV1ack8cOdhysI0CYzIPzjSiH5X
-0QcvC8Lfaj0emsVKYF2rhL5L3fCkVjV76kShi59NHwDniAHzkgDgqBcwOgTMx+gDQQqXCw==
+eJx9VF2L4kAQfN5A/kMjO3cKnqyvSuDWW2+VWz9QTzhYkDHpnME4Eybj14u/fXsmiUZdNg
++B9FRX9VQX+Yn+SoIMQ9f5L7WEAY+E67hO6xX1PFJ6y+Ou2A35Bl1H4Qb6IegVQijjAJWg
+MvXayi4DA4od+FJo4kmBQyB1Hap4aEFjFyW1jCThShd9JaZ9FJv+ALYJRMKe4kGjSCMprn
+oSrleNjKqDPt+m+RSctPb4nVh8uVlGAm84OHFbJUOW5mzFSJYyRQ3jyWgwnnlVdhJNdjo0
+a8CyEss9anVHv61HmVmmfUp9uQPGgImUOiOb9yezv89vi+5w7rFTkDy5ThRChZXqrdOPJq
+t4XuW9AnctV7inOiE/4S2D3qe+ihKdesyMaGaboGmgubk4ArldXlWkpNig0GnDziWkhgBD
+ci7IbYCSI4/jx1cLKyCL0dvLohC/x7NPztkXBP9mvdGwNxp0M5Lz5y3R+SD34hMZ77Kyy4
+IoVnKrIFFyk2i6sM8pKfdBv94OqxQUHe6vDYVxkKuIL2PMbTtbdrlB1XXAPPfzla51dZMz
+vIRwnVqh/muF/hpIbI8gkMRoocps9gtDn2c9M8iDZaWPWyOpRMIPNtTTP/2xKVjJ+6ltd9
+5Ayb+gCRpLcjJr6vSHL/3JVdKz0m3IC2BxWop2ppUdsPZF1LgwpIAqpL0dyQQf05SrYx2W
+Ww1+jFyYFZuUL2Mu1pRvrSK7I/qp2CHhG1wUzLvVbntty/4ByIuHhg==
""")
##file deactivate.bat
View
59 virtualenv_embedded/activate.bat
@@ -1,26 +1,47 @@
@echo off
-set "VIRTUAL_ENV=__VIRTUAL_ENV__"
-
-if defined _OLD_VIRTUAL_PROMPT (
- set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
-) else (
- if not defined PROMPT (
- set "PROMPT=$P$G"
- )
- set "_OLD_VIRTUAL_PROMPT=%PROMPT%"
-)
-set "PROMPT=__VIRTUAL_WINPROMPT__ %PROMPT%"
+goto Main
+
+:GetVirtualEnvName
+rem If the foldername of the virtual env contains a dot, (ex: .vip)
+rem part of the foldername will end up in the extension part of the path.
+rem Because of that, we'll combine the extension and name parts of the
+rem path.
+set PROMPT=(%~n1%~x1) %PROMPT%
+goto :EOF
+
+:Main
+rem Set virtualenv Root
+set VIRTUAL_ENV=%~dp0
+if "%VIRTUAL_ENV:~-1%"=="\" set VIRTUAL_ENV=%VIRTUAL_ENV:~0,-1%
+set VIRTUAL_ENV=%VIRTUAL_ENV:\Scripts=%
-if not defined _OLD_VIRTUAL_PYTHONHOME (
- set "_OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%"
+rem Reset to any old virtual environments.
+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%
+
+rem Set up our prompt.
+call :GetVirtualEnvName "%VIRTUAL_ENV%"
+
+rem Backup old variables.
+if defined PYTHONHOME (
+ set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
+ set PYTHONHOME=
)
-set PYTHONHOME=
+rem Check if we need to reset
if defined _OLD_VIRTUAL_PATH (
- set "PATH=%_OLD_VIRTUAL_PATH%"
-) else (
- set "_OLD_VIRTUAL_PATH=%PATH%"
+ set PATH=%_OLD_VIRTUAL_PATH%
+ goto SKIPPATH
)
-set "PATH=%VIRTUAL_ENV%\__BIN_NAME__;%PATH%"
+set _OLD_VIRTUAL_PATH=%PATH%
+
+:SKIPPATH
+setlocal
+set BINDIR=%~dp0
+if "%BINDIR:~-1%"=="\" set BINDIR=%BINDIR:~0,-1%
+set PATH=%BINDIR%;%PATH%
-:END
+rem Not really necessary, but clean up any blank entries.
+endlocal & set PATH=%PATH:;;=;%
Something went wrong with that request. Please try again.