Skip to content

Commit d5a871c

Browse files
authored
Merge pull request #27 from blowekamp/add_precommit_black
Add pre-commit configuration with black and run in GHA as listing
2 parents f190534 + 17d0543 commit d5a871c

File tree

6 files changed

+221
-107
lines changed

6 files changed

+221
-107
lines changed

.github/workflows/python-app.yml

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,31 @@ on:
1010
branches: [ main ]
1111

1212
jobs:
13-
build:
13+
14+
linting_test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
- name: Set up Python 3.11
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: 3.11
24+
- name: set PY
25+
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
26+
- uses: actions/cache@v3
27+
with:
28+
path: ~/.cache/pre-commit
29+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
30+
- name: Linting
31+
run: |
32+
pip install pre-commit
33+
pre-commit run --all-files
34+
35+
36+
test_package:
37+
needs: linting_test
1438

1539
runs-on: ubuntu-latest
1640

@@ -20,18 +44,11 @@ jobs:
2044
uses: actions/setup-python@v4
2145
with:
2246
python-version: 3.9
47+
cache: 'pip'
2348
- name: Install dependencies
2449
run: |
2550
python -m pip install --upgrade pip
26-
pip install flake8
27-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
2851
pip install -e .
29-
- name: Lint with flake8
30-
run: |
31-
# stop the build if there are Python syntax errors or undefined names
32-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33-
# exit-zero treats all errors as warnings.
34-
flake8 . --count --exit-zero --max-complexity=10 --statistics
3552
- name: Run tests
3653
run: |
3754
python -m unittest discover -s tests

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# .pre-commit-config.yaml
2+
# for details see https://pre-commit.com
3+
# for list of available hooks see https://pre-commit.com/hooks.html
4+
5+
fail_fast: true
6+
7+
repos:
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.4.0
10+
hooks:
11+
- id: check-added-large-files
12+
args: ['--maxkb=200']
13+
- repo: https://github.com/psf/black
14+
rev: 23.3.0
15+
hooks:
16+
- id: black
17+
args: ['--check', '--diff']
18+
- repo: https://github.com/pycqa/flake8
19+
rev: 6.0.0
20+
hooks:
21+
- id: flake8
22+
entry: pflake8
23+
additional_dependencies: [pyproject-flake8]

0 commit comments

Comments
 (0)