Skip to content

Commit

Permalink
add black lint workflow (#178)
Browse files Browse the repository at this point in the history
* add black lint workflow

* black .

* add pre-commit for black/flake8

* configure black and flake8

* add make fmt and clean up makefile

* use basic flake8 config from black docs

fix unused imports
ignore unused import in manage.py as its used to trigger an ImportError

* add isort to pre-commit

* run isort on all .py files

* sort requirements-test.txt

* add isort github action

* master -> main branch refs
  • Loading branch information
mwarkentin committed Dec 23, 2021
1 parent f65fd84 commit e747401
Show file tree
Hide file tree
Showing 27 changed files with 609 additions and 490 deletions.
4 changes: 4 additions & 0 deletions .flake8
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 88
select = C,E,F,W,B,B950
extend-ignore = E203, E501
10 changes: 10 additions & 0 deletions .github/workflows/black.yml
@@ -0,0 +1,10 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
13 changes: 13 additions & 0 deletions .github/workflows/isort.yml
@@ -0,0 +1,13 @@
name: Run isort
on:
- push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
- uses: jamescurtin/isort-action@master
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Expand Up @@ -5,9 +5,9 @@ name: Python package

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
build:
Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/ambv/black
rev: 21.12b0
hooks:
- id: black
language_version: python3.9
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
37 changes: 16 additions & 21 deletions Makefile
@@ -1,53 +1,48 @@
.PHONY: help clean clean-build clean-pyc lint test docs release dist run
.PHONY: help clean clean-build clean-pyc lint fmt test docs release dist run

help:
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "lint - check PEP8 style with flake8, and rst with rst-lint"
@echo "test - run tests quickly with the default Python"
@echo "coverage - check code coverage quickly with the default Python"
@echo "docs - generate Sphinx HTML documentation, including API docs"
@echo "release - package and upload a release"
@echo "dist - package a release"
@echo "run - build and run sample project with docker"

clean: clean-build clean-pyc

clean-build:
@grep -E -h '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

clean: clean-build clean-pyc ## Clean all

clean-build: ## Clean build artifacts
rm -fr build/
rm -fr dist/
rm -fr *.egg-info

clean-pyc:
clean-pyc: ## Clean compiled python files
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +

lint:
lint: ## Check PEP8 style with flake8, and rst with rst-lint
flake8 watchman tests --ignore=E501
rst-lint *.rst

test:
fmt: ## Format python code with black
black .

test: ## Run tests using GHA workflows with act
act --job build

docs:
docs: ## Generate Sphinx HTML documentation, including API docs
rm -f docs/watchman.rst
rm -f docs/modules.rst
sphinx-apidoc -o docs/ watchman
$(MAKE) -C docs clean
$(MAKE) -C docs html
open docs/_build/html/index.html

release: clean lint test
release: clean lint test ## Package and upload a release
python setup.py sdist
python setup.py bdist_wheel
twine upload dist/*

dist: clean lint test
dist: clean lint test ## Package a release
python setup.py sdist
python setup.py bdist_wheel
ls -l dist

run:
run: ## Build and run sample project with docker
docker build -t watchman .
docker run -it -p 8000:8000 watchman
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -6,7 +6,7 @@ django-watchman
:target: http://badge.fury.io/py/django-watchman

.. image:: http://img.shields.io/coveralls/mwarkentin/django-watchman.svg
:target: https://coveralls.io/r/mwarkentin/django-watchman?branch=master
:target: https://coveralls.io/r/mwarkentin/django-watchman?branch=main

django-watchman exposes a status endpoint for your backing services like
databases, caches, etc.
Expand Down

0 comments on commit e747401

Please sign in to comment.