✅: (based)pyright #154
Workflow file for this run
This file contains hidden or 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
name: CI | |
permissions: read-all | |
on: | |
workflow_dispatch: | |
pull_request: | |
push: | |
branches: [main] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
UV_LOCKED: 1 | |
# Many color libraries just need this to be set to any value, but at least | |
# one distinguishes color depth, where "3" -> "256-bit color". | |
FORCE_COLOR: 3 | |
jobs: | |
lint: | |
name: lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
- name: dprint | |
uses: dprint/check@9cb3a2b17a8e606d37aae341e49df3654933fc23 # v2.3 | |
- name: Install uv | |
uses: astral-sh/setup-uv@d9e0f98d3fc6adb07d1e3d37f3043649ddad06a1 # v6.5.0 | |
- name: ruff | |
run: | | |
uv run ruff check --output-format=github | |
uv run ruff format --check | |
# TODO: Fail if lefthook changes any files: | |
# https://github.com/data-apis/array-api-typing/pull/35/files#r2179941334 | |
- name: lefthook | |
run: uv run lefthook run pre-commit | |
- name: mypy | |
run: uv run mypy --tb --no-incremental --cache-dir=/dev/null src | |
# TODO: (based)pyright | |
test_runtime: | |
name: runtime tests | |
runs-on: ${{ matrix.runs-on }} | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.11", "3.12", "3.13"] | |
runs-on: [ubuntu-latest, macos-latest, windows-latest] | |
steps: | |
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
- name: Install uv | |
uses: astral-sh/setup-uv@d9e0f98d3fc6adb07d1e3d37f3043649ddad06a1 # v6.5.0 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Test package | |
run: >- | |
uv run --group=test_runtime | |
pytest --cov --cov-report=xml --cov-report=term --durations=20 | |
- name: Upload coverage report | |
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
test_integration_numpy: | |
name: integration tests (numpy) | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
numpy-version: ["1.25.0", "1.26.4", "2.0.2", "2.1.3", "2.2.6", "2.3.1"] | |
steps: | |
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
- uses: astral-sh/setup-uv@d9e0f98d3fc6adb07d1e3d37f3043649ddad06a1 # v6.5.0 | |
with: | |
python-version: "3.11" | |
activate-environment: true | |
- name: get major.minor numpy version | |
id: numpy-version | |
run: | | |
version="${{ matrix.numpy-version }}" | |
major=$(echo "$version" | cut -d. -f1) | |
minor=$(echo "$version" | cut -d. -f2) | |
echo "major=$major" >> $GITHUB_OUTPUT | |
echo "minor=$minor" >> $GITHUB_OUTPUT | |
- name: collect test files | |
id: collect-files | |
run: | | |
major="${{ steps.numpy-version.outputs.major }}" | |
minor="${{ steps.numpy-version.outputs.minor }}" | |
prefix="tests/integration" | |
files="" | |
while IFS= read -r -d '' path; do | |
fname=$(basename "$path") | |
fminor=$(echo "$fname" | sed -E "s/test_numpy${major}p([0-9]+)\.pyi/\1/") | |
if [ "$fminor" -le "$minor" ]; then | |
files="$files $path" | |
fi | |
done < <(find "$prefix" -name "test_numpy${major}p*.pyi" -print0) | |
files="${files# }" | |
echo "files=$files" >> "$GITHUB_OUTPUT" | |
# NOTE: `uv run --with=...` will be ignored by mypy (and `--isolated` does not help) | |
- name: mypy | |
run: | | |
uv sync --no-editable --group=mypy | |
uv pip install numpy==${{ matrix.numpy-version }} | |
uv run --no-sync --active \ | |
mypy --tb --no-incremental --cache-dir=/dev/null \ | |
${{ steps.collect-files.outputs.files }} | |
- name: basedmypy | |
run: | | |
uv sync --no-editable --group=basedmypy | |
uv pip install numpy==${{ matrix.numpy-version }} | |
uv run --no-sync --active \ | |
mypy --tb --no-incremental --cache-dir=/dev/null \ | |
${{ steps.collect-files.outputs.files }} | |
- name: pyright | |
run: | | |
uv sync --no-editable --group=pyright | |
uv pip install numpy==${{ matrix.numpy-version }} | |
uv run --no-sync --active \ | |
pyright ${{ steps.collect-files.outputs.files }} | |
- name: basedpyright | |
run: | | |
uv sync --no-editable --group=basedpyright | |
uv pip install numpy==${{ matrix.numpy-version }} | |
# Copy test files to a temporary directory | |
tmpdir=$(mktemp -d) | |
cp -r tests/integration "$tmpdir/" | |
# Swap mypy-specific ignores to basedpyright-compatible ones | |
find "$tmpdir/integration" -name "*.pyi" -exec sed -i \ | |
-e 's/# type: ignore\[assignment\]/# type: ignore[reportAssignmentType]/g' {} + | |
# Run basedpyright on the temporary copy | |
uv run --no-sync --active \ | |
basedpyright "$tmpdir/integration" | |
# Clean up | |
rm -rf "$tmpdir" | |
# TODO: integration tests for array-api-strict | |
# TODO: integration tests for 3rd party libs such as cupy, pytorch, tensorflow, dask, etc. |