mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-13 00:14:52 +03:00
Add pre-commit for generated Django project, not for Cookiecutter Django project
This commit is contained in:
parent
6efb18bcea
commit
57a7821158
|
@ -136,6 +136,7 @@ Listed in alphabetical order.
|
||||||
Keyvan Mosharraf `@keyvanm`_
|
Keyvan Mosharraf `@keyvanm`_
|
||||||
Krzysztof Szumny `@noisy`_
|
Krzysztof Szumny `@noisy`_
|
||||||
Krzysztof Żuraw `@krzysztofzuraw`_
|
Krzysztof Żuraw `@krzysztofzuraw`_
|
||||||
|
Leo Wong `@leollon`_
|
||||||
Leo Zhou `@glasslion`_
|
Leo Zhou `@glasslion`_
|
||||||
Leonardo Jimenez `@xpostudio4`_
|
Leonardo Jimenez `@xpostudio4`_
|
||||||
Lin Xianyi `@iynaix`_
|
Lin Xianyi `@iynaix`_
|
||||||
|
@ -286,6 +287,7 @@ Listed in alphabetical order.
|
||||||
.. _@kevgathuku: https://github.com/kevgathuku
|
.. _@kevgathuku: https://github.com/kevgathuku
|
||||||
.. _@keyvanm: https://github.com/keyvanm
|
.. _@keyvanm: https://github.com/keyvanm
|
||||||
.. _@knitatoms: https://github.com/knitatoms
|
.. _@knitatoms: https://github.com/knitatoms
|
||||||
|
.. _@leollon: https://github.com/leollon
|
||||||
.. _@krzysztofzuraw: https://github.com/krzysztofzuraw
|
.. _@krzysztofzuraw: https://github.com/krzysztofzuraw
|
||||||
.. _@MathijsHoogland: https://github.com/MathijsHoogland
|
.. _@MathijsHoogland: https://github.com/MathijsHoogland
|
||||||
.. _@mattayes: https://github.com/mattayes
|
.. _@mattayes: https://github.com/mattayes
|
||||||
|
|
|
@ -84,6 +84,7 @@ Optional Integrations
|
||||||
.. _PythonAnywhere: https://www.pythonanywhere.com/
|
.. _PythonAnywhere: https://www.pythonanywhere.com/
|
||||||
.. _Traefik: https://traefik.io/
|
.. _Traefik: https://traefik.io/
|
||||||
.. _LetsEncrypt: https://letsencrypt.org/
|
.. _LetsEncrypt: https://letsencrypt.org/
|
||||||
|
.. _pre-commit: https://github.com/pre-commit/pre-commit
|
||||||
|
|
||||||
Constraints
|
Constraints
|
||||||
-----------
|
-----------
|
||||||
|
@ -193,6 +194,7 @@ Answer the prompts with your own desired options_. For example::
|
||||||
5 - Not open source
|
5 - Not open source
|
||||||
Choose from 1, 2, 3, 4, 5 [1]: 1
|
Choose from 1, 2, 3, 4, 5 [1]: 1
|
||||||
keep_local_envs_in_vcs [y]: y
|
keep_local_envs_in_vcs [y]: y
|
||||||
|
use_pre_commit [n]: n
|
||||||
debug[n]: n
|
debug[n]: n
|
||||||
|
|
||||||
Enter the project and take a look around::
|
Enter the project and take a look around::
|
||||||
|
|
|
@ -42,6 +42,6 @@
|
||||||
"use_heroku": "n",
|
"use_heroku": "n",
|
||||||
"use_travisci": "n",
|
"use_travisci": "n",
|
||||||
"keep_local_envs_in_vcs": "y",
|
"keep_local_envs_in_vcs": "y",
|
||||||
|
"use_pre_commit": "n",
|
||||||
"debug": "n"
|
"debug": "n"
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ First things first.
|
||||||
#. Install development requirements: ::
|
#. Install development requirements: ::
|
||||||
|
|
||||||
$ pip install -r requirements/local.txt
|
$ pip install -r requirements/local.txt
|
||||||
|
# Optional: install git hook if using pre-commit
|
||||||
|
$ pre-commit install
|
||||||
|
|
||||||
#. Create a new PostgreSQL database using createdb_: ::
|
#. Create a new PostgreSQL database using createdb_: ::
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,14 @@ keep_local_envs_in_vcs:
|
||||||
is strongly encouraged).
|
is strongly encouraged).
|
||||||
Note: .env(s) are only utilized when Docker Compose and/or Heroku support is enabled.
|
Note: .env(s) are only utilized when Docker Compose and/or Heroku support is enabled.
|
||||||
|
|
||||||
|
use_pre_commit:
|
||||||
|
Indicates that pointing out issues in code on every commit with git,
|
||||||
|
such as missing semicolons, trailing whitespace, sort import statements
|
||||||
|
and debug statements. It is also good for code review while not wasting time with
|
||||||
|
trivial style nitpicks.
|
||||||
|
This option is just relevant for Django project developers,
|
||||||
|
but not for Cookiecutter Django developers.
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
Indicates whether the project should be configured for debugging.
|
Indicates whether the project should be configured for debugging.
|
||||||
This option is relevant for Cookiecutter Django developers only.
|
This option is relevant for Cookiecutter Django developers only.
|
||||||
|
|
|
@ -279,6 +279,10 @@ def remove_node_dockerfile():
|
||||||
shutil.rmtree(os.path.join("compose", "local", "node"))
|
shutil.rmtree(os.path.join("compose", "local", "node"))
|
||||||
|
|
||||||
|
|
||||||
|
def remove_dotpre_commit_config_yaml():
|
||||||
|
os.remove(".pre-commit-config.yaml")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
debug = "{{ cookiecutter.debug }}".lower() == "y"
|
debug = "{{ cookiecutter.debug }}".lower() == "y"
|
||||||
|
|
||||||
|
@ -342,6 +346,9 @@ def main():
|
||||||
if "{{ cookiecutter.use_travisci }}".lower() == "n":
|
if "{{ cookiecutter.use_travisci }}".lower() == "n":
|
||||||
remove_dottravisyml_file()
|
remove_dottravisyml_file()
|
||||||
|
|
||||||
|
if "{{ cookiecutter.use_pre_commit }}".lower() == "n":
|
||||||
|
remove_dotpre_commit_config_yaml()
|
||||||
|
|
||||||
print(SUCCESS + "Project initialized, keep up the good work!" + TERMINATOR)
|
print(SUCCESS + "Project initialized, keep up the good work!" + TERMINATOR)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ def context():
|
||||||
@pytest.mark.parametrize("use_sentry", YN_CHOICES, ids=lambda yn: f"sentry:{yn}")
|
@pytest.mark.parametrize("use_sentry", YN_CHOICES, ids=lambda yn: f"sentry:{yn}")
|
||||||
@pytest.mark.parametrize("use_compressor", YN_CHOICES, ids=lambda yn: f"cmpr:{yn}")
|
@pytest.mark.parametrize("use_compressor", YN_CHOICES, ids=lambda yn: f"cmpr:{yn}")
|
||||||
@pytest.mark.parametrize("use_whitenoise", YN_CHOICES, ids=lambda yn: f"wnoise:{yn}")
|
@pytest.mark.parametrize("use_whitenoise", YN_CHOICES, ids=lambda yn: f"wnoise:{yn}")
|
||||||
|
@pytest.mark.parametrize("use_pre_commit", YN_CHOICES, ids=lambda yn: f"precommit:{yn}")
|
||||||
@pytest.mark.parametrize("cloud_provider", CLOUD_CHOICES, ids=lambda yn: f"cloud:{yn}")
|
@pytest.mark.parametrize("cloud_provider", CLOUD_CHOICES, ids=lambda yn: f"cloud:{yn}")
|
||||||
def context_combination(
|
def context_combination(
|
||||||
windows,
|
windows,
|
||||||
|
@ -47,6 +48,7 @@ def context_combination(
|
||||||
use_compressor,
|
use_compressor,
|
||||||
use_whitenoise,
|
use_whitenoise,
|
||||||
cloud_provider,
|
cloud_provider,
|
||||||
|
use_pre_commit,
|
||||||
):
|
):
|
||||||
"""Fixture that parametrize the function where it's used."""
|
"""Fixture that parametrize the function where it's used."""
|
||||||
return {
|
return {
|
||||||
|
@ -58,6 +60,7 @@ def context_combination(
|
||||||
"use_sentry": use_sentry,
|
"use_sentry": use_sentry,
|
||||||
"use_whitenoise": use_whitenoise,
|
"use_whitenoise": use_whitenoise,
|
||||||
"cloud_provider": cloud_provider,
|
"cloud_provider": cloud_provider,
|
||||||
|
"use_pre_commit": use_pre_commit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
32
{{cookiecutter.project_slug}}/.pre-commit-config.yaml
Normal file
32
{{cookiecutter.project_slug}}/.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
exclude: .+/migrations/.+\.py
|
||||||
|
default_stages: [commit]
|
||||||
|
fail_fast: true
|
||||||
|
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: master
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
files: (^|/){{cookiecutter.project_slug}}/.+\.(py|html|sh|css|js)$
|
||||||
|
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
|
name: black
|
||||||
|
entry: black
|
||||||
|
args: [--line-length=80]
|
||||||
|
language: python
|
||||||
|
types: [python]
|
||||||
|
files: (^|/){{cookiecutter.project_slug}}/.+\.py$
|
||||||
|
verbose: true
|
||||||
|
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: flake8
|
||||||
|
name: flake8
|
||||||
|
entry: flake8
|
||||||
|
args: [--max-line-length=120]
|
||||||
|
language: python
|
||||||
|
types: [python]
|
||||||
|
files: (^|/){{cookiecutter.project_slug}}/.+\.py$
|
||||||
|
verbose: true
|
|
@ -21,6 +21,9 @@ flake8==3.7.8 # https://github.com/PyCQA/flake8
|
||||||
coverage==4.5.3 # https://github.com/nedbat/coveragepy
|
coverage==4.5.3 # https://github.com/nedbat/coveragepy
|
||||||
black==19.3b0 # https://github.com/ambv/black
|
black==19.3b0 # https://github.com/ambv/black
|
||||||
pylint-django==2.0.11 # https://github.com/PyCQA/pylint-django
|
pylint-django==2.0.11 # https://github.com/PyCQA/pylint-django
|
||||||
|
{%- if cookiecutter.use_pre_commit == 'y' %}
|
||||||
|
pre-commit==1.17.0 # https://github.com/pre-commit/pre-commit
|
||||||
|
{%- endif %}
|
||||||
{%- if cookiecutter.use_celery == 'y' %}
|
{%- if cookiecutter.use_celery == 'y' %}
|
||||||
pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery
|
pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user