From 4a194c6966dcc5157610a175b2fe30646121491b Mon Sep 17 00:00:00 2001 From: leollon Date: Tue, 29 Oct 2019 22:47:27 +0800 Subject: [PATCH] Add pre-commit for the generated project. (#2171) --- CONTRIBUTORS.rst | 2 ++ README.rst | 2 ++ docs/developing-locally.rst | 6 ++++++ .../.pre-commit-config.yaml | 19 +++++++++++++++++++ .../requirements/local.txt | 1 + 5 files changed, 30 insertions(+) create mode 100644 {{cookiecutter.project_slug}}/.pre-commit-config.yaml diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 90bb6395..5224de1f 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -137,6 +137,7 @@ Listed in alphabetical order. Keyvan Mosharraf `@keyvanm`_ Krzysztof Szumny `@noisy`_ Krzysztof Żuraw `@krzysztofzuraw`_ + Leo won `@leollon`_ Leo Zhou `@glasslion`_ Leonardo Jimenez `@xpostudio4`_ Lin Xianyi `@iynaix`_ @@ -291,6 +292,7 @@ Listed in alphabetical order. .. _@keyvanm: https://github.com/keyvanm .. _@knitatoms: https://github.com/knitatoms .. _@krzysztofzuraw: https://github.com/krzysztofzuraw +.. _@leollon: https://github.com/leollon .. _@MathijsHoogland: https://github.com/MathijsHoogland .. _@mapx: https://github.com/mapx .. _@mattayes: https://github.com/mattayes diff --git a/README.rst b/README.rst index e4f47351..4be3c4bc 100644 --- a/README.rst +++ b/README.rst @@ -53,6 +53,7 @@ Features * Instructions for deploying to PythonAnywhere_ * Run tests with unittest or pytest * Customizable PostgreSQL version +* Default integration with pre-commit_ for identifying simple issues before submission to code review .. _`maintained Foundation fork`: https://github.com/Parbhat/cookiecutter-django-foundation @@ -84,6 +85,7 @@ Optional Integrations .. _PythonAnywhere: https://www.pythonanywhere.com/ .. _Traefik: https://traefik.io/ .. _LetsEncrypt: https://letsencrypt.org/ +.. _pre-commit: https://github.com/pre-commit/pre-commit Constraints ----------- diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index fdab5a90..7a58d099 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -26,6 +26,12 @@ First things first. #. Install development requirements: :: $ pip install -r requirements/local.txt + $ pre-commit install + + .. note:: + + the `pre-commit` exists in the generated project as default. + for the details of `pre-commit`, follow the [site of pre-commit](https://pre-commit.com/). #. Create a new PostgreSQL database using createdb_: :: diff --git a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml new file mode 100644 index 00000000..b9d69a9a --- /dev/null +++ b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +exclude: 'docs|node_modules|migrations|.git|.tox' +default_stages: [commit] +fail_fast: true + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: master + hooks: + - id: trailing-whitespace + files: (^|/)a/.+\.(py|html|sh|css|js)$ + +- repo: local + hooks: + - id: flake8 + name: flake8 + entry: flake8 + language: python + types: [python] + diff --git a/{{cookiecutter.project_slug}}/requirements/local.txt b/{{cookiecutter.project_slug}}/requirements/local.txt index bb60bed0..73104eda 100644 --- a/{{cookiecutter.project_slug}}/requirements/local.txt +++ b/{{cookiecutter.project_slug}}/requirements/local.txt @@ -24,6 +24,7 @@ pylint-django==2.0.11 # https://github.com/PyCQA/pylint-django {%- if cookiecutter.use_celery == 'y' %} pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery {%- endif %} +pre-commit==1.20.0 # https://github.com/pre-commit/pre-commit # Django # ------------------------------------------------------------------------------