Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyenv to uv based python and venv #303

Merged
merged 79 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
b415c16
switch pyenv to uv
coder351 Jul 17, 2024
63b8458
resolve issues
coder351 Jul 18, 2024
c60e49f
remove uv upgrade
coder351 Jul 18, 2024
5e5b8ef
switch to uv
coder351 Jul 22, 2024
d178ab8
remove comment
coder351 Jul 22, 2024
a3de1a2
remove python version
coder351 Jul 22, 2024
f7e55c0
remove python3.12-dev
coder351 Jul 22, 2024
56067dd
remove empty line
coder351 Jul 22, 2024
fd5f9db
use python3.pc
coder351 Jul 22, 2024
2232fe4
test github workflow
coder351 Jul 22, 2024
1bd9278
switch to pyqt-5 + use uv python for pkgconfig
coder351 Jul 24, 2024
7bafbe4
remove references to pyenv
coder351 Jul 24, 2024
8bd41f1
remove references to pyenv
coder351 Jul 24, 2024
db09a10
add python2
coder351 Jul 24, 2024
58ad598
merge master
coder351 Jul 26, 2024
d434034
merge master
coder351 Jul 29, 2024
04d7a05
[upload]
coder351 Jul 31, 2024
4ec3a41
resolve docker warnings
coder351 Jul 31, 2024
c5f49df
[upload]
coder351 Jul 31, 2024
6571d23
setup uv to use /usr/local
coder351 Jul 31, 2024
d91713b
use uv to install pyqt5
coder351 Jul 31, 2024
8a36dae
use uv to install pip
coder351 Aug 1, 2024
5b4a0c9
use --seed to setup pip
coder351 Aug 1, 2024
f609d15
test build using --no-deps
coder351 Aug 1, 2024
920962a
test build pyqt5 using pyproject.toml
coder351 Aug 1, 2024
5b80d73
revert pyqt5 from pyproject.toml
coder351 Aug 1, 2024
ed2e2f1
[upload]
coder351 Aug 1, 2024
85ef729
use PyQt5 wheel
coder351 Aug 3, 2024
87dd173
revert duplicate openpilot_dependencies.sh installed in agnos-base
coder351 Aug 3, 2024
71f46b5
add sudo
coder351 Aug 3, 2024
7763a31
revert dev deps purge
coder351 Aug 3, 2024
f40e27d
remove openpilot_dependencies.sh from agnos-base
coder351 Aug 3, 2024
6b22035
add -y to apt-get
coder351 Aug 3, 2024
8cdd398
add pyproject opencl dep
coder351 Aug 3, 2024
753f242
add gcc-arm-none-eabi dep
coder351 Aug 3, 2024
11ed4cb
test removing dev dependencies
coder351 Aug 3, 2024
f75ba91
test removing dev dependencies
coder351 Aug 3, 2024
ff5ae89
test purge using noninteractive
coder351 Aug 3, 2024
10ea20a
test autoremove dependencies
coder351 Aug 3, 2024
10e8f81
revert autoremove
coder351 Aug 3, 2024
d7db0cf
add pip to handle pip install
coder351 Aug 3, 2024
3fbda24
add new line
coder351 Aug 5, 2024
2e1f21d
rebuild
coder351 Aug 5, 2024
1837383
use uv python 3.12.3
coder351 Aug 10, 2024
af505ef
test github runner
coder351 Aug 10, 2024
e0d1b14
revert github runner
coder351 Aug 10, 2024
a4480ca
rebuild
coder351 Aug 10, 2024
08b886f
Merge branch 'master' into pyenvtouv
coder351 Aug 10, 2024
9e313ba
set pc path to python 3.12
coder351 Aug 10, 2024
ee5679b
merge master
coder351 Aug 15, 2024
d453fe0
rebuild pyqt5 in Docker
coder351 Aug 15, 2024
537630b
test rebuild pyqt5
coder351 Aug 15, 2024
9c46cf7
rebuild pyqt5
coder351 Aug 15, 2024
2efdb90
rebuild pyqt5
coder351 Aug 15, 2024
2b8a3f2
test build pyqt5 wheel
coder351 Aug 15, 2024
1aed813
resolve venv
coder351 Aug 15, 2024
d99c3fd
test rebuild pyqt5 wheel
coder351 Aug 15, 2024
1b133a7
resolve build error
coder351 Aug 15, 2024
ece511e
use pip to build wheel
coder351 Aug 15, 2024
e47a5e5
use prebuilt pyqt5 wheel
coder351 Aug 16, 2024
41e6dd6
merge master
coder351 Aug 20, 2024
69f9cd1
move dbus-python deps
coder351 Aug 20, 2024
d61f3cd
resolve PR comments
coder351 Aug 21, 2024
3af0750
test remove dbus-python deps
coder351 Aug 21, 2024
e7328c1
remove dbus-python deps
coder351 Aug 21, 2024
406e943
remove pyqt5 pre-built wheel
coder351 Aug 28, 2024
23f97a8
test uv python venv
coder351 Aug 28, 2024
53e3723
add quotes
coder351 Aug 28, 2024
02386fc
add shims
coder351 Aug 28, 2024
0ae90b9
rebuild
coder351 Aug 28, 2024
6a9c466
remove XDG_DATA_HOME
coder351 Aug 29, 2024
b6d1fd0
rebuild
coder351 Aug 29, 2024
62aa5a6
add uv shim
coder351 Sep 1, 2024
6468a9b
Merge branch 'commaai:master' into pyenvtouv
coder351 Sep 1, 2024
db232fd
chmod +x uv
coder351 Sep 1, 2024
fcc6da6
set UV_NO_CACHE=1
coder351 Sep 1, 2024
b0b5f1e
remove trailing whitespace
coder351 Sep 1, 2024
b3ee073
resolve uv device issues
coder351 Sep 2, 2024
9905cbf
rebuild
coder351 Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions Dockerfile.agnos
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,31 @@ RUN cd /tmp && apt-get -o Dpkg::Options::="--force-overwrite" install -yq ./capn
COPY --from=agnos-compiler-ffmpeg /tmp/ffmpeg.deb /tmp/ffmpeg.deb
RUN cd /tmp && apt-get -o Dpkg::Options::="--force-overwrite" install -yq ./ffmpeg.deb

