Skip to content

Commit 98d2fa8

Browse files
committed
Use nbqa and ruff to check style of notebooks
Add nbqa to the `environment.yml` file. Add a Makefile to the repo to easily run regular tasks like building the website, running the notebooks, checking style and autoformatting the notebooks. Add a `check.yml` GitHub Action to check style of notebooks in PRs.
1 parent e23428e commit 98d2fa8

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

.github/workflows/check.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Check style
2+
3+
on:
4+
# Check style after every push to main
5+
push:
6+
branches:
7+
- main
8+
# Check style on every PR
9+
pull_request:
10+
11+
jobs:
12+
13+
style:
14+
runs-on: ubuntu-latest
15+
env:
16+
ENVIRONMENT_FILE: environment.yml
17+
ENVIRONMENT_NAME: simpeg-user-tutorials
18+
19+
steps:
20+
- name: Checkout repo
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Miniforge
24+
uses: conda-incubator/setup-miniconda@v3
25+
with:
26+
miniforge-version: Miniforge3
27+
environment-file: $ENVIRONMENT_FILE
28+
activate-environment: $ENVIRONMENT_NAME
29+
30+
- name: Check style of notebooks
31+
bash:
32+
make check

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
NOTEBOOKS_DIR=notebooks
2+
3+
.PHONY: build run clean check format
4+
5+
help:
6+
@echo "Commands:"
7+
@echo ""
8+
@echo " build build Myst website (without running notebooks)"
9+
@echo " clean clean output of Myst website"
10+
@echo " run run all notebooks"
11+
@echo " check lint notebooks with nbqa and ruff"
12+
@echo " format autoformat notebooks with nbqa and ruff"
13+
@echo ""
14+
15+
16+
build:
17+
msyt build --html
18+
19+
clean:
20+
msyt clean --all
21+
22+
run:
23+
jupyter nbconvert --to notebook --execute --inplace "${NOTEBOOKS_DIR}/**/*.ipynb"
24+
25+
check:
26+
nbqa ruff "${NOTEBOOKS_DIR}/**/*.ipynb"
27+
28+
format:
29+
nbqa ruff --fix "${NOTEBOOKS_DIR}/**/*.ipynb"

environment.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ dependencies:
1212
- simpeg==0.22.*
1313
- discretize==0.10.*
1414
- pymatsolver
15+
# Code quality
16+
- nbqa
17+
- ruff

0 commit comments

Comments
 (0)