forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support deactivating virtual environments without user intervention (#…
- Loading branch information
Kartik Raj
authored
Nov 10, 2023
1 parent
8d174a8
commit b68ddee
Showing
21 changed files
with
359 additions
and
680 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Same as deactivate in "<venv>/bin/activate" | ||
deactivate () { | ||
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then | ||
PATH="${_OLD_VIRTUAL_PATH:-}" | ||
export PATH | ||
unset _OLD_VIRTUAL_PATH | ||
fi | ||
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then | ||
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" | ||
export PYTHONHOME | ||
unset _OLD_VIRTUAL_PYTHONHOME | ||
fi | ||
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then | ||
hash -r 2> /dev/null | ||
fi | ||
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then | ||
PS1="${_OLD_VIRTUAL_PS1:-}" | ||
export PS1 | ||
unset _OLD_VIRTUAL_PS1 | ||
fi | ||
unset VIRTUAL_ENV | ||
unset VIRTUAL_ENV_PROMPT | ||
if [ ! "${1:-}" = "nondestructive" ] ; then | ||
unset -f deactivate | ||
fi | ||
} | ||
|
||
# Get the directory of the current script | ||
SCRIPT_DIR=$(dirname "$0") | ||
# Construct the path to envVars.txt relative to the script directory | ||
ENV_FILE="$SCRIPT_DIR/envVars.txt" | ||
|
||
# Read the JSON file and set the variables | ||
TEMP_PS1=$(grep '^PS1=' $ENV_FILE | cut -d '=' -f 2) | ||
TEMP_PATH=$(grep '^PATH=' $ENV_FILE | cut -d '=' -f 2) | ||
TEMP_PYTHONHOME=$(grep '^PYTHONHOME=' $ENV_FILE | cut -d '=' -f 2) | ||
# Initialize the variables required by deactivate function | ||
_OLD_VIRTUAL_PS1="${TEMP_PS1:-}" | ||
_OLD_VIRTUAL_PATH="$TEMP_PATH" | ||
if [ -n "${PYTHONHOME:-}" ] ; then | ||
_OLD_VIRTUAL_PYTHONHOME="${TEMP_PYTHONHOME:-}" | ||
fi | ||
deactivate | ||
bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Same as deactivate in "<venv>/bin/activate" | ||
deactivate () { | ||
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then | ||
PATH="${_OLD_VIRTUAL_PATH:-}" | ||
export PATH | ||
unset _OLD_VIRTUAL_PATH | ||
fi | ||
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then | ||
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" | ||
export PYTHONHOME | ||
unset _OLD_VIRTUAL_PYTHONHOME | ||
fi | ||
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then | ||
hash -r 2> /dev/null | ||
fi | ||
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then | ||
PS1="${_OLD_VIRTUAL_PS1:-}" | ||
export PS1 | ||
unset _OLD_VIRTUAL_PS1 | ||
fi | ||
unset VIRTUAL_ENV | ||
unset VIRTUAL_ENV_PROMPT | ||
if [ ! "${1:-}" = "nondestructive" ] ; then | ||
unset -f deactivate | ||
fi | ||
} | ||
|
||
# Get the directory of the current script | ||
SCRIPT_DIR=$(dirname "$0") | ||
# Construct the path to envVars.txt relative to the script directory | ||
ENV_FILE="$SCRIPT_DIR/envVars.txt" | ||
|
||
# Read the JSON file and set the variables | ||
TEMP_PS1=$(grep '^PS1=' $ENV_FILE | cut -d '=' -f 2) | ||
TEMP_PATH=$(grep '^PATH=' $ENV_FILE | cut -d '=' -f 2) | ||
TEMP_PYTHONHOME=$(grep '^PYTHONHOME=' $ENV_FILE | cut -d '=' -f 2) | ||
# Initialize the variables required by deactivate function | ||
_OLD_VIRTUAL_PS1="${TEMP_PS1:-}" | ||
_OLD_VIRTUAL_PATH="$TEMP_PATH" | ||
if [ -n "${PYTHONHOME:-}" ] ; then | ||
_OLD_VIRTUAL_PYTHONHOME="${TEMP_PYTHONHOME:-}" | ||
fi | ||
deactivate | ||
fish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Load dotenv-style file and restore environment variables | ||
Get-Content -Path "$PSScriptRoot\envVars.txt" | ForEach-Object { | ||
# Split each line into key and value at the first '=' | ||
$parts = $_ -split '=', 2 | ||
if ($parts.Count -eq 2) { | ||
$key = $parts[0].Trim() | ||
$value = $parts[1].Trim() | ||
# Set the environment variable | ||
Set-Item -Path "env:$key" -Value $value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.