Skip to content

Commit fa4e71e

Browse files
authored
Apply linting to entire codebase & add CI workflow to check linting (#167)
* Add pre-commit PR workflow for changed files Add a GitHub Actions workflow that runs pre-commit checks only on files changed in a pull request. The workflow triggers on PR opened/synchronize/reopened, fetches full git history to detect changed files against the base branch, and exposes that list as an output. A conditional precommit job runs only when changes exist: it checks out the PR branch, sets up Python 3.12, installs pre-commit, and executes pre-commit in CI check-only mode on the changed files (--hook-stage manual --show-diff-on-failure). * Run pre-commit on all
1 parent 8a72588 commit fa4e71e

File tree

8 files changed

+70
-7
lines changed

8 files changed

+70
-7
lines changed

.github/workflows/format.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: pre-commit (PR only on changed files)
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
detect_changes:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
changed: ${{ steps.changed_files.outputs.changed }}
12+
13+
steps:
14+
- name: Checkout full history
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Detect changed files
20+
id: changed_files
21+
run: |
22+
git fetch origin ${{ github.base_ref }}
23+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
24+
25+
{
26+
echo "changed<<EOF"
27+
echo "$CHANGED_FILES"
28+
echo "EOF"
29+
} >> "$GITHUB_OUTPUT"
30+
31+
- name: Show changed files
32+
run: |
33+
echo "Changed files:"
34+
echo "${{ steps.changed_files.outputs.changed }}"
35+
36+
precommit:
37+
needs: detect_changes
38+
runs-on: ubuntu-latest
39+
if: ${{ needs.detect_changes.outputs.changed != '' }}
40+
41+
steps:
42+
- name: Checkout PR branch
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
ref: ${{ github.head_ref }}
47+
48+
- name: Set up Python
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: "3.12"
52+
53+
- name: Install pre-commit
54+
run: pip install pre-commit
55+
56+
- name: Run pre-commit (CI check-only stage) on changed files
57+
env:
58+
CHANGED_FILES: ${{ needs.detect_changes.outputs.changed }}
59+
run: |
60+
mapfile -t files <<< "$CHANGED_FILES"
61+
pre-commit run --hook-stage manual --files "${files[@]}" --show-diff-on-failure

src/napari_deeplabcut/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
# FIXME: Circumvent the need to access window.qt_viewer
4141
warnings.filterwarnings("ignore", category=FutureWarning)
4242

43-
import re
43+
import re # noqa: E402
44+
4445
# Suppress RuntimeWarnings caused by NaN values in dataframe
4546
# (encountered during model-predicted labels refinement stage)
4647
warnings.filterwarnings(
@@ -49,6 +50,7 @@
4950
message=re.escape("invalid value encountered in cast"),
5051
)
5152

53+
5254
class VispyWarningFilter(logging.Filter):
5355
def filter(self, record: logging.LogRecord) -> bool:
5456
ignore_messages = (

src/napari_deeplabcut/_tests/test_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def test_lazy_imread_grayscale_and_rgba(tmp_path):
374374
gray = (np.random.rand(10, 10) * 255).astype(np.uint8)
375375
rgba = (np.random.rand(10, 10, 4) * 255).astype(np.uint8)
376376
p1, p2 = tmp_path / "g.png", tmp_path / "r.png"
377-
cv2.imwrite(str(p1), gray) # cv2 writes grayscale as-is; color images are written as BGR
377+
cv2.imwrite(str(p1), gray) # cv2 writes grayscale as-is; color images are written as BGR
378378
cv2.imwrite(str(p2), cv2.cvtColor(rgba, cv2.COLOR_RGBA2BGRA))
379379
res = _reader._lazy_imread([p1, p2], use_dask=False, stack=False)
380380
assert all(img.shape[-1] == 3 for img in res)

src/napari_deeplabcut/assets/napari_shortcuts.svg

Lines changed: 1 addition & 1 deletion
Loading

src/napari_deeplabcut/assets/superanimal_quadruped.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@
155155
707.5655627887081,
156156
375.0788206592507
157157
]
158-
}
158+
}

src/napari_deeplabcut/assets/superanimal_topviewmouse.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,4 @@
107107
117.41024099594408,
108108
252.35239163633167
109109
]
110-
}
110+
}

src/napari_deeplabcut/styles/dark.mplstyle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ axes.labelcolor : f0f1f2
99
axes.facecolor : none
1010
axes.edgecolor : 414851
1111
xtick.color : f0f1f2
12-
ytick.color : f0f1f2
12+
ytick.color : f0f1f2

src/napari_deeplabcut/styles/light.mplstyle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ axes.labelcolor : 3b3a39
99
axes.facecolor : none
1010
axes.edgecolor : d6d0ce
1111
xtick.color : 3b3a39
12-
ytick.color : 3b3a39
12+
ytick.color : 3b3a39

0 commit comments

Comments
 (0)