-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub Action to run style checks on notebooks (#6)
Use `nbqa` to run `ruff` and `black` to check style format of notebooks. Add a `Makefile` with targets for checking and formatting the notebooks. Add a `.github/requirements-style.yml` file with dependencies to run the checks.
- Loading branch information
1 parent
7b30b6d
commit 30e66d2
Showing
4 changed files
with
94 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,3 @@ | ||
nbqa==1.7.1 | ||
ruff==0.1.13 | ||
black==23.12.1 |
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,65 @@ | ||
# Linting and style checks with GitHub Actions | ||
# | ||
# NOTE: Pin actions to a specific commit to avoid having the authentication | ||
# token stolen if the Action is compromised. See the comments and links here: | ||
# https://github.com/pypa/gh-action-pypi-publish/issues/27 | ||
# | ||
# Use nbQA to run linters and code formatters on notebooks | ||
# | ||
name: code-style | ||
|
||
# Only build PRs and the main branch. Pushes to branches will only be built | ||
# when a PR is opened. | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
############################################################################### | ||
jobs: | ||
ruff: | ||
name: ruff | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Install requirements | ||
run: pip install -r .github/requirements-style.txt | ||
|
||
- name: List installed packages | ||
run: pip freeze | ||
|
||
- name: Check code format | ||
run: make ruff | ||
|
||
black: | ||
name: black | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Install requirements | ||
run: pip install -r .github/requirements-style.txt | ||
|
||
- name: List installed packages | ||
run: pip freeze | ||
|
||
- name: Check code format | ||
run: make black |
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,22 @@ | ||
NOTEBOOKS_DIR=notebooks | ||
|
||
.PHONY: help black ruff check format | ||
|
||
help: | ||
@echo "Commands:" | ||
@echo "" | ||
@echo " check run code style and quality checks (black and ruff)" | ||
@echo " format run black and ruff to format notebooks" | ||
@echo "" | ||
|
||
check: ruff black | ||
|
||
ruff: | ||
nbqa ruff ${NOTEBOOKS_DIR}/*.ipynb | ||
|
||
black: | ||
nbqa black --check ${NOTEBOOKS_DIR}/*.ipynb | ||
|
||
format: | ||
nbqa black ${NOTEBOOKS_DIR}/*.ipynb | ||
nbqa ruff --fix ${NOTEBOOKS_DIR}/*.ipynb |
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,7 @@ dependencies: | |
- ipython | ||
- jupyter | ||
- jupyterlab | ||
# Linters | ||
- nbqa==1.7.1 | ||
- ruff==0.1.13 | ||
- black==23.12.1 |