Created
January 7, 2014 11:29
-
-
Save dansimau/8298049 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
#!/bin/bash | |
# Get last argument as the base filename | |
file=${!#} | |
if [ "$file" == "--version" ]; then | |
python --version | |
exit $? | |
fi | |
venv_path="" | |
# Start at the dir of the file | |
basedir=$(dirname $file) | |
# Loop through each dir, going up one each time | |
while [ "$basedir" != "/" ]; do | |
# Check for venv dirs | |
for dir in .venv venv; do | |
if [ -d "$basedir/$dir" ]; then | |
# Break when we've found one | |
venv_path="$basedir/$dir" | |
break 2 | |
fi | |
done | |
# Go up one level | |
basedir=$(dirname $basedir) | |
done | |
# Detect site-package dirs in venv/lib and add them to path | |
for dir in $venv_path/lib/*/site-packages; do | |
PYTHONPATH=$PYTHONPATH:$dir | |
done | |
# Run python with the venv lib dirs in the path | |
export PYTHONPATH | |
exec python "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment