global:deactivate([switch]$NonDestructive)1function global:deactivate ([switch]$NonDestructive) { 2 # Revert to original values 3 if (Test-Path function:_OLD_VIRTUAL_PROMPT) { 4 copy-item function:_OLD_VIRTUAL_PROMPT function:prompt 5 remove-item function:_OLD_VIRTUAL_PROMPT 6 } 7 8 if (Test-Path env:_OLD_VIRTUAL_PYTHONHOME) { 9 copy-item env:_OLD_VIRTUAL_PYTHONHOME env:PYTHONHOME 10 remove-item env:_OLD_VIRTUAL_PYTHONHOME 11 } 12 13 if (Test-Path env:_OLD_VIRTUAL_PATH) { 14 copy-item env:_OLD_VIRTUAL_PATH env:PATH 15 remove-item env:_OLD_VIRTUAL_PATH 16 } 17 18 if (Test-Path env:VIRTUAL_ENV) { 19 remove-item env:VIRTUAL_ENV 20 } 21 22 if (!$NonDestructive) { 23 # Self destruct! 24 remove-item function:deactivate 25 } 26 } 27 28 deactivate -nondestructive 29 30 $env:VIRTUAL_ENV="__VENV_DIR__" 31 32 if (! $env:VIRTUAL_ENV_DISABLE_PROMPT) { 33 # Set the prompt to include the env name 34 # Make sure _OLD_VIRTUAL_PROMPT is global global:_OLD_VIRTUAL_PROMPT()35 function global:_OLD_VIRTUAL_PROMPT {""} 36 copy-item function:prompt function:_OLD_VIRTUAL_PROMPT global:prompt()37 function global:prompt { 38 Write-Host -NoNewline -ForegroundColor Green '__VENV_PROMPT__' 39 _OLD_VIRTUAL_PROMPT 40 } 41 } 42 43 # Clear PYTHONHOME 44 if (Test-Path env:PYTHONHOME) { 45 copy-item env:PYTHONHOME env:_OLD_VIRTUAL_PYTHONHOME 46 remove-item env:PYTHONHOME 47 } 48 49 # Add the venv to the PATH 50 copy-item env:PATH env:_OLD_VIRTUAL_PATH 51 $env:PATH = "$env:VIRTUAL_ENV\__VENV_BIN_NAME__;$env:PATH" 52