mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-07-30 01:39:45 +03:00
add pre-commit hooks
This commit is contained in:
parent
05c521dd61
commit
83a71de11c
|
@ -132,6 +132,7 @@ Answer the prompts with your own desired options_. For example::
|
||||||
use_heroku [n]: n
|
use_heroku [n]: n
|
||||||
use_grunt [n]: y
|
use_grunt [n]: y
|
||||||
use_angular [n]: n
|
use_angular [n]: n
|
||||||
|
use_precommit_hooks [n]: n
|
||||||
Select open_source_license:
|
Select open_source_license:
|
||||||
1 - MIT
|
1 - MIT
|
||||||
2 - BSD
|
2 - BSD
|
||||||
|
@ -162,6 +163,10 @@ For development, see the following for local development:
|
||||||
.. _`Developing locally`: http://cookiecutter-django.readthedocs.io/en/latest/developing-locally.html
|
.. _`Developing locally`: http://cookiecutter-django.readthedocs.io/en/latest/developing-locally.html
|
||||||
.. _`Developing locally using docker`: http://cookiecutter-django.readthedocs.io/en/latest/developing-locally-docker.html
|
.. _`Developing locally using docker`: http://cookiecutter-django.readthedocs.io/en/latest/developing-locally-docker.html
|
||||||
|
|
||||||
|
If you chose to install pre-commit hooks, make sure to also run this after git init::
|
||||||
|
|
||||||
|
$ pre-commit install
|
||||||
|
|
||||||
Community
|
Community
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|
|
@ -22,5 +22,6 @@
|
||||||
"use_heroku": "n",
|
"use_heroku": "n",
|
||||||
"use_grunt": "n",
|
"use_grunt": "n",
|
||||||
"use_angular": "n",
|
"use_angular": "n",
|
||||||
|
"use_precommit_hooks": "n",
|
||||||
"open_source_license": ["MIT", "BSD", "Not open source"]
|
"open_source_license": ["MIT", "BSD", "Not open source"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,13 @@ def remove_pycharm_dir(project_directory):
|
||||||
shutil.rmtree(docs_dir_location)
|
shutil.rmtree(docs_dir_location)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_pre_commit_file():
|
||||||
|
"""
|
||||||
|
Removes pre-commit hook yaml file
|
||||||
|
"""
|
||||||
|
os.remove(os.path.join(PROJECT_DIRECTORY, '.pre-commit-config.yaml'))
|
||||||
|
|
||||||
|
|
||||||
def remove_heroku_files():
|
def remove_heroku_files():
|
||||||
"""
|
"""
|
||||||
Removes files needed for heroku if it isn't going to be used
|
Removes files needed for heroku if it isn't going to be used
|
||||||
|
@ -180,7 +187,6 @@ if '{{ cookiecutter.use_docker }}'.lower() != 'y':
|
||||||
if '{{ cookiecutter.use_grunt }}'.lower() != 'y':
|
if '{{ cookiecutter.use_grunt }}'.lower() != 'y':
|
||||||
remove_grunt_files()
|
remove_grunt_files()
|
||||||
|
|
||||||
|
|
||||||
# 7. Display a warning if use_docker and use_grunt are selected. Grunt isn't supported by our
|
# 7. Display a warning if use_docker and use_grunt are selected. Grunt isn't supported by our
|
||||||
# docker config atm.
|
# docker config atm.
|
||||||
if '{{ cookiecutter.use_grunt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y':
|
if '{{ cookiecutter.use_grunt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y':
|
||||||
|
@ -199,5 +205,9 @@ if '{{ cookiecutter.use_mailhog }}'.lower() == 'y' and '{{ cookiecutter.use_dock
|
||||||
" mailhog service to your docker configuration manually."
|
" mailhog service to your docker configuration manually."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 8. If pre-commit hooks aren't used, remove pre-commit yaml file
|
||||||
|
if '{{ cookiecutter.use_precommit_hooks }}'.lower() != 'y':
|
||||||
|
remove_pre_commit_file()
|
||||||
|
|
||||||
# 4. Copy files from /docs/ to {{ cookiecutter.project_slug }}/docs/
|
# 4. Copy files from /docs/ to {{ cookiecutter.project_slug }}/docs/
|
||||||
# copy_doc_files(PROJECT_DIRECTORY)
|
# copy_doc_files(PROJECT_DIRECTORY)
|
||||||
|
|
20
{{cookiecutter.project_slug}}/.pre-commit-config.yaml
Normal file
20
{{cookiecutter.project_slug}}/.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
- repo: git://github.com/pre-commit/pre-commit-hooks
|
||||||
|
sha: "6b1aa19425b35f8c34f43ada8f1045b028dc19a5"
|
||||||
|
hooks:
|
||||||
|
# keep ids alphabetical! see http://pre-commit.com/hooks.html
|
||||||
|
- id: debug-statements
|
||||||
|
files: \.py$
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
files: \.(py|sh)$
|
||||||
|
- id: flake8
|
||||||
|
files: \.(py|sh)$
|
||||||
|
- id: name-tests-test
|
||||||
|
files: tests/.+\.py$
|
||||||
|
args: ['--django'] # Use args: ['--django'] to match test*.py instead.
|
||||||
|
- id: trailing-whitespace
|
||||||
|
files: \.(py|sh|yaml|txt)$
|
||||||
|
- repo: git://github.com/FalconSocial/pre-commit-python-sorter
|
||||||
|
sha: 1.0.4
|
||||||
|
hooks:
|
||||||
|
- id: python-import-sorter
|
||||||
|
args: ['--diff']
|
|
@ -14,3 +14,7 @@ ipdb==0.10.0
|
||||||
|
|
||||||
pytest-django==2.9.1
|
pytest-django==2.9.1
|
||||||
pytest-sugar==0.7.1
|
pytest-sugar==0.7.1
|
||||||
|
|
||||||
|
{% if cookiecutter.use_precommit_hooks == 'y' -%}
|
||||||
|
pre-commit==0.8.2
|
||||||
|
{%- endif %}
|
Loading…
Reference in New Issue
Block a user