Skip to content

Commit b35de8b

Browse files
committed
chore: switch from poetry to uv
1 parent 9a04dcb commit b35de8b

File tree

21 files changed

+7189
-9817
lines changed

21 files changed

+7189
-9817
lines changed

.github/workflows/code-test.yaml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,48 @@ concurrency:
2020
group: ${{ github.workflow }}-${{ github.ref }}
2121

2222
jobs:
23-
python:
23+
discover:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
projects: ${{ steps.set-projects.outputs.projects }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Find all projects with pyproject.toml
30+
id: set-projects
31+
run: |
32+
projects=$(find . -name pyproject.toml | jq -R -s -c 'split("\n")[:-1] | map(capture("python/(?<name>[^/]+)/pyproject.toml").name)')
33+
echo "projects=$projects" >> "$GITHUB_OUTPUT"
34+
35+
uv:
36+
needs: [discover]
2437
runs-on: ubuntu-latest
2538

2639
strategy:
2740
matrix:
28-
project:
29-
- understack-workflows
30-
- understack-flavor-matcher
31-
- neutron-understack
41+
project: ${{ fromJson(needs.discover.outputs.projects) }}
3242

3343
defaults:
3444
run:
3545
working-directory: ./python/${{ matrix.project }}
3646

3747
steps:
3848
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
39-
- run: pipx install poetry==1.7.1 && poetry self add 'poetry-dynamic-versioning[plugin]'
49+
- uses: astral-sh/setup-uv@v5
4050
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
4151
with:
4252
python-version-file: python/${{ matrix.project }}/pyproject.toml
43-
cache: "poetry"
44-
- run: poetry install --sync --with test
45-
- run: poetry build
46-
- run: "poetry run pytest --cov --cov-report xml:coverage.xml"
53+
- run: uv sync
54+
- run: uv build --wheel
55+
- run: "uv run pytest --cov --cov-report xml:coverage.xml"
4756
- uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
4857
with:
4958
name: coverage-${{ matrix.project }}
5059
path: python/${{ matrix.project }}/coverage.xml
5160
retention-days: 1
5261

62+
5363
coverage-upload:
54-
needs: python
64+
needs: [uv]
5565
runs-on: ubuntu-latest
5666
steps:
5767
- uses: actions/download-artifact@b14cf4c92620c250e1c074ab0a5800e37df86765 # v4

.pre-commit-config.yaml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,25 @@ repos:
4848
- id: ruff
4949
args: [--fix]
5050
- id: ruff-format
51-
- repo: https://github.com/python-poetry/poetry
52-
rev: '1.7.1'
51+
- repo: https://github.com/astral-sh/uv-pre-commit
52+
# uv version.
53+
rev: 0.6.11
5354
hooks:
54-
- id: poetry-check
55-
language_version: "3.11"
56-
name: "poetry-check (understack-workflows)"
57-
files: '^python/understack-workflows/'
58-
args: ["-C", "python/understack-workflows"]
59-
- id: poetry-lock
60-
language_version: "3.11"
61-
name: "poetry-lock (understack-workflows)"
62-
files: '^python/understack-workflows/'
63-
args: ["-C", "python/understack-workflows", "--no-update"]
55+
- id: uv-lock
56+
name: diff-nautobot-understack
57+
args: ["-D", "python/diff-nautobot-understack"]
58+
- id: uv-lock
59+
name: ironic-understack
60+
args: ["-D", "python/ironic-understack"]
61+
- id: uv-lock
62+
name: neutron-understack
63+
args: ["-D", "python/neutron-understack"]
64+
- id: uv-lock
65+
name: understack-flavor-matcher
66+
args: ["-D", "python/understack-flavor-matcher"]
67+
- id: uv-lock
68+
name: understack-workflows
69+
args: ["-D", "python/understack-workflows"]
6470
- repo: https://github.com/renovatebot/pre-commit-hooks
6571
rev: 39.174.0
6672
hooks:

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,29 @@ 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
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
1411
# need netifaces built as a wheel
1512
RUN --mount=type=cache,target=/root/.cache/pip pip wheel --wheel-dir /app/dist netifaces psutil==6.1.1
1613
# 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
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
for proj in $(find /tmp/understack -name pyproject.toml); do \
16+
cd $(dirname ${proj}) && uv build --wheel --out-dir /tmp/wheels/; \
17+
done && \
18+
uv export --no-hashes -o /tmp/wheels/requirements.txt
1819

1920
FROM ${BASE} AS prod
2021
LABEL org.opencontainers.image.description="UnderStack Workflows"
2122
WORKDIR /app
2223

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
26-
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+
RUN --mount=type=cache,target=/root/.cache/pip \
25+
--mount=from=builder,source=/tmp/wheels,target=/tmp/wheels \
26+
/opt/venv/bin/python -m pip install --no-input --find-links /tmp/wheels/ \
27+
--only-binary netifaces psutils \
28+
-r /tmp/wheels/requirements.txt \
29+
understack-workflows
2830

2931
USER appuser

containers/ironic/Dockerfile.ironic

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
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); \
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 \
820
genisoimage \
921
isolinux \
1022
&& apt-get clean && rm -rf /var/lib/apt/lists/*
1123

12-
COPY python/ironic-understack /tmp/ironic-understack
13-
COPY python/understack-flavor-matcher /tmp/understack-flavor-matcher
14-
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
24+
RUN --mount=type=cache,target=/root/.cache/pip \
25+
--mount=from=builder,source=/tmp/wheels,target=/tmp/wheels \
26+
/var/lib/openstack/bin/python -m pip install --no-input --find-links /tmp/wheels/ \
27+
ironic-understack \
28+
understack-flavor-matcher \
29+
sushy-oem-idrac==6.0.0

containers/neutron/Dockerfile.neutron

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)