Skip to content
Merged
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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,31 @@ jobs:
- uses: astral-sh/setup-uv@v6
- run: echo "RUFF=$(uv export --only-group dev --no-hashes --frozen | grep '^ruff==')" >> "$GITHUB_ENV"
- run: uvx --from "$RUFF" ruff format --check
# rustfmt and clippy, also on Windows, where the binary waits for Python. `make test` and
# the Windows job run the Rust tests.
rust:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --check
- run: cargo clippy --workspace --all-targets -- -D warnings
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: uv sync --frozen
- run: make typecheck
test:
Expand All @@ -40,6 +58,8 @@ jobs:
- uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: uv sync --frozen
- run: make test
# The build's self-check runs the sandbox, which must also work on an instructor's Mac.
Expand All @@ -50,6 +70,8 @@ jobs:
- uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: uv sync --frozen
- run: make test
# Students on Windows run the check panels, the export button, the selfcheck and the PDF.
Expand All @@ -61,12 +83,16 @@ jobs:
- uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: uv sync --frozen
- run: cargo test --workspace
- run: >-
uv run pytest -q
tests/test_config.py tests/test_source.py tests/test_transform.py
tests/test_assertrewrite_guard.py tests/test_runner.py tests/test_check.py
tests/test_loader.py tests/test_selfcheck.py tests/test_export.py tests/test_pdf.py
tests/test_binary.py
# The autograder graded in Gradescope's base image. MOGS_REQUIRE_CONTAINER makes a missing
# Docker fail the job instead of skipping the tests.
docker:
Expand All @@ -79,5 +105,7 @@ jobs:
- uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: uv sync --frozen
- run: uv run pytest -m docker -v
160 changes: 160 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: release
on:
release:
types: [published]
permissions:
contents: read
jobs:
# Tags look like `0.7`: the tag, padded with `.0` to three parts, must equal the version in
# Cargo.toml, which the wheels carry.
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v4
- id: check
env:
TAG: ${{ github.event.release.tag_name }}
run: |
version=$(sed -n 's/^version = "\(.*\)"$/\1/p' Cargo.toml)
padded="$TAG"
while [ "$(printf '%s' "$padded" | tr -cd . | wc -c)" -lt 2 ]; do
padded="$padded.0"
done
if [ "$padded" != "$version" ]; then
echo "::error::Release tag $TAG does not match version $version in Cargo.toml."
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"