ARG XDG_DATA_HOME="/usr/local"
ARG PATH="$XDG_DATA_HOME/.cargo/bin:$PATH"

# Use pre-compiled PyQt5 wheel
COPY --from=agnos-compiler-pyqt5 /tmp/PyQt5-5.15.9/PyQt5-5.15.9-cp38-abi3-manylinux_2_17_aarch64.whl /tmp/PyQt5-5.15.9-cp38-abi3-manylinux_2_17_aarch64.whl

RUN export PATH="/usr/local/pyenv/bin:/usr/local/pyenv/shims:$PATH" && \
export PYENV_ROOT="/usr/local/pyenv" && \
eval "$(pyenv init -)" && \
eval "$(pyenv virtualenv-init -)" && \
export MAKEFLAGS="-j$(nproc)" && \
pip install pyqt5-sip==12.12.1 && \
pip install /tmp/PyQt5-5.15.9-cp38-abi3-manylinux_2_17_aarch64.whl --verbose --config-settings --confirm-license= && \
pyenv rehash
RUN export MAKEFLAGS="-j$(nproc)" && \
source $XDG_DATA_HOME/venv/bin/activate && \
uv pip install pyqt5-sip==12.12.1 && \
uv pip install /tmp/PyQt5-5.15.9-cp38-abi3-manylinux_2_17_aarch64.whl --verbose --config-settings="--confirm-license="

# Install openpilot python packages
RUN mkdir -p /tmp/agnos/uv
COPY ./userspace/pyproject.toml ./userspace/uv.lock /tmp/agnos/uv
RUN export PATH="/usr/local/pyenv/bin:/usr/local/pyenv/shims:$PATH" && \
export PYENV_ROOT="/usr/local/pyenv" && \
eval "$(pyenv init -)" && \
eval "$(pyenv virtualenv-init -)" && \
RUN source $XDG_DATA_HOME/venv/bin/activate && \
cd /tmp/agnos/uv && \
export PYOPENCL_CL_PRETEND_VERSION="2.0" && \
MAKEFLAGS="-j$(nproc)" UV_NO_CACHE=1 uv pip install --no-cache-dir --system . && \
pyenv rehash
pc="$(python -c "import sysconfig;print(sysconfig.get_config_vars('installed_base')[0])")" && \
pcpath=$pc"/lib/pkgconfig" && \
export PKG_CONFIG_PATH="$pcpath:$PKG_CONFIG_PATH" && \
pypcpath=$pcpath"/python-3.12.pc" && \
sed -i 's|prefix=/install|prefix='$pc'|' $pypcpath && \
pypcpathembed=$pcpath"/python-3.12-embed.pc" && \
sed -i 's|prefix=/install|prefix='$pc'|' $pypcpathembed && \
MAKEFLAGS="-j$(nproc)" UV_NO_CACHE=1 uv pip install --no-cache-dir .

# Install nice to haves
COPY ./userspace/install_extras.sh /tmp/agnos/
Expand Down
6 changes: 1 addition & 5 deletions userspace/compile-pyqt5.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash -e

# Use pyenv venv
export PATH="/usr/local/pyenv/bin:/usr/local/pyenv/shims:$PATH"
export PYENV_ROOT="/usr/local/pyenv"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
source /usr/local/venv/bin/activate

# Build PyQt5 wheel
cd /tmp
Expand Down
2 changes: 1 addition & 1 deletion userspace/files/brightnessd.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=Limit display brightness with uptime

[Service]
Restart=on-failure
ExecStart=/usr/local/pyenv/shims/python -u /usr/comma/brightnessd.py
ExecStart=/usr/local/venv/bin/python -u /usr/comma/brightnessd.py

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion userspace/files/phantom_touch_logger.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ After=multi-user.target
[Service]
User=comma
Restart=no
ExecStart=/usr/local/pyenv/shims/python -u /usr/comma/phantom_touch_logger.py
ExecStart=/usr/local/venv/bin/python -u /usr/comma/phantom_touch_logger.py

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion userspace/files/power_drop_monitor.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ After=multi-user.target

