Adding pre-commit hooks

master
Drew Bednar 2 years ago
parent d9d7b14b80
commit 79657b585c

1
.gitignore vendored

@ -138,4 +138,3 @@ dmypy.json
# Cython debug symbols
cython_debug/

@ -0,0 +1,27 @@
default_stages: [commit, push]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
# https://pylint.pycqa.org/en/latest/user_guide/installation/pre-commit-integration.html
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args: [
'-rn', # Only display messages
'-sn', # Don't display the score
'--disable=C,R,W0511', # Disable C and R type messages, and TODO fixme warning
]
# TODO add https://pre-commit.com/#docker hook for bash linting

@ -11,3 +11,51 @@ Since Dramatiq supports Redis and RabbitMQ as queue backends, there are two sepa
All invoke tasks reside in the `tasks.py` file at the root of the project. Use `invoke --list` or `inv -l` to print out a list of available commands. Use `inv <cmd> --help` for additional details.
A bash complete wrapper script `autocomplete.zsh` was generated with `invoke --print-completion-script zsh > autocomplete.zsh`. Simply source this file to enable autocomplete for invoke. Use `bash` instead of `zsh` to generate a bash autocomplete wrapper.
## Pre-commit Hooks
A `.pre-commit-config.yaml` for [pre-commit](https://pre-commit.com/) is available for this project. To install the pre-commit hooks run:
```
pre-commit install
```
In the event new hooks are addedd it may be beneficial to run all hooks against all files:
```
pre-commit run --all-files
```
You can run individual pre-commit hooks like:
```
pre-commit run pylint
```
This will use the args present in hook, which in our case ignores C,R, and TODO fixme commands.
To remove the pre-commit hooks all together
```
rm .git/hooks/pre-commit
```
## Pylint
To disable a rule
```
# pylint: disable=unused-import
import not_used
# pylint: disable=enable-import
```
or
```
bad_code # pylint: disable=W1337
```
You can also suppress the entire rule by adding a pragma disable at the top of the file
# pragma pylint: disable=W9902

@ -0,0 +1 @@
import dramatiq

@ -31,4 +31,3 @@ _complete_invoke() {
compctl -K _complete_invoke + -f invoke inv
# vim: set ft=sh :

@ -2,3 +2,5 @@ black
flake8
invoke
pip-tools
pre-commit
pylint

@ -4,22 +4,42 @@
#
# pip-compile dev_requirements.in
#
astroid==2.12.9
# via pylint
black==22.8.0
# via -r dev_requirements.in
build==0.8.0
# via pip-tools
cfgv==3.3.1
# via pre-commit
click==8.1.3
# via
# black
# pip-tools
dill==0.3.5.1
# via pylint
distlib==0.3.6
# via virtualenv
filelock==3.8.0
# via virtualenv
flake8==5.0.4
# via -r dev_requirements.in
identify==2.5.5
# via pre-commit
invoke==1.7.1
# via -r dev_requirements.in
isort==5.10.1
# via pylint
lazy-object-proxy==1.7.1
# via astroid
mccabe==0.7.0
# via flake8
# via
# flake8
# pylint
mypy-extensions==0.4.3
# via black
nodeenv==1.7.0
# via pre-commit
packaging==21.3
# via build
pathspec==0.10.1
@ -29,22 +49,43 @@ pep517==0.13.0
pip-tools==6.8.0
# via -r dev_requirements.in
platformdirs==2.5.2
# via black
# via
# black
# pylint
# virtualenv
pre-commit==2.20.0
# via -r dev_requirements.in
pycodestyle==2.9.1
# via flake8
pyflakes==2.5.0
# via flake8
pylint==2.15.2
# via -r dev_requirements.in
pyparsing==3.0.9
# via packaging
pyyaml==6.0
# via pre-commit
toml==0.10.2
# via pre-commit
tomli==2.0.1
# via
# black
# build
# pep517
# pylint
tomlkit==0.11.4
# via pylint
typing-extensions==4.3.0
# via black
# via
# astroid
# black
# pylint
virtualenv==20.16.5
# via pre-commit
wheel==0.37.1
# via pip-tools
wrapt==1.14.1
# via astroid
# The following packages are considered to be unsafe in a requirements file:
# pip

@ -7,4 +7,3 @@ services:
restart: always
ports:
- 6379:6379

@ -3,18 +3,21 @@ A set of `invoke` helper commands used for this project.
"""
from invoke import task
@task
def start_app(c, docs=False, extra=''):
def start_app(docs=False, extra=""):
"""Starts the app."""
print("Start the app")
if docs:
print(f"Building docs. Docs value: {extra}")
@task
def non_sense(c):
def non_sense():
"""A non-sense command."""
print("This is non-sense")
@task
def start_rabbit(c):
"""Runs the RabbitMQ integration environment."""
@ -22,22 +25,26 @@ def start_rabbit(c):
start_app(c)
c.run("docker compose -f docker-compose-rabbit.yml up -d")
@task
def stop_rabbit(c):
"""Stops the RabbitMQ integration environent."""
print("Stopping RabbitMQ")
c.run("docker compose -f docker-compose-rabbit.yml down")
@task
def start_redis(c):
"""Runs the Redis integration environment."""
print("Starting Redis")
c.run("docker compose -f docker-compose-redis.yml up -d")
@task
def stop_redis(c):
"""Stops the Redis integration environent."""
print("Stopping Redis")
c.run("docker compose -f docker-compose-redis.yml down")
# TODO add docker build, tag, and push command for app

Loading…
Cancel
Save