File tree Expand file tree Collapse file tree 4 files changed +83
-0
lines changed
Expand file tree Collapse file tree 4 files changed +83
-0
lines changed Original file line number Diff line number Diff line change 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+ PYTHON : " 3.12"
17+
18+ steps :
19+ - name : Checkout repo
20+ uses : actions/checkout@v4
21+
22+ - name : Setup Python
23+ uses : actions/setup-python@v5
24+ with :
25+ python-version : ${{ env.PYTHON }}
26+
27+ - name : Install required packages
28+ run : pip install ruff nbqa
29+
30+ - name : Check style of notebooks
31+ run : make check
Original file line number Diff line number Diff line change 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} "
27+
28+ format :
29+ nbqa ruff --fix " ${NOTEBOOKS_DIR} "
Original file line number Diff line number Diff line change @@ -113,6 +113,26 @@ jupyter nbconvert --to notebook --execute --inplace notebooks/**/*.ipynb
113113[ mystmd.org ] : https://mystmd.org
114114
115115
116+ ## Check style of notebooks
117+
118+ We can check the code style of our notebooks using [ ` ruff ` ] [ ruff ] and
119+ [ ` nbqa ` ] [ nbqa ] . Simply run the following command to check the style of the
120+ notebooks:
121+
122+ ``` bash
123+ nbqa ruff notebooks
124+ ```
125+
126+ And run this to autoformat them:
127+
128+ ``` bash
129+ nbqa ruff --fix notebooks
130+ ```
131+
132+ Alternatively, you can use the targets we have in the ` Makefile ` , like `make
133+ check` and ` make format`. Read more information about the available targets
134+ by running ` make help ` .
135+
116136## License
117137
118138All text and figures are licensed under a
Original file line number Diff line number Diff line change @@ -13,3 +13,6 @@ dependencies:
1313 - simpeg==0.22.*
1414 - discretize==0.10.*
1515 - pymatsolver
16+ # Code quality
17+ - nbqa
18+ - ruff
You can’t perform that action at this time.
0 commit comments