This commit is contained in:
Jeffrey Shek 2016-06-13 21:36:02 +00:00 committed by GitHub
commit 5d50d6a5cb
7 changed files with 63 additions and 1 deletions

View File

@ -50,6 +50,7 @@ Optional Integrations
* Serve static files from Amazon S3 or Whitenoise_
* Configuration for Celery_
* Configuration for Precommit-Hooks_
* Integration with MailHog_ for local email testing
* Integration with Sentry_ for error logging
* Integration with NewRelic_ for performance monitoring
@ -72,7 +73,7 @@ Optional Integrations
.. _docker-compose: https://www.github.com/docker/compose
.. _Opbeat: https://opbeat.com/
.. _PythonAnywhere: https://www.pythonanywhere.com/
.. _Precommit-Hooks_: http://pre-commit.com/
Constraints
-----------
@ -127,6 +128,7 @@ Answer the prompts with your own desired options_. For example::
use_docker [y]: y
use_heroku [n]: n
use_grunt [n]: y
use_precommit_hooks [n]: n
Select open_source_license:
1 - MIT
2 - BSD
@ -157,6 +159,10 @@ For development, see the following for local development:
.. _`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
If you chose to install pre-commit hooks, make sure to also run this after git init::
$ pre-commit install
Community
-----------

View File

@ -18,6 +18,7 @@
"use_docker": "y",
"use_heroku": "n",
"js_task_runner": ["Gulp", "Grunt", "None"],
"use_precommit_hooks": "n",
"use_lets_encrypt": "n",
"open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"]
}

View File

@ -49,6 +49,9 @@ use_python2 [n]
By default, the Python code generated will be for Python 3.x. But if you
answer `y` here, it will be legacy Python 2.7 code.
use_precommit_hooks [n]
If yes, include a basic configurations for git hooks that have to pass on each commit (or skipped).
.. _WhiteNoise: https://github.com/evansd/whitenoise
.. _Celery: https://github.com/celery/celery
.. _MailHog: https://github.com/mailhog/MailHog

View File

@ -111,6 +111,13 @@ def remove_pycharm_dir(project_directory):
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():
"""
Removes files needed for heroku if it isn't going to be used
@ -245,5 +252,9 @@ if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use
"You must generate a dhparams.pem file before running docker-compose in a production environment."
)
# 11. 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/
# copy_doc_files(PROJECT_DIRECTORY)

View File

@ -0,0 +1,17 @@
- 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: flake8
files: \.(py|sh)$
- id: name-tests-test
name: Django Tests should start with test_ prefix
files: tests/.+\.py$
args: ['--django'] # args: ['--django'] will match test*.py instead.
- repo: git://github.com/FalconSocial/pre-commit-python-sorter
sha: 1.0.4
hooks:
- id: python-import-sorter
args: ['--diff']

View File

@ -73,6 +73,26 @@ Please note: For Celery's import magic to work, it is important *where* the cele
{% endif %}
{% if cookiecutter.use_precommit_hooks == "y" %}
Pre-Commit Hooks
^^^^^^^^^^^^^^^^
To use pre-commit hooks when committing messages, after initial git commit, run
.. code-block:: bash
pre-commit install
Now on each commit message, this will run whatever commit plugins have been enabled. To skip a pre-commit hook, add a -n (no verify) parameter at the end of your commit message.
.. code-block:: bash
git commit -m "i put a really bad pdb in here" -n
{% endif %}
{% if cookiecutter.use_mailhog == "y" %}
Email Server

View File

@ -14,3 +14,7 @@ ipdb==0.10.0
pytest-django==2.9.1
pytest-sugar==0.7.1
{% if cookiecutter.use_precommit_hooks == 'y' -%}
pre-commit==0.8.2
{%- endif %}