Skip to content

Commit

Permalink
Use pre-commit for linting
Browse files Browse the repository at this point in the history
This change introduces pre-commit for managing linting config
and tool versions.
  • Loading branch information
abn committed Apr 7, 2020
1 parent 8ccad66 commit 74866ca
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 17 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Setup python
- uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
architecture: x64

- uses: actions/checkout@master

- name: Install dependencies
run: pip install -r requirements-dev.txt

- name: Run flake8
run: make flake8

- name: Run pylint
run: make pylint
- name: Run all pre-commit hooks
run: make lint

copyright:
runs-on: ubuntu-latest
Expand Down
50 changes: 50 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
files: \.py$
args:
- --config=.flake8

- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.27.0
hooks:
- id: yapf
files: \.py$
exclude: ^vendor/
args:
- --parallel
- --recursive
- --in-place

- repo: https://github.com/timothycrosley/isort
rev: 4.3.21
hooks:
- id: isort
files: \.py$
exclude: ^vendor/
args:
- --recursive

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: trailing-whitespace
exclude: ^vendor/|^tests/.*/fixtures/.*
- id: end-of-file-fixer
exclude: ^vendor/|^tests/.*/fixtures/.*
- id: debug-statements

# https://pre-commit.com/#repository-local-hooks
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
files: \.py$
exclude: ^vendor/
args:
- --rcfile=.pylintrc
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ kafka: start-kafka

.PHONY: pylint
pylint: $(GENERATED)
python3 -m pylint --rcfile .pylintrc $(ALL_PYTHON_DIRS)
pre-commit run pylint --all-files

.PHONY: flake8
flake8: $(GENERATED)
python3 -m flake8 --config .flake8 $(ALL_PYTHON_DIRS)
pre-commit run flake8 --all-files

.PHONY: copyright
copyright:
Expand All @@ -80,20 +80,25 @@ unittest: fetch-kafka $(GENERATED)
python3 -m pytest -s -vvv tests/

.PHONY: test
test: flake8 pylint reformat copyright unittest
test: lint copyright unittest

.PHONY: isort
isort:
time isort --recursive $(ALL_PYTHON_DIRS)
pre-commit run isort --all-files

.PHONY: yapf
yapf:
time yapf --parallel --recursive --in-place $(ALL_PYTHON_DIRS)
pre-commit run yapf --all-files

.PHONY: reformat
reformat: isort yapf
[ $(shell git diff --name-only | wc -l) -eq 0 ] || (echo "please reformat code and re-commit" && exit 1)

.PHONY: pre-commit
pre-commit: $(GENERATED)
pre-commit run --all-files

.PHONY: lint
lint: pre-commit

/usr/lib/rpm/check-buildroot /usr/bin/rpmbuild:
$(DNF_INSTALL) rpm-build
Expand Down
3 changes: 1 addition & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
avro-python3==1.9.2.1
kafka-python==2.0.1
aiohttp-socks==0.3.4
flake8==3.7.9
pylint==2.4.4
pytest==5.4.1
requests==2.23.0
yapf==0.27.0
pre-commit>=2.2.0

0 comments on commit 74866ca

Please sign in to comment.