forked from mirror/conan-config
5 changed files with 156 additions and 19 deletions
@ -0,0 +1,77 @@
|
||||
<# |
||||
.Synopsis |
||||
Activate a Python virtual environment for the current PowerShell session. |
||||
|
||||
.Notes |
||||
On Windows, it may be required to enable this Activate.ps1 script by setting the |
||||
execution policy for the user. You can do this by issuing the following PowerShell |
||||
command: |
||||
|
||||
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser |
||||
|
||||
For more information on Execution Policies: |
||||
https://go.microsoft.com/fwlink/?LinkID=135170 |
||||
|
||||
#> |
||||
|
||||
<# |
||||
.Synopsis |
||||
Remove all shell session elements added by the Activate script, including the |
||||
addition of the virtual environment's Python executable from the beginning of |
||||
the PATH variable. |
||||
|
||||
.Parameter NonDestructive |
||||
If present, do not remove this function from the global namespace for the |
||||
session. |
||||
|
||||
#> |
||||
function global:deactivate ([switch]$NonDestructive) { |
||||
# Revert to original values |
||||
|
||||
# The prior prompt: |
||||
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) { |
||||
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt |
||||
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT |
||||
} |
||||
|
||||
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) { |
||||
Remove-Item -Path env:VIRTUAL_ENV_PROMPT |
||||
} |
||||
|
||||
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether: |
||||
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) { |
||||
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force |
||||
} |
||||
|
||||
{% for var, value in envvars.items() %}if (Test-Path -Path Env:_OLD_{{ var }}) { |
||||
Copy-Item -Path Env:_OLD_{{ var }} -Destination Env:{{ var }} |
||||
Remove-Item -Path Env:_OLD_{{ var }} |
||||
} else { |
||||
if (Test-Path -Path Env:{{ var }}) { |
||||
Remove-Item -Path Env:{{ var }} |
||||
} |
||||
} |
||||
{% endfor %} |
||||
# Leave deactivate function in the global namespace if requested: |
||||
if (-not $NonDestructive) { |
||||
Remove-Item -Path function:deactivate |
||||
} |
||||
} |
||||
|
||||
Copy-Item -Path Env:PATH -Destination Env:_OLD_PATH |
||||
|
||||
{% for var, value in envvars.items() %}if (Test-Path -Path Env:{{ var }}) { |
||||
Copy-Item -Path Env:{{ var }} -Destination Env:_OLD_{{ var }} |
||||
} |
||||
$Env:{{ var }} = "{{ value }}" |
||||
{% endfor %} |
||||
|
||||
function global:_OLD_VIRTUAL_PROMPT { "" } |
||||
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT |
||||
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value {{ prompt }} |
||||
|
||||
function global:prompt { |
||||
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) " |
||||
_OLD_VIRTUAL_PROMPT |
||||
} |
||||
$env:VIRTUAL_ENV_PROMPT = "{{ prompt }}" |
||||
@ -0,0 +1,19 @@
|
||||
@echo off |
||||
|
||||
rem This file is UTF-8 encoded, so we need to update the current code page while executing it |
||||
for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do ( |
||||
set _OLD_CODEPAGE=%%a |
||||
) |
||||
if defined _OLD_CODEPAGE ( |
||||
"%SystemRoot%\System32\chcp.com" 65001 > nul |
||||
) |
||||
|
||||
{% for var, value in envvars.items() %}set _OLD_{{ var }}=%PATH% |
||||
set {{ var }}={{ value }} |
||||
{% endfor %} |
||||
set PATH=%VIRTUAL_ENV%\Scripts;%PATH% |
||||
:END |
||||
if defined _OLD_CODEPAGE ( |
||||
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul |
||||
set _OLD_CODEPAGE= |
||||
) |
||||
@ -0,0 +1,32 @@
|
||||
# This file must be used with "source bin/activate" *from bash* |
||||
# you cannot run it directly |
||||
|
||||
deactivate () { |
||||
# reset old environment variables |
||||
{% for var in envvars.keys() %}if [ -n "$_OLD_{{ var }}" ] ; then |
||||
{{ var }}="$_OLD_{{ var }}" |
||||
export {{ var }} |
||||
unset _OLD_{{ var }} |
||||
then |
||||
unset {{ var }} |
||||
fi |
||||
{% endfor %} |
||||
|
||||
if [ -n "${_OLD_VIRTUAL_PS1}" ] ; then |
||||
PS1="${_OLD_VIRTUAL_PS1}" |
||||
export PS1 |
||||
unset _OLD_VIRTUAL_PS1 |
||||
fi |
||||
} |
||||
|
||||
{% for var, value in envvars.items() %}if [ -n "${{ var }}" ] ; then |
||||
_OLD_{{ var }}="${{ var }}" |
||||
export _OLD_{{ var }} |
||||
fi |
||||
{{ var }}="{{ value }}" |
||||
export {{ var }} |
||||
{% endfor %} |
||||
|
||||
_OLD_VIRTUAL_PS1="${PS1:-}" |
||||
PS1="({{ prompt }}) ${PS1:-}" |
||||
export PS1 |
||||
Loading…
Reference in new issue