Skip to content

Commit e2d411c

Browse files
authored
Switch to Using uv in CI (#1514)
* Switch infra to uv * Update Dockerfile for uv * Configure uv with pinned python and shims * Use uv in pre-commit * Move uv download manual setting * Add asv tool for the future
1 parent 0b3850f commit e2d411c

File tree

9 files changed

+31
-164
lines changed

9 files changed

+31
-164
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ RUN mkdir -p ${HOME} && \
2626
useradd --uid ${UID} --gid ${GID} --home ${HOME} vscode && \
2727
chown -R ${UID}:${GID} /home/vscode
2828

29-
# Fix pyenv installation
30-
RUN echo 'eval "$(pyenv init -)"' >>${HOME}/.bashrc && \
31-
chown -R vscode:vscode "${PYENV_ROOT}" && \
32-
chown -R vscode:vscode "${PIPX_HOME}"
29+
# Allow uv to download Python versions manually
30+
ENV UV_PYTHON_DOWNLOADS=manual
3331

3432
# Set user
3533
USER ${UID}:${GID}

.github/containers/Dockerfile

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
FROM ubuntu:20.04
16+
FROM ubuntu:24.04
1717
ARG TARGETPLATFORM
1818

1919
# Install OS packages
@@ -23,33 +23,15 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
2323
bash \
2424
build-essential \
2525
curl \
26-
default-libmysqlclient-dev \
27-
expat \
2826
fish \
2927
fontconfig \
30-
freetds-common \
31-
freetds-dev \
3228
gcc \
3329
git \
34-
libbz2-dev \
35-
libcurl4-openssl-dev \
36-
libffi-dev \
37-
libgmp-dev \
38-
libkrb5-dev \
39-
liblzma-dev \
40-
libmpfr-dev \
41-
libncurses-dev \
42-
libpq-dev \
43-
libreadline-dev \
44-
libsqlite3-dev \
45-
libssl-dev \
4630
locales \
4731
make \
4832
odbc-postgresql \
4933
openssl \
5034
pkg-config \
51-
python3-dev \
52-
python3-pip \
5335
rustc \
5436
sudo \
5537
tzdata \
@@ -58,8 +40,6 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
5840
vim \
5941
wget \
6042
zip \
61-
zlib1g \
62-
zlib1g-dev \
6343
zsh && \
6444
rm -rf /var/lib/apt/lists/*
6545

@@ -103,36 +83,32 @@ RUN ln -fs "/usr/share/zoneinfo/${TZ}" /etc/localtime && \
10383
ENV HOME=/root
10484
WORKDIR "${HOME}"
10585

106-
# Install pyenv
107-
ENV PYENV_ROOT="/usr/local/pyenv"
108-
RUN curl https://pyenv.run/ | /bin/bash
109-
ENV PATH="${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH}"
110-
RUN echo 'eval "$(pyenv init -)"' >>${HOME}/.bashrc && \
111-
pyenv update
86+
# Install and configure uv
87+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
88+
ENV PATH="${HOME}/.local/bin:${PATH}"
89+
ENV UV_PYTHON_PREFERENCE="only-managed"
11290

11391
# Install Python
114-
ARG PYTHON_VERSIONS="3.13 3.12 3.11 3.10 3.9 3.8 pypy3.10-7.3.17"
115-
COPY --chown=0:0 --chmod=755 ./install-python.sh /tmp/install-python.sh
116-
RUN /tmp/install-python.sh && \
117-
rm /tmp/install-python.sh
92+
ARG PYTHON_VERSIONS="3.13 3.12 3.11 3.10 3.9 3.8 pypy3.10"
93+
RUN bash -c "uv python install ${PYTHON_VERSIONS}" && \
94+
uv python pin --global 3.13
11895

119-
# Install dependencies for main python installation
120-
COPY ./requirements.txt /tmp/requirements.txt
121-
RUN pyenv exec pip install --upgrade -r /tmp/requirements.txt && \
122-
rm /tmp/requirements.txt
96+
# Add shims for python and pip
97+
COPY --chmod=775 <<EOF "${HOME}/.local/bin/python"
98+
#!/bin/bash
99+
exec uv run --no-project python \$@
100+
EOF
123101

124-
# Install tools with pipx in isolated environments
125-
COPY ./requirements-tools.txt /tmp/requirements-tools.txt
126-
ENV PIPX_HOME="/opt/pipx"
127-
ENV PIPX_BIN_DIR="${PIPX_HOME}/bin"
128-
ENV PATH="${PIPX_BIN_DIR}:${PATH}"
129-
RUN mkdir -p "${PIPX_BIN_DIR}" && \
130-
while IFS="" read -r line || [ -n "$line" ]; do \
131-
pyenv exec pipx install --global "${line}"; \
132-
done </tmp/requirements-tools.txt && \
133-
rm /tmp/requirements-tools.txt
102+
COPY --chmod=775 <<EOF "${HOME}/.local/bin/pip"
103+
#!/bin/bash
104+
exec uv pip \$@
105+
EOF
134106

135-
# Inject compatibile dependencies for tox
136-
COPY ./requirements-tox.txt /tmp/requirements-tox.txt
137-
RUN pipx inject --force tox -r /tmp/requirements-tox.txt && \
138-
rm /tmp/requirements-tox.txt
107+
# Prevent any runtime downloads
108+
ENV UV_PYTHON_DOWNLOADS=never
109+
110+
# Install tools with uv in isolated environments
111+
RUN uv tool install tox==4.23.2 --with tox-uv && \
112+
uv tool install ruff && \
113+
uv tool install pre-commit --with pre-commit-uv && \
114+
uv tool install asv --with virtualenv

.github/containers/Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
# Override constants
1616
PLATFORM_OVERRIDE:=
17-
PYTHON_VERSIONS_OVERRIDE:=
1817

1918
# Computed variables
2019
IMAGE_NAME:=ghcr.io/newrelic/newrelic-python-agent-ci
@@ -23,8 +22,6 @@ REPO_ROOT:=$(realpath ${MAKEFILE_DIR}../../)
2322
UNAME_P:=$(shell uname -p)
2423
PLATFORM_AUTOMATIC:=$(if $(findstring arm,${UNAME_P}),linux/arm64,linux/amd64)
2524
PLATFORM:=$(if ${PLATFORM_OVERRIDE},${PLATFORM_OVERRIDE},${PLATFORM_AUTOMATIC})
26-
PYTHON_VERSIONS_AUTOMATIC:=3.10
27-
PYTHON_VERSIONS:=$(if ${PYTHON_VERSIONS_OVERRIDE},${PYTHON_VERSIONS_OVERRIDE},${PYTHON_VERSIONS_AUTOMATIC})
2825

2926
.PHONY: default
3027
default: test
@@ -33,8 +30,7 @@ default: test
3330
build:
3431
@docker build ${MAKEFILE_DIR} \
3532
--platform=${PLATFORM} \
36-
-t ${IMAGE_NAME}:local \
37-
--build-arg='PYTHON_VERSIONS=${PYTHON_VERSIONS}'
33+
-t ${IMAGE_NAME}:local
3834

3935
# Run the local tag as a container.
4036
.PHONY: run
@@ -62,12 +58,12 @@ run.%:
6258
-e GITHUB_ACTIONS="true" \
6359
${IMAGE_NAME}:$* /bin/bash
6460

65-
# Ensure python versions are usable. Cannot be automatically used with PYTHON_VERSIONS_OVERRIDE.
61+
# Ensures python versions are usable.
6662
.PHONY: test
6763
test: build
6864
@docker run --rm \
6965
--platform=${PLATFORM} \
70-
ghcr.io/newrelic/python-agent-ci:local \
66+
${IMAGE_NAME}:local \
7167
/bin/bash -c '\
7268
python3.10 --version && \
7369
touch tox.ini && tox --version && \

.github/containers/install-python.sh

Lines changed: 0 additions & 50 deletions
This file was deleted.

.github/containers/requirements-tools.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/containers/requirements-tox.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/containers/requirements.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/scripts/retry.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

tox.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
[tox]
4343
setupdir = {toxinidir}
44+
uv_python_preference = only-managed
4445
; Fail tests when interpreters are missing.
4546
skip_missing_interpreters = false
4647
envlist =
@@ -472,9 +473,6 @@ commands =
472473
allowlist_externals =
473474
{toxinidir}/.github/scripts/*
474475

475-
install_command=
476-
{toxinidir}/.github/scripts/retry.sh 3 pip install {opts} {packages}
477-
478476
extras =
479477
agent_streaming: infinite-tracing
480478

0 commit comments

Comments
 (0)