Skip to content

Commit a22fb19

Browse files
committed
Removing auto-running of pre-commit, move tests to Makefile
This commit changes the harness running ruff and nbstripout from pre-commit to a Makefile. Developers can run `make format-python` to run `ruff format` and format python files. Developers can also run `make format-notebooks` to run `nbstripout` and format notebooks. `make format-{notebook,python}-check` checks that files have been appropriately formatted. These checks are run as workflows when python or notebooks files are changed. Signed-off-by: Ali Maredia <[email protected]>
1 parent 1fdc247 commit a22fb19

File tree

5 files changed

+40
-43
lines changed

5 files changed

+40
-43
lines changed

.github/workflows/validate-and-execute-notebooks.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Smoke Tests for Notebooks
1+
name: Validation & Smoke Tests for Notebooks
22

33
on:
44
pull_request:
@@ -105,9 +105,12 @@ jobs:
105105

106106
- name: Install Testing Tools
107107
run: |
108-
pip install papermill ipykernel
108+
pip install papermill ipykernel nbstripout
109109
ipython kernel install --name "python3" --user
110110
111+
- name: Run Formatting Tests
112+
run: make format-notebooks-check
113+
111114
- name: Execute Notebooks
112115
run: |
113116
set -ux
Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
name: Pre-commit checks
1+
name: Python Formatting Validation
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
types: [opened, synchronize, reopened]
67
paths:
78
- "**/*.py"
8-
- "**/*.ipynb"
99
- ".pre-commit-config.yaml"
10+
- "Makefile"
1011
- "pyproject.toml"
12+
- ".github/workflow/validate-python.yml"
1113
pull_request_target:
1214
types: [closed]
1315
paths:
1416
- "**/*.py"
15-
- "**/*.ipynb"
1617
- ".pre-commit-config.yaml"
18+
- "Makefile"
1719
- "pyproject.toml"
18-
19-
concurrency:
20-
group: pre-commit-${{ github.ref }}z
21-
cancel-in-progress: true
20+
- ".github/workflow/validate-python.yml"
2221

2322
jobs:
24-
pre-commit:
25-
if: github.event_name != 'pull_request_target' || github.event.pull_request.merged == true
23+
formatting-test:
2624
runs-on: ubuntu-latest
2725
permissions:
2826
contents: read
@@ -38,16 +36,8 @@ jobs:
3836
with:
3937
python-version: "3.12"
4038

41-
- name: Cache pre-commit envs
42-
uses: actions/cache@v4
43-
with:
44-
path: ~/.cache/pre-commit
45-
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
46-
47-
- name: Install pre-commit
48-
run: pip install pre-commit
39+
- name: Install python formatting test dependencies
40+
run: pip install ruff
4941

50-
- name: Run pre-commit
51-
uses: pre-commit/[email protected]
52-
with:
53-
extra_args: --all-files --show-diff-on-failure
42+
- name: Run Formatting Tests
43+
run: make format-python-check

.pre-commit-config.yaml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,9 @@ repos:
44
- repo: https://github.com/astral-sh/ruff-pre-commit
55
rev: v0.13.0
66
hooks:
7-
- id: ruff
8-
name: ruff-check
9-
args: [--fix, --show-fixes]
10-
types_or: [python]
117
- id: ruff-format
128
name: ruff-format
139
types_or: [python]
14-
15-
# Import ordering (aligned with Black)
16-
- repo: https://github.com/pycqa/isort
17-
rev: 6.0.1
18-
hooks:
19-
- id: isort
20-
types_or: [python]
21-
22-
# Canonical Python formatter
23-
- repo: https://github.com/psf/black
24-
rev: 24.8.0
25-
hooks:
26-
- id: black
27-
types_or: [python]
28-
2910
# Strip notebook outputs anywhere in repo
3011
- repo: https://github.com/kynan/nbstripout
3112
rev: 0.8.1
@@ -39,4 +20,4 @@ exclude: |
3920
^\.venv/|^venv/|
4021
^\.pytest_cache/|^\.mypy_cache/|
4122
^\.ipynb_checkpoints/
42-
)
23+
)

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.PHONY: format-python format-notebook format-python-check format-notebooks-check
2+
3+
USE_CASES := $(wildcard notebooks/use-cases/*.ipynb)
4+
TUTORIALS := $(wildcard notebooks/tutorials/*.ipynb)
5+
ALL_NOTEBOOKS := $(USE_CASES) $(TUTORIALS)
6+
7+
format-python:
8+
@echo "Running ruff format..."
9+
ruff format
10+
11+
format-notebooks:
12+
@echo "Running nbstripout..."
13+
nbstripout $(ALL_NOTEBOOKS)
14+
15+
format-notebooks-check: lint nbcleanup
16+
nbstripout --verify $(ALL_NOTEBOOKS)
17+
@echo "nbstripout check passed :)"
18+
19+
format-python-check: lint nbcleanup
20+
ruff format --check
21+
@echo "ruff format check passed :)"

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ruff
2+
nbstripout

0 commit comments

Comments
 (0)