From de75372880cb354df2bcb2e0f36e769213bf7072 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Wed, 19 Jun 2024 09:55:23 -0700 Subject: [PATCH] Remove pyenv (#32786) * no pyenv * better * check poetry * docker * syntax * manual env * pre-commit * revert * format --- Dockerfile.openpilot_base | 16 ++++---- tools/install_python_dependencies.sh | 60 ++++------------------------ tools/install_ubuntu_dependencies.sh | 2 +- 3 files changed, 16 insertions(+), 62 deletions(-) diff --git a/Dockerfile.openpilot_base b/Dockerfile.openpilot_base index 7228d16ef9..343fd29c82 100644 --- a/Dockerfile.openpilot_base +++ b/Dockerfile.openpilot_base @@ -68,20 +68,18 @@ RUN usermod -aG sudo $USER RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers USER $USER -ENV POETRY_VIRTUALENVS_CREATE=false -ENV PYENV_VERSION=3.12.4 -ENV PYENV_ROOT="/home/$USER/pyenv" -ENV PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH" - COPY --chown=$USER pyproject.toml poetry.lock /tmp/ COPY --chown=$USER tools/install_python_dependencies.sh /tmp/tools/ -RUN cd /tmp && \ +ENV POETRY_VIRTUALENVS_CREATE=false +ENV VIRTUAL_ENV=/home/$USER/venv/.venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" +RUN . $VIRTUAL_ENV/bin/activate && \ + cd /tmp && \ tools/install_python_dependencies.sh && \ rm -rf /tmp/* && \ - rm -rf /home/$USER/.cache && \ - find /home/$USER/pyenv -type d -name ".git" | xargs rm -rf && \ - rm -rf /home/$USER/pyenv/versions/3.12.4/lib/python3.12/test + rm -rf /home/$USER/.cache USER root RUN sudo git config --global --add safe.directory /tmp/openpilot diff --git a/tools/install_python_dependencies.sh b/tools/install_python_dependencies.sh index bb00302073..086fc2d14f 100755 --- a/tools/install_python_dependencies.sh +++ b/tools/install_python_dependencies.sh @@ -13,58 +13,15 @@ if [ "$(uname)" == "Darwin" ] && [ $SHELL == "/bin/bash" ]; then RC_FILE="$HOME/.bash_profile" fi -if ! command -v "pyenv" > /dev/null 2>&1; 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:\$HOME/.pyenv/versions/${PYENV_PYTHON_VERSION}/bin:\$PATH" +if ! command -v "poetry" > /dev/null 2>&1; then + echo "installing poetry..." + curl -sSL https://install.python-poetry.org | python3 - + POETRY_BIN='$HOME/.local/bin' + ADD_PATH_CMD="export PATH=\"$POETRY_BIN:\$PATH\"" + eval $ADD_PATH_CMD + printf "\n#poetry path\n$ADD_PATH_CMD\n" >> $RC_FILE fi -if [ -z "$PYENV_SHELL" ] || [ -n "$PYENV_PATH_SETUP" ]; then - echo "pyenvrc setup ..." - cat < "${HOME}/.pyenvrc" -if [ -z "\$PYENV_ROOT" ]; then - $PYENV_PATH_SETUP - export PYENV_ROOT="\$HOME/.pyenv" - eval "\$(pyenv init -)" - eval "\$(pyenv virtualenv-init -)" -fi -EOF - - SOURCE_PYENVRC="source ~/.pyenvrc" - if ! grep "^$SOURCE_PYENVRC$" $RC_FILE > /dev/null; then - printf "\n$SOURCE_PYENVRC\n" >> $RC_FILE - fi - - eval "$SOURCE_PYENVRC" - # $(pyenv init -) produces a function which is broken on bash 3.2 which ships on macOS - if [ $(uname) == "Darwin" ]; then - unset -f pyenv - fi -fi - -export MAKEFLAGS="-j$(nproc)" - -PYENV_PYTHON_VERSION="3.12.4" -if ! pyenv prefix ${PYENV_PYTHON_VERSION} &> /dev/null; then - # no pyenv update on mac - if [ "$(uname)" == "Linux" ]; then - echo "pyenv update ..." - pyenv update - fi - echo "python ${PYENV_PYTHON_VERSION} install ..." - CONFIGURE_OPTS="--enable-shared" pyenv install -f ${PYENV_PYTHON_VERSION} -fi - -eval "$(pyenv init --path)" -eval "$(pyenv init -)" -eval "$(pyenv virtualenv-init -)" -pyenv local ${PYENV_PYTHON_VERSION} -pyenv rehash - -echo "update pip" -pip install pip==24.0 -pip install poetry==1.7.0 - poetry config virtualenvs.prefer-active-python true --local poetry config virtualenvs.in-project true --local @@ -77,9 +34,8 @@ fi poetry self add poetry-dotenv-plugin@^0.1.0 -echo "pip packages install..." +echo "installing python packages..." poetry install --no-cache --no-root -pyenv rehash [ -n "$POETRY_VIRTUALENVS_CREATE" ] && RUN="" || RUN="poetry run" diff --git a/tools/install_ubuntu_dependencies.sh b/tools/install_ubuntu_dependencies.sh index 1fc5e4fc8b..5c10bf5438 100755 --- a/tools/install_ubuntu_dependencies.sh +++ b/tools/install_ubuntu_dependencies.sh @@ -94,7 +94,7 @@ function install_ubuntu_lts_latest_requirements() { qt5-qmake \ qtbase5-dev-tools \ python3-dev \ - tk-dev + python3-venv } # Install Ubuntu 20.04 packages