Skip to content

Commit a692815

Browse files
chore: uv as package manager (#926)
* chore: swap poetry for UV * ci: make actions use UV * chore: move pre-commit constraints to pyproject.toml * chore: add uv lock hook to pre-commit * ci: add snyk workflow * Update .pre-commit-config.yaml * ci: replace final poetry with uv * docs: update readme with uv * chore: add build system and package mode to pyproject * fix: version * chore: Remove all traces of poetry * chore: fix dependency specification * ci: fix broken workflows * fix: neqsim service fixture * Potential fix for code scanning alert no. 36: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * chore: sync uv.lock * chore: revise dockerfile * chore: fix devcontainer * docs: Review comment * chore: update uv lock * ci: update dependabot config & add snyk code test
1 parent 261fa48 commit a692815

22 files changed

Lines changed: 2996 additions & 4167 deletions

.devcontainer/python/Dockerfile

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
ARG VARIANT="3.11-bookworm"
22
FROM mcr.microsoft.com/devcontainers/python:${VARIANT}
33

4+
COPY --from=ghcr.io/astral-sh/uv:0.7.15 /uv /uvx /bin/
45

56
ARG DEBIAN_FRONTEND=noninteractive
6-
ARG POETRY_VERSION=1.8.3
7-
ARG POETRY_VIRTUALENVS_PATH
87
ENV USER=vscode
98

109
RUN DEBIAN_FRONTEND=noninteractive \
11-
&& apt-get update \
10+
&& apt-get update \
1211
&& apt-get install -y build-essential --no-install-recommends make \
1312
ca-certificates \
1413
git \
@@ -34,27 +33,9 @@ USER $USER
3433
ENV HOME="/home/$USER"
3534
ENV PATH="${HOME}/.local/bin:$PATH"
3635

37-
# Set poetry related env vars
38-
# Set poetry virtualenv path in writable dir outsde mounted workspace
39-
ENV POETRY_VIRTUALENVS_PATH="$HOME/.venv"
40-
ENV POETRY_VIRTUALENVS_CREATE=true
41-
ENV POETRY_VIRTUALENVS_IN_PROJECT=false
42-
ENV POETRY_VIRTUALENVS_PROMPT='ecalc-py{python_version}'
4336
ENV PIP_DEFAULT_TIMEOUT=100
4437

45-
# Python and poetry installation
46-
RUN echo $(which python) && echo $(which python3) \
47-
&& python3 -m pip install --upgrade pip pipx \
48-
&& pipx install "poetry==${POETRY_VERSION}" \
49-
&& pip install pre-commit \
50-
&& poetry --version \
51-
&& pre-commit --version
52-
53-
# Set workdir to ecalc project
54-
WORKDIR /workspaces/ecalc
38+
WORKDIR /project/libecalc
5539

5640
# Copy essential file (devcontainer setup takes care of other files)
57-
COPY pyproject.toml poetry.lock ./
58-
59-
# Install poetry environment without root package
60-
RUN poetry install --no-interaction --no-ansi --no-root
41+
COPY pyproject.toml uv.lock ./

.devcontainer/python/devcontainer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"dockerfile": "Dockerfile",
66
"context": "../..",
77
"args": {
8-
"VARIANT": "3.11-bookworm",
9-
"POETRY_VERSION": "1.8.3",
8+
"VARIANT": "3.11-bookworm"
109
}
1110
},
1211
"containerEnv": {

.devcontainer/python/post-create.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
# Exit immediately if a command exits with a non-zero status
44
set -e
55

6+
# Install uv environment
7+
uv venv
8+
uv sync --group dev --locked
9+
610
# Install Pre-commit hooks
711
echo "Installing Pre-commit hooks..."
12+
uv tool install pre-commit
813
pre-commit install
914

10-
# Install poetry environment
11-
poetry install
1215

1316
echo "Post-create script completed successfully."

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ updates:
1010

1111
# Monitor Python dependencies (pip ecosystem = poetry; poetry.lock) for security vulnerabilities only
1212
# TODO: Rename pre-commit-requirements.txt to requirements.txt or similar to detect it.
13-
- package-ecosystem: "pip"
13+
- package-ecosystem: "uv"
1414
directory: "/"
1515
schedule:
1616
interval: "daily"

.github/workflows/docs-ci.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,25 @@ jobs:
1414
- name: Checkout code
1515
uses: actions/checkout@v5
1616

17-
- name: Install Poetry
18-
run: pipx install poetry==1.8.4
19-
20-
- name: Setup Python
21-
uses: actions/setup-python@v5
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v6
2219
with:
23-
python-version: "3.11"
24-
cache: 'poetry'
20+
enable-cache: true
2521

26-
- name: Check pyproject.toml validity
27-
run: poetry check --no-interaction
22+
- name: Set up Python
23+
run: uv python install
2824

29-
- name: Install deps
30-
run: poetry install --no-interaction
25+
- name: Install the project
26+
run: uv sync --locked --all-extras --dev
3127

3228
- name: Generate CLI reference
3329
run: |
34-
poetry run typer src/ecalc_cli/main.py utils docs > ./docs/docs/about/getting_started/cli/cli_reference.md
30+
uv run typer src/ecalc_cli/main.py utils docs > ./docs/docs/about/getting_started/cli/cli_reference.md
3531
3632
- name: Generate JSON Schema
3733
run: |
3834
cd src
39-
poetry run python generate_json_schema.py > ../docs/docs/about/getting_started/yaml/ecalc_json_schema.json
35+
uv run python generate_json_schema.py > ../docs/docs/about/getting_started/yaml/ecalc_json_schema.json
4036
4137
- name: Setup node
4238
uses: actions/setup-node@v4

.github/workflows/docs-publish.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,25 @@ jobs:
2020
- name: Checkout code
2121
uses: actions/checkout@v5
2222

23-
- name: Install Poetry
24-
run: pipx install poetry==1.8.4
25-
26-
- name: Setup Python
27-
uses: actions/setup-python@v5
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v6
2825
with:
29-
python-version: "3.11"
30-
cache: 'poetry'
26+
enable-cache: true
3127

32-
- name: Check pyproject.toml validity
33-
run: poetry check --no-interaction
28+
- name: Set up Python
29+
run: uv python install
3430

35-
- name: Install deps
36-
run: poetry install --no-interaction
31+
- name: Install the project
32+
run: uv sync --locked --all-extras --dev
3733

3834
- name: Generate CLI reference
3935
run: |
40-
poetry run typer src/ecalc_cli/main.py utils docs > ./docs/docs/about/getting_started/cli/cli_reference.md
36+
uv run typer src/ecalc_cli/main.py utils docs > ./docs/docs/about/getting_started/cli/cli_reference.md
4137
4238
- name: Generate JSON Schema
4339
run: |
4440
cd src
45-
poetry run python generate_json_schema.py > ../docs/docs/about/getting_started/yaml/ecalc_json_schema.json
41+
uv run python generate_json_schema.py > ../docs/docs/about/getting_started/yaml/ecalc_json_schema.json
4642
4743
- name: Setup node
4844
uses: actions/setup-node@v4

.github/workflows/examples-ci.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,20 @@ jobs:
1212
- name: Checkout code
1313
uses: actions/checkout@v5
1414

15-
- name: Install Poetry
16-
run: pipx install poetry==1.8.4
17-
18-
- name: Setup Python
19-
uses: actions/setup-python@v5
15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v6
2017
with:
21-
python-version: "3.11"
22-
cache: 'poetry'
18+
enable-cache: true
2319

24-
- name: Check pyproject.toml validity
25-
run: poetry check --no-interaction
20+
- name: Set up Python
21+
run: uv python install
2622

27-
- name: Install deps
28-
run: poetry install --no-interaction --all-extras
23+
- name: Install the project
24+
run: uv sync --locked --all-extras --dev
2925

3026
- name: Convert example Jupyter notebooks to Python code
31-
run: poetry run jupyter nbconvert --to python examples/*.ipynb
27+
run: uv run jupyter nbconvert --to python examples/*.ipynb
3228

3329
# This will not log any tests per se, but it will fail if there are any errors raised in the generated Python files.
3430
- name: Run tests
35-
run: poetry run pytest examples/*.py
31+
run: uv run pytest examples/*.py

.github/workflows/lib-ci.yml

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ env:
1010

1111
# TODO: BuildX and publish to use as in order for web to always be able to fetch image to matching branch?
1212
jobs:
13-
1413
run-tests-with-coverage:
1514
runs-on: ubuntu-24.04
1615
strategy:
@@ -21,40 +20,37 @@ jobs:
2120
- name: Checkout code
2221
uses: actions/checkout@v5
2322

24-
- name: Install Poetry
25-
run: pipx install poetry==1.8.4
26-
27-
- name: Setup Python ${{ matrix.python-version }}
28-
uses: actions/setup-python@v5
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v6
2925
with:
26+
enable-cache: true
3027
python-version: ${{ matrix.python-version }}
31-
cache: 'poetry'
3228

33-
- name: Check pyproject.toml validity
34-
run: poetry check --no-interaction
29+
- name: Set up Python
30+
run: uv python install
3531

36-
- name: Install deps
37-
run: poetry install --no-interaction
32+
- name: Install the project
33+
run: uv sync --locked --all-extras --dev
3834

3935
- name: List pydantic version
40-
run: poetry show pydantic
36+
run: uv pip show pydantic
4137

4238
- name: Run tests with coverage
43-
run: poetry run python -m coverage run -m pytest -n auto
39+
run: uv run python -m coverage run -m pytest -n auto
4440

4541
- name: Get Test Coverage score
4642
id: total
4743
if: matrix.python-version == '3.11'
4844
run: |
49-
poetry run python -m coverage report --fail-under 40
50-
poetry run python -m coverage html -d build/
51-
poetry run python -m coverage json -o build/coverage.json
45+
uv run python -m coverage report --fail-under 40
46+
uv run python -m coverage html -d build/
47+
uv run python -m coverage json -o build/coverage.json
5248
echo '# Code Coverage Report\n See the index.html for a more detailed report.\n' >> build/README.md
53-
echo "$(poetry run python -m coverage report --format=markdown)" >> build/README.md
49+
echo "$(uv run python -m coverage report --format=markdown)" >> build/README.md
5450
rm build/.gitignore
5551
5652
- name: Build artifacts
57-
run: poetry build
53+
run: uv build
5854

5955
- name: Push coverage report to coverage-report branch
6056
if: github.ref == 'refs/heads/main' && matrix.python-version == '3.11'

.github/workflows/pre-ci.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,23 @@ on:
66
# Workflow call is used for called from another workflow
77
workflow_call:
88

9+
env:
10+
UV_SYSTEM_PYTHON: 1
11+
912
jobs:
1013
pre-commit: # Static analyzers, formatters and verifying pre-commit hooks has been run for both API and Web
1114
name: Build & Run Pre Commit hooks to verify code structure, quality etc. from pre-commit hooks
1215
runs-on: ubuntu-24.04
1316
steps:
1417
- uses: actions/checkout@v5
1518

16-
- name: Set up python
17-
id: setup-python
18-
uses: actions/setup-python@v5
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v6
1921
with:
20-
python-version: "3.11"
21-
cache: "pip"
22+
enable-cache: true
2223

2324
- name: Install pre-commit
24-
run: python -m pip install -r pre-commit-requirements.txt
25-
- uses: actions/cache@v4
26-
with:
27-
path: ~/.cache/pre-commit/
28-
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
25+
run: uv sync --only-group dev -v
26+
2927
- name: Run pre-commit
30-
run: SKIP=trufflehog pre-commit run --all-files --verbose
28+
run: SKIP=trufflehog uv run pre-commit run --all-files --verbose

.github/workflows/publish.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
# order for this workflow to be the owner of the PyPI publishing job, and can be verified. This limits
1212
# us to only allow this workflow to be allowed to publish to PyPI trustedly.
1313

14-
workflow_dispatch: # Trigger manually, if needed
14+
workflow_dispatch: # Trigger manually, if needed.
1515

1616
# NOTE!: When using Trusted Publishing to PyPI, we cannot do that from within a reusable workflow, therefore
1717
# we make it independent, and trigger it with published event from release-please workflow, instead of calling explicitly.
@@ -53,22 +53,22 @@ jobs:
5353
- name: Checkout code
5454
uses: actions/checkout@v5
5555
with:
56-
# NOTE: Make sure we publish from main branch, not the triggering ref
56+
# NOTE: Make sure we publish from the main branch, not the triggering ref
5757
ref: ${{ github.event.repository.default_branch }}
5858

59-
- name: Setup Python 3.11
60-
uses: actions/setup-python@v5
59+
- name: Install uv
60+
uses: astral-sh/setup-uv@v6
6161
with:
62-
python-version: '3.11'
62+
enable-cache: true
6363

64-
- uses: snok/install-poetry@v1
65-
with:
66-
version: 1.8.4
67-
virtualenvs-create: true
64+
- name: Set up Python
65+
run: uv python install
66+
67+
- name: Install the project
68+
run: uv sync --locked --all-extras --dev
6869

6970
- name: Build the libecalc package (wheel and sdist by default)
70-
run: |
71-
poetry build
71+
run: uv build
7272

7373
- name: Publish to PyPI
7474
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)