Add update-python-env script
This commit is contained in:
parent
3794855291
commit
cd222daa98
49
update-python-env.sh
Executable file
49
update-python-env.sh
Executable file
@ -0,0 +1,49 @@
|
||||
if [ -z $1 ]; then
|
||||
echo "Usage: $0 <python version> [ENV_NAME [dev]]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f .python-version ]; then
|
||||
echo "Not a python project: `pwd`"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PY_VER=$1
|
||||
PROJECT=$2
|
||||
if [[ $PROJECT == "" ]]; then
|
||||
PROJECT=$(basename $PWD)
|
||||
fi
|
||||
DO_DEV=$3
|
||||
|
||||
echo "[*] Checking if required python version $PY_VER is installed"
|
||||
pyenv versions | grep $PY_VER > /dev/null
|
||||
res=$?
|
||||
if [ $res -eq 1 ]; then
|
||||
echo "Python $PY_VER is not installed. Run \"pyenv install $PY_VER\""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CUR_VENV=$(cat .python-version)
|
||||
echo "[*] Removing current virtualenv ($CUR_VENV)"
|
||||
pyenv virtualenv-delete -f $CUR_VENV
|
||||
|
||||
echo "[*] Removing virtualenv named as project ($PROJECT)"
|
||||
pyenv virtualenv-delete -f $PROJECT
|
||||
|
||||
NEW_VENV=$PY_VER/envs/$PROJECT
|
||||
echo "[*] Creating new virtualenv ($NEW_VENV)"
|
||||
pyenv virtualenv $PY_VER $PROJECT
|
||||
echo $NEW_VENV > .python-version
|
||||
|
||||
echo "[*] Updating pip, setuptools and wheel"
|
||||
pip install -U pip setuptools wheel
|
||||
|
||||
if [ -f requirements.txt ]; then
|
||||
echo "[*] Installing packets from requirements.txt"
|
||||
pip install -Ur requirements.txt
|
||||
fi
|
||||
|
||||
if [ -f requirements-dev.txt ] && [ "$DO_DEV" = "dev" ]; then
|
||||
echo "[*] Installing packets from requirements-dev.txt"
|
||||
pip install -Ur requirements-dev.txt
|
||||
fi
|
||||
Loading…
Reference in New Issue
Block a user