Commits

Axel H.  committed c8db297

Added msys paths support

  • Participants
  • Parent commits c847d8f

Comments (0)

Files changed (2)

File virtualenvwrapper.sh

     VIRTUALENVWRAPPER_VIRTUALENV="virtualenv"
 fi
 
+# Define script folder depending on the platorm (Win32/Unix)
+script_folder="bin"
+if [ "$OS" = "Windows_NT" ] && [ "$MSYSTEM" = "MINGW32" ]
+then
+	# Only assign this for msys, cygwin use standard Unix paths
+	# and its own python installation 
+	script_folder="Scripts"
+fi
+
 virtualenvwrapper_derive_workon_home() {
     typeset workon_home_dir="$WORKON_HOME"
 
     # NOTE: DO NOT use ls here because colorized versions spew control characters
     #       into the output list.
     # echo seems a little faster than find, even with -depth 3.
-    (cd "$WORKON_HOME"; for f in */bin/activate; do echo $f; done) 2>/dev/null | \sed 's|^\./||' | \sed 's|/bin/activate||' | \sort | (unset GREP_OPTIONS; \egrep -v '^\*$')
+    (cd "$WORKON_HOME"; for f in */$script_folder/activate; do echo $f; done) 2>/dev/null | \sed 's|^\./||' | \sed 's|/bin/activate||' | \sort | (unset GREP_OPTIONS; \egrep -v '^\*$')
     
 #    (cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
 }
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_workon_environment $env_name || return 1
     
-    activate="$WORKON_HOME/$env_name/bin/activate"
+    activate="$WORKON_HOME/$env_name/$script_folder/activate"
     if [ ! -f "$activate" ]
     then
         echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script." >&2
         # any settings made by the local postactivate first.
         virtualenvwrapper_run_hook "pre_deactivate"
         
-        env_postdeactivate_hook="$VIRTUAL_ENV/bin/postdeactivate"
+        env_postdeactivate_hook="$VIRTUAL_ENV/$script_folder/postdeactivate"
         old_env=$(basename "$VIRTUAL_ENV")
         
         # Call the original function.
     fi
 
     \cp -r "$source_env" "$target_env"
-    for script in $( \ls $target_env/bin/* )
+    for script in $( \ls $target_env/$script_folder/* )
     do
         newscript="$script-new"
         \sed "s|$source_env|$target_env|g" < "$script" > "$newscript"
     done
 
     virtualenv "$target_env" --relocatable
-    \sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/bin/activate" > "$target_env/bin/activate"
+    \sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/bin/activate" > "$target_env/$script_folder/activate"
 
     (cd "$WORKON_HOME" && ( 
         virtualenvwrapper_run_hook "pre_cpvirtualenv" "$env_name" "$new_env";

File virtualenvwrapper/user_scripts.py

 
 import logging
 import os
+import re
 import stat
 import subprocess
+import sys
 
 import pkg_resources
 
 log = logging.getLogger(__name__)
 
+    
+# Are we running under msys
+if sys.platform == 'win32' and os.environ.get('OS') == 'Windows_NT' and os.environ.get('MSYSTEM') == 'MINGW32':
+    msys = True
+    script_folder = 'Scripts'
+else:
+    script_folder = 'bin'
+
 
 def run_script(script_path, *args):
     """Execute a script in a subshell.
     """
     if os.path.exists(script_path):
         cmd = [script_path] + list(args)
+        if msys:
+            cmd = [os.path.join(os.environ['MSYS_HOME'],'bin','sh.exe')] + cmd
         log.debug('running %s', str(cmd))
         try:
             return_code = subprocess.call(cmd)
 def run_global(script_name, *args):
     """Run a script from $VIRTUALENVWRAPPER_HOOK_DIR.
     """
-    script_path = os.path.expandvars(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', script_name))
+    script_path = get_path('$VIRTUALENVWRAPPER_HOOK_DIR', script_name)
     run_script(script_path, *args)
     return
 
     :param filename: The name of the file to write.
     :param comment: The comment to insert into the file.
     """
-    filename = os.path.expanduser(os.path.expandvars(filename))
+    filename = get_path(filename)
     if not os.path.exists(filename):
         log.info('creating %s', filename)
         f = open(filename, 'w')
 
 def initialize(args):
     for filename, comment in GLOBAL_HOOKS:
-        make_hook(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment)
+        make_hook(get_path('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment)
     return
 
 
     log.debug('pre_mkvirtualenv %s', str(args))
     envname=args[0]
     for filename, comment in LOCAL_HOOKS:
-        make_hook(os.path.join('$WORKON_HOME', envname, 'bin', filename), comment)
+        make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
     run_global('premkvirtualenv', *args)
     return
 
     log.debug('pre_cpvirtualenv %s', str(args))
     envname=args[0]
     for filename, comment in LOCAL_HOOKS:
-        make_hook(os.path.join('$WORKON_HOME', envname, 'bin', filename), comment)
+        make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
     run_global('precpvirtualenv', *args)
     return
 
 def pre_activate(args):
     log.debug('pre_activate')
     run_global('preactivate', *args)
-    script_path = os.path.expandvars(os.path.join('$WORKON_HOME', args[0], 'bin', 'preactivate'))
+    script_path = get_path('$WORKON_HOME', args[0], script_folder, 'preactivate')
     run_script(script_path, *args)
     return
 
 def get_env_details(args):
     log.debug('get_env_details')
     run_global('get_env_details', *args)
-    script_path = os.path.expandvars(os.path.join('$WORKON_HOME', args[0], 'bin', 'get_env_details'))
+    script_path = get_path('$WORKON_HOME', args[0], script_folder, 'get_env_details')
     run_script(script_path, *args)
     return
+
+def get_path(*args):
+    '''
+    Get a full path from args.
+    Path separator is determined according to the os and the shell and allow to use msys.
+    Variables and user are expanded during the process.
+    '''
+    path = os.path.expanduser(os.path.expandvars(os.path.join(*args)))
+    if msys:
+        # MSYS accept unix or Win32 and sometimes it conduce to mixed style paths
+        if re.match(r'^/[a-zA-Z](/|^)', path):
+            # msys path could starts with '/c/'-form drive letter
+            path = ''.join((path[1],':',path[2:]))
+        path = path.replace('/', os.sep)
+        
+    return os.path.abspath(path)