-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use nbqa and ruff to check style of notebooks (#34)
Add `nbqa` and `ruff` 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.
- Loading branch information
1 parent
79cd2cc
commit 1af946d
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Check style | ||
|
||
on: | ||
# Check style after every push to main | ||
push: | ||
branches: | ||
- main | ||
# Check style on every PR | ||
pull_request: | ||
|
||
jobs: | ||
|
||
style: | ||
runs-on: ubuntu-latest | ||
env: | ||
PYTHON: "3.12" | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ env.PYTHON }} | ||
|
||
- name: Install required packages | ||
run: pip install ruff nbqa | ||
|
||
- name: Check style of notebooks | ||
run: make check |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
NOTEBOOKS_DIR=notebooks | ||
|
||
.PHONY: build run clean check format | ||
|
||
help: | ||
@echo "Commands:" | ||
@echo "" | ||
@echo " build build Myst website (without running notebooks)" | ||
@echo " clean clean output of Myst website" | ||
@echo " run run all notebooks" | ||
@echo " check lint notebooks with nbqa and ruff" | ||
@echo " format autoformat notebooks with nbqa and ruff" | ||
@echo "" | ||
|
||
|
||
build: | ||
msyt build --html | ||
|
||
clean: | ||
msyt clean --all | ||
|
||
run: | ||
jupyter nbconvert --to notebook --execute --inplace "${NOTEBOOKS_DIR}/**/*.ipynb" | ||
|
||
check: | ||
nbqa ruff "${NOTEBOOKS_DIR}" | ||
|
||
format: | ||
nbqa ruff --fix "${NOTEBOOKS_DIR}" |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ dependencies: | |
- simpeg==0.22.* | ||
- discretize==0.10.* | ||
- pymatsolver | ||
# Code quality | ||
- nbqa | ||
- ruff |