Commits

Arun Mahapatra committed 4f57637

Fixed issue #8, read wow6432node registry in case of 32bit python installs on a 64bit machine. Activate and Deactivate now backup/restore PYTHONHOME environment variable.

  • Participants
  • Parent commits 4dc1548

Comments (0)

Files changed (2)

File VirtualEnvWrapper/Extensions/Extension.UserScripts.ps1

                                 -arg '-Nologo', `
                                      '-NoProfile', `
                                      # Between quotes so that paths with spaces work.
-                                     '-File', "`"$Script`""
+                                     '-File', "`"$(Resolve-Path $Script)`""
 }
 
 

File VirtualEnvWrapper/Win.psm1

 $VIRTUAL_ENV = $BASE_DIR
 $env:VIRTUAL_ENV = $VIRTUAL_ENV
 
+# TODO: Handle both environment variables and variables in global scope
 $global:_OLD_VIRTUAL_PATH = $env:PATH
 $env:PATH = "$env:VIRTUAL_ENV/Scripts;" + $env:PATH
+if (test-path variable:PYTHONHOME) {
+    $global:_OLD_PYTHONHOME = $env:PYTHONHOME
+    remove-item env:PYTHONHOME
+}
+
 Switch-DefaultPython
+
 function global:_old_virtual_prompt { "" }
 $function:_old_virtual_prompt = $function:prompt
 function global:prompt {
     & $function:_old_virtual_prompt
 }
 
-function global:deactivate ( [switch] $NonDestructive ){
+function global:deactivate ( [switch] $NonDestructive ) {
 
     $venv = split-path $env:VIRTUAL_ENV -leaf
     [void] (New-Event -SourceIdentifier 'VirtualEnvWrapper.PreDeactivateVirtualEnv' -eventarguments $venv)
         remove-variable "_OLD_VIRTUAL_PATH" -scope global
     }
 
+    if ( test-path env:PYTHONHOME ) {
+        $env:PYTHONHOME = $env:_OLD_PYTHONHOME
+        remove-item env:_OLD_PYTHONHOME
+    }
+
     if ( test-path function:_old_virtual_prompt ) {
         $function:prompt = $function:_old_virtual_prompt
         remove-item function:\_old_virtual_prompt
 
 function switchPythonCore
 {
-
+    $pythonCoreRegistry = "HKCU:/Software/Python/PythonCore"
     $currPython = getCurrentPythonExe
     $currPythonW = getCurrentPythonWExe
     $pyVer = & { $OFS = ""; "$((& "python.exe" "-V" 2>&1).exception.message.split(" ")[1][0..2])" }
+    $pyArch = $(& "python.exe" -c 'import platform; print platform.architecture()[0]')
+
+    if ($pyArch -eq "32bit")
+    {
+        $pythonCoreRegistry = "HKLM:/Software/Wow6432Node/Python/PythonCore"
+    }
 
     if ($currPython -like "*Scripts*")
     {
     }
     else
     {
-       $pyBase = resolve-path (split-path $currPython -parent)
+        $pyBase = resolve-path (split-path $currPython -parent)
     }
-    if (-not(test-path "HKCU:/Software/Python/PythonCore"))
+    if (-not(test-path $pythonCoreRegistry))
     {
-        new-item "HKCU:/Software/Python/PythonCore/$pyVer/InstallPath" -Force > $null
-        new-item "HKCU:/Software/Python/PythonCore/$pyVer/PythonPath" > $null
+        new-item "$pythonCoreRegistry/$pyVer/InstallPath" -Force > $null
+        new-item "$pythonCoreRegistry/$pyVer/PythonPath" > $null
     }
-    set-itemproperty -path "HKCU:/Software/Python/PythonCore/$pyVer/InstallPath" -name "(default)" -value $pyBase
-    set-itemproperty -path "HKCU:/Software/Python/PythonCore/$pyVer/PythonPath" -name "(default)" -value "$pyBase\Lib;$pyBase\DLLs;$pyBase\Lib\lib-tk"
+    set-itemproperty -path "$pythonCoreRegistry/$pyVer/InstallPath" -name "(default)" -value $pyBase
+    set-itemproperty -path "$pythonCoreRegistry/$pyVer/PythonPath" -name "(default)" -value "$pyBase\Lib;$pyBase\DLLs;$pyBase\Lib\lib-tk"
 }
 
 function Switch-DefaultPython