# Each wheel is built on a runner of its architecture, so the smoke test can run it.
linux:
needs: version
strategy:
fail-fast: false
matrix:
runner: [ubuntu-latest, ubuntu-24.04-arm]
compatibility: [manylinux_2_17, musllinux_1_2]
include:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-24.04-arm
target: aarch64
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: ${{ matrix.compatibility }}
args: --release --out dist
- if: startsWith(matrix.compatibility, 'manylinux')
uses: astral-sh/setup-uv@v6
# `mogs --version` imports only `mogs` and `packaging`, so no other dependency is needed.
- if: startsWith(matrix.compatibility, 'manylinux')
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
uv venv --python 3.13 smoke
uv pip install --python smoke --no-deps dist/*.whl packaging
test "$(smoke/bin/mogs --version)" = "mogs $VERSION"
- if: startsWith(matrix.compatibility, 'musllinux')
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
docker run --rm -v "$PWD/dist:/dist" -e VERSION python:3.13-alpine sh -euc '
pip install --quiet --root-user-action=ignore --no-deps /dist/*.whl packaging
test "$(mogs --version)" = "mogs $VERSION"
'
- uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}-${{ matrix.compatibility }}
path: dist

# Both wheels are built on an arm64 runner. Only the arm64 one runs there.
macos:
needs: version
strategy:
fail-fast: false
matrix:
target: [aarch64, x86_64]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist
- if: matrix.target == 'aarch64'
uses: astral-sh/setup-uv@v6
- if: matrix.target == 'aarch64'
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
uv venv --python 3.13 smoke
uv pip install --python smoke --no-deps dist/*.whl packaging
test "$(smoke/bin/mogs --version)" = "mogs $VERSION"
- uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.target }}
path: dist

windows:
needs: version
strategy:
fail-fast: false
matrix:
include:
- runner: windows-latest
target: x64
- runner: windows-11-arm
target: aarch64
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist
- uses: astral-sh/setup-uv@v6
- shell: bash
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
uv venv --python 3.13 smoke
uv pip install --python smoke --no-deps dist/*.whl packaging
test "$(smoke/Scripts/mogs.exe --version | tr -d '\r')" = "mogs $VERSION"
- uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.target }}
path: dist

sdist:
needs: version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

# Trusted publishing: PyPI trusts this workflow in the `pypi` environment. No token.
publish:
needs: [linux, macos, windows, sdist]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: wheels-*
merge-multiple: true
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__/
.ruff_cache/
dist/
__marimo__/
target/
29 changes: 23 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,59 @@ and a Gradescope autograder zip. Alpha: the API changes without deprecation.
- Design, plans and progress notes live outside this repo, in the author's
private planning directory. Never put design notes, plans or local paths in
the repo.
- `src/mogs/`: the package, imported, published on PyPI and run as `mogs`.
- `src/mogs/`: the Python package, imported and published on PyPI.
`config.py` reads the config from the notebook's `mogs.assignment(...)` and
`mogs.grade(...)` calls (statically, from the AST) and edits the PEP 723
header as text. `scaffold.py` is `mogs init`.
- `src/mogs/_typst/`: the Typst packages cmarker and mitex,
vendored for the PDF of written answers (`pdf.py`). They need the Typst
version the `pdf` extra pins (`typst>=0.15,<0.16`): bump the pin and the
vendored versions together.
- `tests/`: pytest suite.
- `crates/mogs/`: the `mogs` executable, in Rust. It runs
`python -P -m mogs.cli` with the interpreter in its own folder, found after
resolving symlinks. On Windows it then tries the folder above `Scripts`,
where a global `pip install` puts `python.exe`. Last comes
`$(uv tool dir)/mogs`, because uv copies tool executables on Windows.
maturin builds it into platform wheels together with
`src/mogs/`. The version is `[workspace.package] version` in `Cargo.toml`.
`src/mogs/_binary.py` finds and runs the installed executable.
- `tests/`: pytest suite. `cargo test` runs the Rust tests.
- `tests/e2e/`: end-to-end tests. The `docker` ones build the demo autograder
into Gradescope's base image (`tests/e2e/Dockerfile`) and grade submissions
through the real `/autograder/run_autograder`. They need docker or podman
(`MOGS_CONTAINER=docker|podman` picks one) and network, and take several
minutes. Without a runtime they skip; `MOGS_REQUIRE_CONTAINER=1` (set in CI)
minutes. The wheel for the image comes from `maturin build --zig` for
manylinux_2_17 x86_64, so it builds on any host. Without a runtime they skip; `MOGS_REQUIRE_CONTAINER=1` (set in CI)
makes that a failure. The base image is amd64 only: on an arm64 host it runs
under emulation, which is slow enough that grading timeouts may trip.
- `.github/workflows/release.yml`: on a published GitHub release (tags like
`0.7`, no `v`), checks the tag against the `Cargo.toml` version, builds the
wheels and the sdist, smoke-tests each wheel on a runner that can run it,
then publishes them all to PyPI through
trusted publishing.
- `docs/`: the docs site (Astro Starlight, built with Bun), deployed to
https://mogs.kristia.de by `.github/workflows/docs.yml`. Pages
are `docs/src/content/docs/` (`index.md`, `instructors.md`,
`students.md`). The README stays short and links there.

## Commands

Always go through `uv` (never global Python).
Always go through `uv` (never global Python). The Rust toolchain is
`rust-toolchain.toml` (stable, with clippy and rustfmt). `uv sync` and
`uv run` rebuild the executable when `Cargo.toml`, `Cargo.lock` or a `.rs`
file changes.

```bash
make sync # uv sync
make check # ruff check + format check, ty, pytest (the CI gate)
make check # ruff, cargo fmt + clippy, ty, cargo test, pytest (the CI gate)
make docs # build the docs site into docs/dist (needs Bun)
make docs-serve # live preview at localhost:4321
make test TESTS=tests/test_config.py ARGS="-k header"
make test ARGS="-m slow" # only the slow tests (marimo via `uv run --with`; included by default)
make test ARGS="-m network" # only the tests that resolve packages through uv (included by default)
make test ARGS="-m 'not slow and not network'" # offline
make test ARGS="-m docker" # only the Docker end-to-end tests: deselected unless `-m` names `docker`
make fix # ruff fixes, then format
make fix # ruff fixes, then ruff format and cargo fmt
```

## Rules
Expand Down
Loading
Loading