diff --git a/tools/install_python_dependencies.sh b/tools/install_python_dependencies.sh index 4a0c173751a56f..30cd09ddec4686 100755 --- a/tools/install_python_dependencies.sh +++ b/tools/install_python_dependencies.sh @@ -21,20 +21,21 @@ if [ "$(uname)" == "Darwin" ] && [ $SHELL == "/bin/bash" ]; then RC_FILE="$HOME/.bash_profile" fi -PYENV_INSTALLED = true -if ! command -v "pyenv" > /dev/null 2>&1; then - PYENV_INSTALLED = false +PYENV_INSTALLED="false" +POETRY_INSTALLED="false" +if ! command -v "pyenv" > /dev/null 2>&1; then if ask "Install pyenv?"; then echo "pyenv install ..." curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash PYENV_PATH_SETUP="export PATH=\$HOME/.pyenv/bin:\$HOME/.pyenv/shims:\$PATH" - - PYENV_INSTALLED = true + PYENV_INSTALLED="true" fi +else + PYENV_INSTALLED="true" fi -if $PYENV_INSTALLED && ([ -z "$PYENV_SHELL" ] || [ -n "$PYENV_PATH_SETUP" ]); then +if [[ "$PYENV_INSTALLED" == "true" ]] && ([ -z "$PYENV_SHELL" ] || [ -n "$PYENV_PATH_SETUP" ]); then echo "pyenvrc setup ..." cat < "${HOME}/.pyenvrc" if [ -z "\$PYENV_ROOT" ]; then @@ -60,7 +61,7 @@ fi export MAKEFLAGS="-j$(nproc)" PYENV_PYTHON_VERSION=$(cat $ROOT/.python-version) -if PYENV_INSTALLED && (! pyenv prefix ${PYENV_PYTHON_VERSION} &> /dev/null); then +if [[ "$PYENV_INSTALLED" == "true" ]] && (! pyenv prefix ${PYENV_PYTHON_VERSION} &> /dev/null); then # no pyenv update on mac if [ "$(uname)" == "Linux" ]; then if ask "Update pyenv?"; then @@ -75,7 +76,7 @@ if PYENV_INSTALLED && (! pyenv prefix ${PYENV_PYTHON_VERSION} &> /dev/null); the fi fi -PYENV_INSTALLED && eval "$(pyenv init --path)" +[[ "$PYENV_INSTALLED" == "true" ]] && eval "$(pyenv init --path)" if ask "Update pip?"; then echo "update pip" @@ -90,7 +91,7 @@ if ask "Install poetry?"; then poetry self add poetry-dotenv-plugin@^0.1.0 - POETRY_INSTALLED = true + POETRY_INSTALLED="true" fi echo "PYTHONPATH=${PWD}" > $ROOT/.env @@ -99,14 +100,14 @@ if [[ "$(uname)" == 'Darwin' ]]; then echo "export ZMQ=1" >> $ROOT/.env echo "export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES" >> $ROOT/.env - if [[! POETRY_INSTALLED]]; then + if [[ "$POETRY_INSTALLED" == "false" ]]; then echo "Before running any python files, load the environment variables by running this command:" echo "source ~/.env" fi fi -if POETRY_INSTALLED && PYENV_INSTALLED; then +if [[ "$POETRY_INSTALLED" == "true" ]] && [[ "$PYENV_INSTALLED" == "true" ]]; then if ask "Install openpilot python dependencies?" echo "pip packages install..." poetry install --no-cache --no-root @@ -118,7 +119,7 @@ else echo "pip install ." fi -(! POETRY_INSTALLED || [ -n "$POETRY_VIRTUALENVS_CREATE" ]) && RUN="" || RUN="poetry run" +([[ "$POETRY_INSTALLED" == "false" ]] || [ -n "$POETRY_VIRTUALENVS_CREATE" ]) && RUN="" || RUN="poetry run" if [ "$(uname)" != "Darwin" ] && [ -e "$ROOT/.git" ]; then if ask "Install git pre-commit hooks?"; then @@ -127,3 +128,11 @@ if [ "$(uname)" != "Darwin" ] && [ -e "$ROOT/.git" ]; then $RUN git submodule foreach pre-commit install fi fi + +echo "Setup done." +if [[ "$POETRY_INSTALLED" == "true" ]]; then + echo "Before building, activate the poetry environment with this command:" + echo "poetry shell" +else + echo "Before building, activate your python virtual environment." +fi