Skip to content

Commit

Permalink
chore: Use uv to manage the python package (#72)
Browse files Browse the repository at this point in the history
And fix the `[project]` config in `pyproject.toml` in preparation for
releasing a package
  • Loading branch information
ABorgna authored Oct 2, 2024
1 parent 34ef1e4 commit 389123d
Show file tree
Hide file tree
Showing 9 changed files with 2,098 additions and 2,747 deletions.
31 changes: 13 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,22 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: '3.11'
cache: 'poetry'
enable-cache: true
- name: Install the project libraries
run: poetry install
run: uv sync --locked
- name: Check rust formatting
run: cargo fmt -p quizx_pybindings -- --check
- name: Run clippy
run: cargo clippy --all-targets --all-features -p quizx_pybindings -- -D warnings
- name: Type check python with mypy
run: poetry run mypy .
run: uv run mypy .
- name: Check python formatting with ruff
run: poetry run ruff format --check
run: uv run ruff format --check
- name: Lint python with ruff
run: poetry run ruff check
run: uv run ruff check

test-quizx-stable:
needs: changes
Expand Down Expand Up @@ -160,19 +158,16 @@ jobs:
components: rustfmt, clippy
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: '3.11'
cache: 'poetry'
enable-cache: true
- name: Install the project libraries
run: poetry install
run: uv sync --locked
- name: Build pyo3 bindings
run: |
poetry run maturin develop
run: uv run maturin develop
- name: Test pyo3 bindings
run: true
# No tests yet, so running `pytest` fails
#run: poetry run pytest
run: uv run pytest

# This is a meta job to mark successful completion of the required checks,
# even if they are skipped due to no changes in the relevant files.
Expand Down
59 changes: 51 additions & 8 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# This file is autogenerated by maturin v1.5.1, and manually modified to use poetry.
# This file is autogenerated by maturin v1.7.4
# To update, run
#
# maturin generate-ci github
#
name: Wheels
name: CI

on:
push:
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
Expand All @@ -53,6 +53,37 @@ jobs:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
Expand All @@ -66,7 +97,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: 3.x
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
Expand All @@ -85,15 +116,15 @@ jobs:
strategy:
matrix:
platform:
- runner: macos-latest
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
Expand Down Expand Up @@ -124,13 +155,25 @@ jobs:
release:
name: Release
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: [linux, windows, macos, sdist]
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' }}
needs: [linux, musllinux, windows, macos, sdist]
permissions:
# Use to sign the release artifacts
id-token: write
# Used to upload release artifacts
contents: write
# Used to generate artifact attestation
attestations: write
steps:
- uses: actions/download-artifact@v4
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-path: 'wheels-*/*'
- name: Publish to PyPI
# TODO: Disabled until the package is ready for release
if: false
# if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ repos:
- id: ruff format
name: ruff format
description: Format python code with `ruff format`.
entry: poetry run ruff format
entry: uv run ruff format
language: system
files: \.py$
pass_filenames: false
- id: ruff lint
name: ruff lint
description: Lint python code with `ruff lint`.
entry: poetry run ruff check
entry: uv run ruff check
language: system
files: \.py$
pass_filenames: false
- id: mypy
name: mypy
description: Run mypy type checker.
entry: poetry run mypy pybindings
entry: uv run mypy pybindings
language: system
files: \.py$
pass_filenames: false
Expand Down
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#ff6433",
"activityBar.background": "#ff6433",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#00ff3d",
"activityBarBadge.foreground": "#15202b",
"commandCenter.border": "#e7e7e799",
"sash.hoverBorder": "#ff6433",
"statusBar.background": "#ff3d00",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#ff6433",
"statusBarItem.remoteBackground": "#ff3d00",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#ff3d00",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#ff3d0099",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#ff3d00"
}
16 changes: 6 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ If you find any errors or omissions in this document, please [open an issue](htt

## #️⃣ Setting up the development environment

To develop the rust library, you will need to have the rust toolchain installed. You can install it by following the instructions at [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).
To develop the rust library, you will need to have the rust toolchain installed. You can install it by following the instructions at [rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).

If you are using VSCode, you can install the `rust-analyzer` extension to get code completion and other features.

To develop the python library, you will additionally need the Poetry package manager. You can install it by following the instructions at [https://python-poetry.org/docs/](https://python-poetry.org/docs/).
To develop the python library, you will additionally need the `uv` package manager. You can install it by following the instructions at [docs.astral.sh/uv/](https://docs.astral.sh/uv/).

Finally, we provide a `just` file to help manage the common development workflow. You can install `just` by following the instructions at [https://just.systems/](https://just.systems/).
Finally, we provide a `just` file to help manage the common development workflow. You can install `just` by following the instructions at [just.systems](https://just.systems/).

Once you have these installed, run `just setup` to download the necessary dependencies and set up some pre-commit hooks.

Expand All @@ -30,14 +30,10 @@ cargo run --release --example <program_name>
To build the python library, run:

```bash
# Ensure you have all the necessary dependencies installed
poetry install
# Enter the environment with the installed dependencies
poetry shell
# Build the python library
maturin develop
# Setup the dependencies and build the python library
uv run maturin develop
# The library will now be available for import in python
python -c "import quizx"
uv run python -c "import quizx"
```

## 🏃 Running the tests
Expand Down
18 changes: 6 additions & 12 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,36 @@ help:
# Prepare the environment for development, installing all the dependencies and
# setting up the pre-commit hooks.
setup:
poetry install
poetry run pre-commit install -t pre-commit
uv run pre-commit install -t pre-commit

# Run the pre-commit checks.
check:
poetry run pre-commit run --all-files
uv run pre-commit run --all-files

# Build the project.
build language="[rust|python]": (_run_lang language \
"cargo build" \
"poetry run maturin develop"
"uv run maturin develop"
)

# Run all the tests.
test language="[rust|python]": (_run_lang language \
"cargo test --all-features" \
"poetry run maturin develop && poetry run pytest"
"uv run maturin develop && uv run pytest"
)

# Auto-fix all clippy warnings.
fix language="[rust|python]": (_run_lang language \
"cargo clippy --all-targets --all-features --workspace --fix --allow-staged --allow-dirty" \
"poetry run ruff check --fix"
"uv run ruff check --fix"
)

# Format the code.
format language="[rust|python]": (_run_lang language \
"cargo fmt" \
"poetry run ruff format"
"uv run ruff format"
)

# Load a shell with all the dependencies installed
shell:
poetry shell


# Runs a rust and a python command, depending on the `language` variable.
#
# If `language` is set to `rust` or `python`, only run the command for that language.
Expand Down
Loading

0 comments on commit 389123d

Please sign in to comment.