-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaces the python project manager with `uv`. For most commands that used poetry before, it just be as easy as replacing `poetry {things}` with `uv {things}`. Some notable exeptions: - Instead of `poetry install --with extra1,extra2`, use `uv sync --extra extra1 --extra extra2`. Note that will delete any extraneous packages/extras so the venv state is deterministic. Add `--inexact` if you want to replicate the old poetry behaviour. - `poetry shell` is no longer available. The preferred workflow is to `uv run` / `uvx` things, to ensure you are always in sync with the project definition. If that's too annoying, it is always possible to `source .venv/bin/activate`. Updates the justfile, so using that should be the same as before. --------- Co-authored-by: Seyon Sivarajah <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,234 additions
and
1,381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ python: | |
- "tket2-py/**" | ||
- "tket2-eccs/**" | ||
- "pyproject.toml" | ||
- "poetry.lock" | ||
- "uv.lock" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
|
||
# Installs a fixed UV version | ||
# | ||
# This reads the `UV_CACHE_DIR` environment variable if it is set, | ||
# and stores the downloaded dependencies in that directory. | ||
|
||
curl -LsSf https://astral.sh/uv/0.3.4/install.sh | sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ env: | |
CI: true # insta snapshots behave differently on ci | ||
SCCACHE_GHA_ENABLED: "true" | ||
RUSTC_WRAPPER: "sccache" | ||
UV_CACHE_DIR: /tmp/.uv-cache | ||
|
||
jobs: | ||
# Check if changes were made to the relevant files. | ||
|
@@ -82,23 +83,29 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: mozilla-actions/[email protected] | ||
- name: Install poetry | ||
run: pipx install poetry | ||
- name: Set up Python | ||
- name: Set up uv | ||
run: .github/script/install-uv.sh | ||
- name: "Set up Python" | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
cache: "poetry" | ||
- name: Install the project libraries | ||
# Note: We do not need to compile with maturin here, | ||
# as we are only checking the Python code. | ||
run: poetry install | ||
python-version: '3.12' | ||
- name: Restore uv cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ env.UV_CACHE_DIR }} | ||
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} | ||
restore-keys: | | ||
uv-${{ runner.os }} | ||
- name: Setup dependencies | ||
run: uv sync --locked | ||
- name: Type check with mypy | ||
run: poetry run mypy . | ||
run: uv run mypy . | ||
- name: Check formatting with ruff | ||
run: poetry run ruff format --check | ||
run: uv run ruff format --check | ||
- name: Lint with ruff | ||
run: poetry run ruff check | ||
run: uv run ruff check | ||
- name: Minimize uv cache | ||
run: uv cache prune --ci | ||
|
||
benches: | ||
name: Build benchmarks 🏋️ | ||
|
@@ -226,23 +233,30 @@ jobs: | |
- uses: mozilla-actions/[email protected] | ||
- name: Install stable toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
- name: Install poetry | ||
run: pipx install poetry | ||
- uses: actions/setup-python@v5 | ||
- name: Set up uv | ||
run: .github/script/install-uv.sh | ||
- name: "Set up Python" | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
cache: 'poetry' | ||
- name: Build pyo3 bindings | ||
run: | | ||
poetry install | ||
poetry run maturin develop | ||
python-version: '3.10' | ||
- name: Restore uv cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ env.UV_CACHE_DIR }} | ||
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} | ||
restore-keys: | | ||
uv-${{ runner.os }} | ||
- name: Setup dependencies | ||
run: uv sync --locked | ||
- name: Run python tests with coverage instrumentation | ||
run: poetry run pytest --cov=./ --cov-report=xml | ||
run: uv run pytest --cov=./ --cov-report=xml | ||
- name: Upload coverage output artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: py-coverage | ||
path: coverage.xml | ||
- name: Minimize uv cache | ||
run: uv cache prune --ci | ||
|
||
coverage-py: | ||
name: Upload Python coverage 🐍 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ jobs: | |
strategy: | ||
matrix: | ||
target: | ||
- { name: tket2-eccs, key_secret: PYPI_PUBLISH_TKET2_ECCS } | ||
- { dir: tket2-eccs, name: tket2_eccs, key_secret: PYPI_PUBLISH_TKET2_ECCS } | ||
steps: | ||
# Check the release tag against the package name | ||
# | ||
|
@@ -35,41 +35,56 @@ jobs: | |
run: | | ||
echo "run=$SHOULD_RUN" >> $GITHUB_OUTPUT | ||
env: | ||
SHOULD_RUN: ${{ github.event_name != 'release' || ( github.ref_type == 'tag' && startsWith(github.ref, format('refs/tags/{0}-v', matrix.target.name)) ) }} | ||
SHOULD_RUN: ${{ github.event_name != 'release' || ( github.ref_type == 'tag' && startsWith(github.ref, format('refs/tags/{0}-v', matrix.target.dir)) ) }} | ||
|
||
- uses: actions/checkout@v4 | ||
if: ${{ steps.check-tag.outputs.run == 'true' }} | ||
- name: Run sccache-cache | ||
if: ${{ steps.check-tag.outputs.run == 'true' }} | ||
uses: mozilla-actions/[email protected] | ||
- name: Install poetry | ||
|
||
|
||
- name: Set up uv | ||
if: ${{ steps.check-tag.outputs.run == 'true' }} | ||
run: pipx install poetry | ||
- name: Set up Python '3.10' | ||
run: .github/script/install-uv.sh | ||
- name: Set up Python | ||
if: ${{ steps.check-tag.outputs.run == 'true' }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
cache: "poetry" | ||
python-version: '3.12' | ||
|
||
- name: Build sdist and wheels | ||
if: ${{ steps.check-tag.outputs.run == 'true' }} | ||
run: | | ||
cd ${{ matrix.target.name }} | ||
poetry build -o ../dist | ||
cd ${{ matrix.target.dir }} | ||
uvx --from build pyproject-build --installer uv --outdir ../dist | ||
- name: Upload the built packages as artifacts | ||
if: ${{ steps.check-tag.outputs.run == 'true' }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: build-${{ matrix.target.name }}-sdist | ||
name: build-${{ matrix.target.dir }}-sdist | ||
path: | | ||
dist/*.tar.gz | ||
dist/*.whl | ||
- name: Test installing the built wheels | ||
if: ${{ steps.check-tag.outputs.run == 'true' }} | ||
run: | | ||
echo "Testing the newly built ${{ matrix.target.name }} wheels..." | ||
uv run -f dist --with ${{ matrix.target.name }} --refresh-package ${{ matrix.target.name }} --no-project -- python -c "import ${{ matrix.target.name }}" | ||
uvx twine check --strict dist/* | ||
- name: Publish to PyPI | ||
if: ${{ (github.event_name == 'release' && github.ref_type == 'tag' && startsWith(github.ref, format('refs/tags/{0}-v', matrix.target.name)) ) || (github.event_name == 'workflow_dispatch' && github.ref_type == 'tag' && startsWith(github.ref, format('refs/tags/{0}-v', matrix.target.name)) ) }} | ||
if: ${{ (github.event_name == 'release' && github.ref_type == 'tag' && startsWith(github.ref, format('refs/tags/{0}-v', matrix.target.dir)) ) || (github.event_name == 'workflow_dispatch' && github.ref_type == 'tag' && startsWith(github.ref, format('refs/tags/{0}-v', matrix.target.dir)) ) }} | ||
run: | | ||
cd ${{ matrix.target.name }} | ||
poetry config pypi-token.pypi ${{ secrets[matrix.target.key_secret] }} | ||
poetry publish --dist-dir ../dist --skip-existing | ||
echo "Publishing to PyPI..." | ||
echo "Based on the following workflow variables, this is a new version tag push:" | ||
echo " - event_name: ${{ github.event_name }}" | ||
echo " - ref_type: ${{ github.ref_type }}" | ||
echo " - ref: ${{ github.ref }}" | ||
uvx twine upload --skip-existing --verbose dist/* | ||
env: | ||
TWINE_NON_INTERACTIVE: 1 | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets[matrix.target.key_secret] }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.