Last active
December 25, 2019 13:22
-
-
Save bohanyang/59e7df320b23cc7520672d042907eaba to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env sh | |
set -e | |
generate_entry_script() { | |
TARGET_BIN="$1" | |
ENTRY_SCRIPT="$ENV_DIR/$TARGET_BIN" | |
printf "#!/usr/bin/env sh\nexec \"%s/bin/%s\" \"%s/bin/%s\" \"\$@\"\n" "$ENV_DIR" "$PYTHON_BIN" "$ENV_DIR" "$TARGET_BIN" > "$ENTRY_SCRIPT" | |
chmod +x "$ENTRY_SCRIPT" | |
echo "ln -s \"$ENTRY_SCRIPT\"" | |
} | |
ENV_DIR="$HOME/.pybin/$1" | |
PYTHON_BIN=${2:-"python3"} | |
if [ -n "$3" ]; then | |
generate_entry_script "$3" | |
else | |
rm -rf "$ENV_DIR" | |
virtualenv -p "$PYTHON_BIN" "$ENV_DIR" | |
echo "source $ENV_DIR/bin/activate" | |
generate_entry_script "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment