diff --git a/.gitignore b/.gitignore index 53e0254..147b9e9 100644 --- a/.gitignore +++ b/.gitignore @@ -138,4 +138,3 @@ dmypy.json # Cython debug symbols cython_debug/ - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8d02c83 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 14ca0e9..0533a63 100644 --- a/README.md +++ b/README.md @@ -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 --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 diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..5e96ca1 --- /dev/null +++ b/app/__init__.py @@ -0,0 +1 @@ +import dramatiq diff --git a/autocomplete.zsh b/autocomplete.zsh index c038a92..73b56e8 100644 --- a/autocomplete.zsh +++ b/autocomplete.zsh @@ -31,4 +31,3 @@ _complete_invoke() { compctl -K _complete_invoke + -f invoke inv # vim: set ft=sh : - diff --git a/dev_requirements.in b/dev_requirements.in index 615c294..5ac72d3 100644 --- a/dev_requirements.in +++ b/dev_requirements.in @@ -2,3 +2,5 @@ black flake8 invoke pip-tools +pre-commit +pylint diff --git a/dev_requirements.txt b/dev_requirements.txt index 601f4a7..13dc905 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -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 diff --git a/docker-compose-rabbit.yml b/docker-compose-rabbit.yml index 7605073..3677d45 100644 --- a/docker-compose-rabbit.yml +++ b/docker-compose-rabbit.yml @@ -42,4 +42,4 @@ services: test: [ "CMD", "nc", "-z", "localhost", "5672" ] interval: 5s timeout: 15s - retries: 1 \ No newline at end of file + retries: 1 diff --git a/docker-compose-redis.yml b/docker-compose-redis.yml index 05d40f5..5fd2d0e 100644 --- a/docker-compose-redis.yml +++ b/docker-compose-redis.yml @@ -7,4 +7,3 @@ services: restart: always ports: - 6379:6379 - diff --git a/requirements.in b/requirements.in index 6b5d58e..2dec9c0 100644 --- a/requirements.in +++ b/requirements.in @@ -1 +1 @@ -dramatiq[all] \ No newline at end of file +dramatiq[all] diff --git a/tasks.py b/tasks.py index 2e0f08c..0e66859 100644 --- a/tasks.py +++ b/tasks.py @@ -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