[Service]
Restart=always
ExecStart=/usr/local/pyenv/shims/python -u /usr/comma/power_drop_monitor.py
ExecStart=/usr/local/venv/bin/python -u /usr/comma/power_drop_monitor.py

[Install]
WantedBy=multi-user.target
27 changes: 5 additions & 22 deletions userspace/files/profile
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,16 @@ export QT_QPA_PLATFORM="wayland-egl"

# python setup
export PYTHONPATH="/data/pythonpath"
export PATH="/usr/local/pyenv/bin:$PATH"
export PYENV_VERSION="3.11.4"
export PYENV_ROOT="/usr/local/pyenv"

# output of "pyenv init - --no-rehash"
export PATH="/usr/local/pyenv/shims:${PATH}"
export PYENV_SHELL=bash
source '/usr/local/pyenv/libexec/../completions/pyenv.bash'
pyenv() {
local command
command="${1:-}"
if [ "$#" -gt 0 ]; then
shift
fi

case "$command" in
activate|deactivate|rehash|shell)
eval "$(pyenv "sh-$command" "$@")";;
*)
command pyenv "$command" "$@";;
esac
}
export PATH="/usr/local/.cargo/bin:$PATH"
export UV_PYTHON_INSTALL_DIR="/usr/local/uv/python"
export UV_PYTHON_PREFERENCE=only-managed
export UV_LINK_MODE=copy
source /usr/local/venv/bin/activate

# custom shims
coder351 marked this conversation as resolved.
Show resolved Hide resolved
export PATH="/usr/comma/shims:${PATH}"


# nice AT command helper
atc() {
mmcli -m any --command="${@}"
Expand Down
23 changes: 8 additions & 15 deletions userspace/openpilot_python_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
#!/bin/bash -e

echo "Installing python for openpilot"
echo "installing uv..."

# Install pyenv
export PYENV_ROOT="/usr/local/pyenv"
curl https://pyenv.run | bash
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
export XDG_DATA_HOME="/usr/local"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for? I suspect this has implications for other things

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adeebshihadeh The XDG_DATA_HOME only sets the uv venv location (usr/local) otherwise the default location would fall to current directory (.venv).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it doesn't affect anything except providing the installation part for the venv. But we should avoid usage it /etc/profile as this will make it Into the envvars and might have some influence.

export CARGO_HOME="$XDG_DATA_HOME/.cargo"

PYTHON_VERSION="3.11.4"
if [ "$(uname -p)" == "aarch64" ]; then
pyenv install --verbose $PYTHON_VERSION
else
MAKEFLAGS="-j1" MAKE_OPTS="-j1" taskset --cpu-list 0 pyenv install --verbose $PYTHON_VERSION
fi
curl -LsSf https://astral.sh/uv/install.sh | sh
eval ". $CARGO_HOME/env"

echo "Setting global python version"
pyenv global $PYTHON_VERSION
PYTHON_VERSION="3.12.3"

pip3 install --no-cache-dir --upgrade pip uv
# uv requires virtual env either managed or system before installing dependencies
uv venv $XDG_DATA_HOME/venv --seed --python-preference only-managed --python=$PYTHON_VERSION
4 changes: 2 additions & 2 deletions userspace/usr/comma/shims/pip
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/bash

PIP_PATH=/usr/local/pyenv/shims/pip
PIP_PATH=/usr/local/venv/bin/pip
export TMPDIR=/tmp/pip-tmp

# setup large tmp for install
Expand All @@ -14,5 +14,5 @@ sudo TMPDIR=$TMPDIR PIP_NO_CACHE_DIR=1 $PIP_PATH "$@"

# cleanup
sudo mount -o ro,remount /
rm -rf $TMPDIR
sudo rm -rf $TMPDIR
sudo mount -o remount /tmp
18 changes: 18 additions & 0 deletions userspace/usr/comma/shims/uv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/bash

UV_PATH=/usr/local/.cargo/bin/uv
export TMPDIR=/tmp/uv-tmp

# setup large tmp for install
mkdir -p $TMPDIR
sudo mount -o remount,size=2G /tmp
sudo mount -o rw,remount /
sudo resize2fs $(findmnt -n -o SOURCE /) &>/dev/null || sudo resize2fs $(findmnt -n -o SOURCE /)

# run command
sudo -E TMPDIR=$TMPDIR UV_NO_CACHE=1 $UV_PATH "$@"

# cleanup
sudo mount -o ro,remount /
sudo rm -rf $TMPDIR
sudo mount -o remount /tmp
2 changes: 1 addition & 1 deletion userspace/usr/comma/sound/sound_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ echo "sound card online"
/usr/comma/sound/tinymix set "TERT_MI2S_TX Channels" Two

# setup the amplifier registers
/usr/local/pyenv/shims/python /usr/comma/sound/amplifier.py
/usr/local/venv/bin/python /usr/comma/sound/amplifier.py