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
36 changes: 36 additions & 0 deletions .github/workflows/mypy_notebooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
FAILED=0

while IFS= read -r nb; do
[[ -z "$nb" || ! -f "$nb" ]] && continue
if git check-ignore -q "$nb"; then
echo -e "\033[90m=== Skipped $nb (gitignore) ===\033[0m"
continue
fi


NB_DIR=$(dirname "$nb")
NB_BASE=$(basename "$nb" .ipynb)
PY_FILE="${NB_DIR}/_${NB_BASE}.py"

echo "=== Checking $nb -> $PY_FILE ==="

# Convert to _ prefixed filename (simple!)
uv run jupyter nbconvert --to python "$nb" \
--output "_${NB_BASE}" \
--log-level ERROR

if ! uv run mypy "$PY_FILE" --config-file pyproject.toml; then
((FAILED++))
fi

rm -f "$PY_FILE"
done < <(find . -name "*.ipynb")

if [ $FAILED -eq 0 ]; then
echo "🎉 All notebooks passed mypy!"
exit 0
else
echo "❌ $FAILED notebooks failed mypy!"
exit 1
fi
30 changes: 28 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: Get changed files
outputs:
any_python_changed: ${{ steps.raw-changed-python-files.outputs.any_changed }}
changed_python_files: ${{ steps.changed-python-files.outputs.all_changed_files }}
all_changed_files: ${{ steps.changed-python-files.outputs.all_changed_files }}
steps:
- uses: actions/checkout@v4
- name: Get changed python files
Expand All @@ -22,6 +22,10 @@ jobs:
with:
files: |
**.py
**.ipynb
pyproject.toml
uv.lock

- name: Check changed python files
id: changed-python-files
env:
Expand All @@ -44,6 +48,7 @@ jobs:
- name: Check style with Ruff
run: |
uv run ruff check --output-format=github .

format:
name: Check format with Ruff
runs-on: [self-hosted, linux]
Expand All @@ -59,8 +64,10 @@ jobs:
- name: Check format with Ruff
run: |
uv run ruff format --check --diff .
check-notebooks:

verify-nbstripout:
runs-on: [self-hosted, linux]
if: needs.changed-files.outputs.any_python_changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v6
Expand Down Expand Up @@ -107,6 +114,24 @@ jobs:
- name: Check type hints with mypy
run: |
uv run mypy --show-error-codes --check-untyped-defs --config-file ./pyproject.toml ./

mypy-notebooks:
name: Check notebook type hints with mypy
runs-on: [self-hosted, linux]
needs: changed-files
if: needs.changed-files.outputs.any_python_changed == 'true'
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install dependencies
run: |
uv sync --all-extras
uv pip install jupyter
- name: Check notebook type hints with mypy
run: |
./.github/workflows/mypy_notebooks.sh

test:
name: Run tests
runs-on: [self-hosted, linux]
Expand Down Expand Up @@ -140,6 +165,7 @@ jobs:
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

docs:
name: Build Sphinx docs
runs-on: [self-hosted, linux]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dev = [
{ include-group = "typed" },
"pre-commit>=4.5.1",
]
lint = ["ruff>=0.14.11", "nbstripout>=0.9.1"]
lint = ["ruff>=0.14.11", "nbstripout>=0.9.1", "nbconvert"]
test = [
"beets>=2.5.1",
"pytest>=9.0.2",
Expand Down
103 changes: 103 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading