Skip to content

Commit de75372

Browse files
Remove pyenv (commaai#32786)
* no pyenv * better * check poetry * docker * syntax * manual env * pre-commit * revert * format
1 parent 151b453 commit de75372

3 files changed

+16
-62
lines changed

Dockerfile.openpilot_base

+7-9
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,18 @@ RUN usermod -aG sudo $USER
6868
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
6969
USER $USER
7070

71-
ENV POETRY_VIRTUALENVS_CREATE=false
72-
ENV PYENV_VERSION=3.12.4
73-
ENV PYENV_ROOT="/home/$USER/pyenv"
74-
ENV PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
75-
7671
COPY --chown=$USER pyproject.toml poetry.lock /tmp/
7772
COPY --chown=$USER tools/install_python_dependencies.sh /tmp/tools/
7873

79-
RUN cd /tmp && \
74+
ENV POETRY_VIRTUALENVS_CREATE=false
75+
ENV VIRTUAL_ENV=/home/$USER/venv/.venv
76+
RUN python3 -m venv $VIRTUAL_ENV
77+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
78+
RUN . $VIRTUAL_ENV/bin/activate && \
79+
cd /tmp && \
8080
tools/install_python_dependencies.sh && \
8181
rm -rf /tmp/* && \
82-
rm -rf /home/$USER/.cache && \
83-
find /home/$USER/pyenv -type d -name ".git" | xargs rm -rf && \
84-
rm -rf /home/$USER/pyenv/versions/3.12.4/lib/python3.12/test
82+
rm -rf /home/$USER/.cache
8583

8684
USER root
8785
RUN sudo git config --global --add safe.directory /tmp/openpilot

tools/install_python_dependencies.sh

+8-52
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,15 @@ if [ "$(uname)" == "Darwin" ] && [ $SHELL == "/bin/bash" ]; then
1313
RC_FILE="$HOME/.bash_profile"
1414
fi
1515

16-
if ! command -v "pyenv" > /dev/null 2>&1; then
17-
echo "pyenv install ..."
18-
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
19-
PYENV_PATH_SETUP="export PATH=\$HOME/.pyenv/bin:\$HOME/.pyenv/shims:\$HOME/.pyenv/versions/${PYENV_PYTHON_VERSION}/bin:\$PATH"
16+
if ! command -v "poetry" > /dev/null 2>&1; then
17+
echo "installing poetry..."
18+
curl -sSL https://install.python-poetry.org | python3 -
19+
POETRY_BIN='$HOME/.local/bin'
20+
ADD_PATH_CMD="export PATH=\"$POETRY_BIN:\$PATH\""
21+
eval $ADD_PATH_CMD
22+
printf "\n#poetry path\n$ADD_PATH_CMD\n" >> $RC_FILE
2023
fi
2124

22-
if [ -z "$PYENV_SHELL" ] || [ -n "$PYENV_PATH_SETUP" ]; then
23-
echo "pyenvrc setup ..."
24-
cat <<EOF > "${HOME}/.pyenvrc"
25-
if [ -z "\$PYENV_ROOT" ]; then
26-
$PYENV_PATH_SETUP
27-
export PYENV_ROOT="\$HOME/.pyenv"
28-
eval "\$(pyenv init -)"
29-
eval "\$(pyenv virtualenv-init -)"
30-
fi
31-
EOF
32-
33-
SOURCE_PYENVRC="source ~/.pyenvrc"
34-
if ! grep "^$SOURCE_PYENVRC$" $RC_FILE > /dev/null; then
35-
printf "\n$SOURCE_PYENVRC\n" >> $RC_FILE
36-
fi
37-
38-
eval "$SOURCE_PYENVRC"
39-
# $(pyenv init -) produces a function which is broken on bash 3.2 which ships on macOS
40-
if [ $(uname) == "Darwin" ]; then
41-
unset -f pyenv
42-
fi
43-
fi
44-
45-
export MAKEFLAGS="-j$(nproc)"
46-
47-
PYENV_PYTHON_VERSION="3.12.4"
48-
if ! pyenv prefix ${PYENV_PYTHON_VERSION} &> /dev/null; then
49-
# no pyenv update on mac
50-
if [ "$(uname)" == "Linux" ]; then
51-
echo "pyenv update ..."
52-
pyenv update
53-
fi
54-
echo "python ${PYENV_PYTHON_VERSION} install ..."
55-
CONFIGURE_OPTS="--enable-shared" pyenv install -f ${PYENV_PYTHON_VERSION}
56-
fi
57-
58-
eval "$(pyenv init --path)"
59-
eval "$(pyenv init -)"
60-
eval "$(pyenv virtualenv-init -)"
61-
pyenv local ${PYENV_PYTHON_VERSION}
62-
pyenv rehash
63-
64-
echo "update pip"
65-
pip install pip==24.0
66-
pip install poetry==1.7.0
67-
6825
poetry config virtualenvs.prefer-active-python true --local
6926
poetry config virtualenvs.in-project true --local
7027

@@ -77,9 +34,8 @@ fi
7734

7835
poetry self add poetry-dotenv-plugin@^0.1.0
7936

80-
echo "pip packages install..."
37+
echo "installing python packages..."
8138
poetry install --no-cache --no-root
82-
pyenv rehash
8339

8440
[ -n "$POETRY_VIRTUALENVS_CREATE" ] && RUN="" || RUN="poetry run"
8541

tools/install_ubuntu_dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function install_ubuntu_lts_latest_requirements() {
9494
qt5-qmake \
9595
qtbase5-dev-tools \
9696
python3-dev \
97-
tk-dev
97+
python3-venv
9898
}
9999

100100
# Install Ubuntu 20.04 packages

0 commit comments

Comments
 (0)