Skip to content

Commit 75f3cd1

Browse files
authored
Merge pull request #812 from rackerlabs/switch-to-uv
chore: switch from poetry to uv
2 parents 6f3daf6 + 3ddd079 commit 75f3cd1

File tree

22 files changed

+7221
-10334
lines changed

22 files changed

+7221
-10334
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./python/understack-tests/.venv/
1+
.venv

.github/workflows/code-test.yaml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ jobs:
2525
outputs:
2626
projects: ${{ steps.set-projects.outputs.projects }}
2727
steps:
28-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
29-
- name: Find all Python projects with pyproject.toml
28+
- uses: actions/checkout@v4
29+
- name: Find all projects with pyproject.toml
3030
id: set-projects
3131
run: |
3232
# grabs all paths with pyproject.toml, snips the 2nd dir, grabs only unique ones, makes a JSON list
3333
projects=$(find python -mindepth 2 ! -wholename 'python/understack-tests/*' -name pyproject.toml | awk -F/ '{print $2}' | sort -u | jq -R -s -c 'split("\n")[:-1]')
3434
echo "projects=$projects" >> "$GITHUB_OUTPUT"
35-
python:
35+
36+
uv:
3637
needs: [discover]
3738
runs-on: ubuntu-latest
3839

@@ -46,22 +47,22 @@ jobs:
4647

4748
steps:
4849
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
49-
- run: pipx install poetry==1.7.1 && poetry self add 'poetry-dynamic-versioning[plugin]'
50-
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
50+
- uses: astral-sh/setup-uv@v5
51+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
5152
with:
5253
python-version-file: python/${{ matrix.project }}/pyproject.toml
53-
cache: "poetry"
54-
- run: poetry install --sync --with test
55-
- run: poetry build
56-
- run: "poetry run pytest --cov --cov-report xml:coverage.xml"
57-
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
54+
- run: uv sync
55+
- run: uv build --wheel
56+
- run: "uv run pytest --cov --cov-report xml:coverage.xml"
57+
- uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
5858
with:
5959
name: coverage-${{ matrix.project }}
6060
path: python/${{ matrix.project }}/coverage.xml
6161
retention-days: 1
6262

63+
6364
coverage-upload:
64-
needs: python
65+
needs: [uv]
6566
runs-on: ubuntu-latest
6667
steps:
6768
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4

.pre-commit-config.yaml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,25 @@ repos:
5959
- ansible
6060
- jmespath
6161
files: '^ansible/.*'
62-
- repo: https://github.com/python-poetry/poetry
63-
rev: '2.1.3'
62+
- repo: https://github.com/astral-sh/uv-pre-commit
63+
# uv version.
64+
rev: 0.7.13
6465
hooks:
65-
- id: poetry-check
66-
language_version: "3.11"
67-
name: "poetry-check (understack-workflows)"
68-
files: '^python/understack-workflows/'
69-
args: ["-C", "python/understack-workflows"]
70-
- id: poetry-lock
71-
language_version: "3.11"
72-
name: "poetry-lock (understack-workflows)"
73-
files: '^python/understack-workflows/'
74-
args: ["-C", "python/understack-workflows"]
66+
- id: uv-lock
67+
name: diff-nautobot-understack
68+
args: ["-D", "python/diff-nautobot-understack"]
69+
- id: uv-lock
70+
name: ironic-understack
71+
args: ["-D", "python/ironic-understack"]
72+
- id: uv-lock
73+
name: neutron-understack
74+
args: ["-D", "python/neutron-understack"]
75+
- id: uv-lock
76+
name: understack-flavor-matcher
77+
args: ["-D", "python/understack-flavor-matcher"]
78+
- id: uv-lock
79+
name: understack-workflows
80+
args: ["-D", "python/understack-workflows"]
7581
- repo: https://github.com/renovatebot/pre-commit-hooks
7682
rev: 40.8.1
7783
hooks:

containers/ironic-nautobot-client/Dockerfile.ironic-nautobot-client

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,24 @@ FROM ${BASE} AS builder
33

44
RUN --mount=type=cache,target=/var/cache/apk apk add --virtual build-deps gcc python3-dev musl-dev linux-headers
55
RUN --mount=type=cache,target=/root/.cache/pip pip install 'wheel==0.43.0'
6-
RUN --mount=type=cache,target=/root/.cache/pip \
7-
python -m venv /opt/poetry && \
8-
/opt/poetry/bin/pip install 'poetry==1.7.1' && \
9-
/opt/poetry/bin/poetry self add 'poetry-dynamic-versioning[plugin]==1.3.0'
6+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
107

118
# copy in the code
12-
COPY --chown=appuser:appgroup python/understack-workflows /app
13-
COPY --chown=appuser:appgroup python/understack-flavor-matcher /understack-flavor-matcher
14-
# need netifaces built as a wheel
15-
RUN --mount=type=cache,target=/root/.cache/pip pip wheel --wheel-dir /app/dist netifaces psutil==6.1.1
16-
# build wheels and requirements.txt, skip hashes due to building of netifaces above which won't match
17-
RUN cd /app && /opt/poetry/bin/poetry build -f wheel && /opt/poetry/bin/poetry export --without-hashes -f requirements.txt -o dist/requirements.txt
9+
COPY --chown=appuser:appgroup python/understack-workflows /tmp/understack/python/understack-workflows
10+
COPY --chown=appuser:appgroup python/understack-flavor-matcher /tmp/understack/python/understack-flavor-matcher
11+
12+
# install our requirements and our packages
13+
RUN --mount=type=cache,target=/root/.cache/uv \
14+
uv venv /opt/venv && \
15+
uv pip install \
16+
netifaces \
17+
psutil==6.1.1 \
18+
/tmp/understack/python/understack-workflows \
19+
/tmp/understack/python/understack-flavor-matcher
1820

