Skip to content

chore: switch from poetry to uv #812

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 13 additions & 13 deletions .github/workflows/code-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ jobs:
outputs:
projects: ${{ steps.set-projects.outputs.projects }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Find all Python projects with pyproject.toml
- uses: actions/checkout@v4
- name: Find all projects with pyproject.toml
id: set-projects
run: |
# grabs all paths with pyproject.toml, snips the 2nd dir, grabs only unique ones, makes a JSON list
projects=$(find python -mindepth 2 -name pyproject.toml | awk -F/ '{print $2}' | sort -u | jq -R -s -c 'split("\n")[:-1]')
projects=$(find . -name pyproject.toml | jq -R -s -c 'split("\n")[:-1] | map(capture("python/(?<name>[^/]+)/pyproject.toml").name)')
echo "projects=$projects" >> "$GITHUB_OUTPUT"
python:

uv:
needs: [discover]
runs-on: ubuntu-latest

Expand All @@ -46,22 +46,22 @@ jobs:

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: pipx install poetry==1.7.1 && poetry self add 'poetry-dynamic-versioning[plugin]'
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
- uses: astral-sh/setup-uv@v5
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
with:
python-version-file: python/${{ matrix.project }}/pyproject.toml
cache: "poetry"
- run: poetry install --sync --with test
- run: poetry build
- run: "poetry run pytest --cov --cov-report xml:coverage.xml"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
- run: uv sync
- run: uv build --wheel
- run: "uv run pytest --cov --cov-report xml:coverage.xml"
- uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
with:
name: coverage-${{ matrix.project }}
path: python/${{ matrix.project }}/coverage.xml
retention-days: 1


coverage-upload:
needs: python
needs: [uv]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
Expand Down
30 changes: 18 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,25 @@ repos:
- ansible
- jmespath
files: '^ansible/.*$'
- repo: https://github.com/python-poetry/poetry
rev: '2.1.3'
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.7.13
hooks:
- id: poetry-check
language_version: "3.11"
name: "poetry-check (understack-workflows)"
files: '^python/understack-workflows/'
args: ["-C", "python/understack-workflows"]
- id: poetry-lock
language_version: "3.11"
name: "poetry-lock (understack-workflows)"
files: '^python/understack-workflows/'
args: ["-C", "python/understack-workflows"]
- id: uv-lock
name: diff-nautobot-understack
args: ["-D", "python/diff-nautobot-understack"]
- id: uv-lock
name: ironic-understack
args: ["-D", "python/ironic-understack"]
- id: uv-lock
name: neutron-understack
args: ["-D", "python/neutron-understack"]
- id: uv-lock
name: understack-flavor-matcher
args: ["-D", "python/understack-flavor-matcher"]
- id: uv-lock
name: understack-workflows
args: ["-D", "python/understack-workflows"]
- repo: https://github.com/renovatebot/pre-commit-hooks
rev: 40.8.1
hooks:
Expand Down
26 changes: 14 additions & 12 deletions containers/ironic-nautobot-client/Dockerfile.ironic-nautobot-client
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ FROM ${BASE} AS builder

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

# copy in the code
COPY --chown=appuser:appgroup python/understack-workflows /app
COPY --chown=appuser:appgroup python/understack-flavor-matcher /understack-flavor-matcher
COPY --chown=appuser:appgroup python/understack-workflows /tmp/understack/python/understack-workflows
COPY --chown=appuser:appgroup python/understack-flavor-matcher /tmp/understack/python/understack-flavor-matcher
# need netifaces built as a wheel
RUN --mount=type=cache,target=/root/.cache/pip pip wheel --wheel-dir /app/dist netifaces psutil==6.1.1
# build wheels and requirements.txt, skip hashes due to building of netifaces above which won't match
RUN cd /app && /opt/poetry/bin/poetry build -f wheel && /opt/poetry/bin/poetry export --without-hashes -f requirements.txt -o dist/requirements.txt
RUN --mount=type=cache,target=/root/.cache/uv \
for proj in $(find /tmp/understack -name pyproject.toml); do \
cd $(dirname ${proj}) && uv build --wheel --out-dir /tmp/wheels/; \
done && \
uv export --no-hashes -o /tmp/wheels/requirements.txt

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

RUN mkdir -p /opt/venv/wheels/
COPY --from=builder /app/dist/*.whl /app/dist/requirements.txt /opt/venv/wheels/
COPY --chown=appuser:appgroup python/understack-flavor-matcher /understack-flavor-matcher

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

USER appuser
23 changes: 19 additions & 4 deletions containers/ironic/Dockerfile.ironic
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# syntax=docker/dockerfile:1

ARG OPENSTACK_VERSION="required_argument"
FROM docker.io/openstackhelm/ironic:${OPENSTACK_VERSION}-ubuntu_jammy
FROM docker.io/openstackhelm/ironic:${OPENSTACK_VERSION}-ubuntu_jammy AS builder

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

COPY python/ironic-understack /tmp/understack/ironic-understack
COPY python/understack-flavor-matcher /tmp/understack/understack-flavor-matcher

RUN --mount=type=cache,target=/root/.cache/uv \
for proj in $(find /tmp/understack -name pyproject.toml); do \
cd $(dirname ${proj}) && uv build --wheel --out-dir /tmp/wheels/; \
done

FROM docker.io/openstackhelm/ironic:${OPENSTACK_VERSION}-ubuntu_jammy AS final

RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand All @@ -11,9 +23,12 @@ RUN apt-get update && \
quilt \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

RUN --mount=type=cache,target=/root/.cache/pip \
--mount=from=builder,source=/tmp/wheels,target=/tmp/wheels \
/var/lib/openstack/bin/python -m pip install --no-input --find-links /tmp/wheels/ \
ironic-understack \
understack-flavor-matcher \
sushy-oem-idrac==6.0.0
COPY containers/ironic/patches /tmp/patches/
COPY python/ironic-understack /tmp/ironic-understack
COPY python/understack-flavor-matcher /tmp/understack-flavor-matcher
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
RUN cd /var/lib/openstack/lib/python3.10/site-packages && \
QUILT_PATCHES=/tmp/patches quilt push -a
15 changes: 13 additions & 2 deletions containers/neutron/Dockerfile.neutron
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# syntax=docker/dockerfile:1

ARG OPENSTACK_VERSION="required_argument"
FROM docker.io/openstackhelm/neutron:${OPENSTACK_VERSION}-ubuntu_jammy
FROM docker.io/openstackhelm/neutron:${OPENSTACK_VERSION}-ubuntu_jammy AS builder

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

COPY python/neutron-understack /tmp/neutron-understack
RUN /var/lib/openstack/bin/python -m pip install --no-input --no-cache-dir /tmp/neutron-understack

RUN --mount=type=cache,target=/root/.cache/uv \
cd /tmp/neutron-understack && \
uv build --wheel --out-dir /tmp/wheels/

FROM docker.io/openstackhelm/neutron:${OPENSTACK_VERSION}-ubuntu_jammy AS final

RUN --mount=type=cache,target=/root/.cache/pip \
--mount=from=builder,source=/tmp/wheels,target=/tmp/wheels \
/var/lib/openstack/bin/python -m pip install --no-input --find-links /tmp/wheels/ neutron-understack
7 changes: 3 additions & 4 deletions python/diff-nautobot-understack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ This tool compares data between Nautobot and OpenStack.
| Project | Tenant |
| Network | UCVNI & Namespace |


---

## Setup Instructions

1. cd python/diff-nautobot-understack
2. `poetry install`
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`.
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>
2. `uv sync`
1. `uv` will handle the creation of this virtual environment for you. It'll use .venv in the project.
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>`

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