Skip to content

Commit da68227

Browse files
[CI] Adds autoflake, pytest, and basic format/lint/codec pre-commit hooks
1 parent ce50d09 commit da68227

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

.pre-commit-config.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,28 @@ repos:
33
rev: 26.1.0
44
hooks:
55
- id: black
6-
6+
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v6.0.0
9+
hooks:
10+
- id: end-of-file-fixer
11+
- id: trailing-whitespace
12+
- id: check-toml
13+
- id: check-yaml
14+
- id: fix-byte-order-marker
15+
16+
- repo: local
17+
hooks:
18+
- id: autoflake.bash
19+
name: autoflake
20+
entry: .pre-commit/autoflake_runner.bash
21+
language: script
22+
description: Run autoflake against source
23+
24+
- repo: local
25+
hooks:
26+
- id: pytest_runner
27+
name: pytest
28+
language: script
29+
description: Run pytest against source
30+
entry: .pre-commit/pytest_runner.bash

.pre-commit/autoflake_runner.bash

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /usr/bin/bash
2+
3+
set -euo pipefail
4+
5+
files=$(git diff --cached --name-only -z --diff-filter=ACM -- '*.py')
6+
7+
if [ -z "$files" ]; then
8+
exit 0
9+
fi
10+
11+
autoflake --check --remove-all-unused-imports --ignore-init-modules-imports --verbose

.pre-commit/pytest_runner.bash

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /usr/bin/bash
2+
3+
set -euo pipefail
4+
5+
REPO_ROOT=$(git rev-parse --show-toplevel)
6+
cd "$REPO_ROOT"
7+
8+
if [ ! command -v pytest > /dev/null ]; then
9+
echo "pytest could not be resolved"
10+
exit 1
11+
fi
12+
13+
if [ ! -d "tests" ]; then
14+
echo "No 'tests' directory found at TLD for pytest to run against"
15+
exit 1
16+
fi
17+
18+
files=$(git diff --cached --name-only -z --diff-filter=ACM -- '*.py')
19+
20+
if [ -z "$files" ]; then
21+
exit 0
22+
fi
23+
24+
pytest -vv --tb=short

0 commit comments

Comments
 (0)