1921
FROM ${BASE} AS prod
2022
LABEL org.opencontainers.image.description="UnderStack Workflows"
21-
WORKDIR /app
22-
23-
RUN mkdir -p /opt/venv/wheels/
24-
COPY --from=builder /app/dist/*.whl /app/dist/requirements.txt /opt/venv/wheels/
25-
COPY --chown=appuser:appgroup python/understack-flavor-matcher /understack-flavor-matcher
2623

27-
RUN --mount=type=cache,target=/root/.cache/pip /opt/venv/bin/pip install --find-links /opt/venv/wheels/ --only-binary netifaces psutil -r /opt/venv/wheels/requirements.txt understack-workflows
24+
COPY --from=builder --link /opt/venv /opt/venv
2825

2926
USER appuser
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
# syntax=docker/dockerfile:1
22

33
ARG OPENSTACK_VERSION="required_argument"
4-
FROM docker.io/openstackhelm/ironic:${OPENSTACK_VERSION}-ubuntu_jammy
4+
FROM docker.io/openstackhelm/ironic:${OPENSTACK_VERSION}-ubuntu_jammy AS builder
5+
6+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
7+
8+
COPY python/ironic-understack /tmp/understack/ironic-understack
9+
COPY python/understack-flavor-matcher /tmp/understack/understack-flavor-matcher
10+
11+
RUN --mount=type=cache,target=/root/.cache/uv \
12+
for proj in $(find /tmp/understack -name pyproject.toml); do \
13+
cd $(dirname ${proj}) && uv build --wheel --out-dir /tmp/wheels/; \
14+
done
15+
16+
FROM docker.io/openstackhelm/ironic:${OPENSTACK_VERSION}-ubuntu_jammy AS final
517

618
RUN apt-get update && \
719
apt-get install -y --no-install-recommends \
@@ -11,9 +23,12 @@ RUN apt-get update && \
1123
quilt \
1224
&& apt-get clean && rm -rf /var/lib/apt/lists/*
1325

26+
RUN --mount=type=cache,target=/root/.cache/pip \
27+
--mount=from=builder,source=/tmp/wheels,target=/tmp/wheels \
28+
/var/lib/openstack/bin/python -m pip install --no-input --find-links /tmp/wheels/ \
29+
ironic-understack \
30+
understack-flavor-matcher \
31+
sushy-oem-idrac==6.0.0
1432
COPY containers/ironic/patches /tmp/patches/
15-
COPY python/ironic-understack /tmp/ironic-understack
16-
COPY python/understack-flavor-matcher /tmp/understack-flavor-matcher
17-
RUN /var/lib/openstack/bin/python -m pip install --no-cache --no-cache-dir /tmp/ironic-understack /tmp/understack-flavor-matcher sushy-oem-idrac==6.0.0
1833
RUN cd /var/lib/openstack/lib/python3.10/site-packages && \
1934
QUILT_PATCHES=/tmp/patches quilt push -a
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# syntax=docker/dockerfile:1
22

33
ARG OPENSTACK_VERSION="required_argument"
4-
FROM docker.io/openstackhelm/neutron:${OPENSTACK_VERSION}-ubuntu_jammy
4+
FROM docker.io/openstackhelm/neutron:${OPENSTACK_VERSION}-ubuntu_jammy AS builder
5+
6+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
57

68
COPY python/neutron-understack /tmp/neutron-understack
7-
RUN /var/lib/openstack/bin/python -m pip install --no-input --no-cache-dir /tmp/neutron-understack
9+
10+
RUN --mount=type=cache,target=/root/.cache/uv \
11+
cd /tmp/neutron-understack && \
12+
uv build --wheel --out-dir /tmp/wheels/
13+
14+
FROM docker.io/openstackhelm/neutron:${OPENSTACK_VERSION}-ubuntu_jammy AS final
15+
16+
RUN --mount=type=cache,target=/root/.cache/pip \
17+
--mount=from=builder,source=/tmp/wheels,target=/tmp/wheels \
18+
/var/lib/openstack/bin/python -m pip install --no-input --find-links /tmp/wheels/ neutron-understack

python/diff-nautobot-understack/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ This tool compares data between Nautobot and OpenStack.
99
| Project | Tenant |
1010
| Network | UCVNI & Namespace |
1111

12-
1312
---
1413

1514
## Setup Instructions
1615

1716
1. cd python/diff-nautobot-understack
18-
2. `poetry install`
19-
1. poetry will handle the creation of this virtual environment for you. It'll use .venv in the project if you configure it to do so locally on your machine with `poetry config virtualenvs.in-project true`.
20-
2. user can create a shell with poetry shell and then when they exit it will clean up auth variables. Or they can run source .venv/bin/activate or poetry run <commands-below>
17+
2. `uv sync`
18+
1. `uv` will handle the creation of this virtual environment for you. It'll use .venv in the project.
19+
2. user can create a shell with `uv shell` and then when they exit it will clean up auth variables. Or they can run source .venv/bin/activate or `uv run <commands-below>`
2120

2221
3. Export environment variables (or add them to a .env file):
2322
1. export NAUTOBOT_URL=https://nautobot.url.here

0 commit comments

Comments
 (0)