Setup pre-commit for the template files (#3433)

This commit is contained in:
Bruno Alla 2021-11-26 15:41:50 +00:00 committed by GitHub
parent 15f403c02c
commit 407a7d8bbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 87 additions and 43 deletions

View File

@ -12,11 +12,11 @@ labels: bug
<!-- To assist you best, please include commands that you've run, options you've selected and any relevant logs -->
* Host system configuration:
* Host system configuration:
* Version of cookiecutter CLI (get it with `cookiecutter --version`):
* OS name and version:
On Linux, run
On Linux, run
```bash
lsb_release -a 2> /dev/null || cat /etc/redhat-release 2> /dev/null || cat /etc/*-release 2> /dev/null || cat /etc/issue 2> /dev/null
```
@ -25,7 +25,7 @@ labels: bug
```bash
sw_vers
```
On Windows, via CMD, run
```
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
@ -34,7 +34,7 @@ labels: bug
```bash
# Insert here the OS name and version
```
* Python version, run `python3 -V`:

View File

@ -6,6 +6,6 @@ labels: question
First, make sure to examine [the docs](https://cookiecutter-django.readthedocs.io/en/latest/). If that doesn't help, we recommend one of these 3 main channels:
- If your issue is related to Django + something else but was generated with cookiecutter-django, the best is to post a question on [StackOverflow](https://stackoverflow.com/questions/tagged/cookiecutter-django) tagged with `cookiecutter-django`, you would get more visibility from other communities as well.
- If your issue is related to Django + something else but was generated with cookiecutter-django, the best is to post a question on [StackOverflow](https://stackoverflow.com/questions/tagged/cookiecutter-django) tagged with `cookiecutter-django`, you would get more visibility from other communities as well.
- Join us on [Discord](https://discord.gg/bTfDa6Zz) and ask around.
- Start [a discussion](https://github.com/cookiecutter/cookiecutter-django/discussions) on our project's GitHub.

View File

@ -12,7 +12,7 @@ Checklist:
## Rationale
<!--
Why does this project need the change you're proposing?
If this pull request fixes an open issue, don't forget to link it with `Fix #NNNN`
<!--
Why does this project need the change you're proposing?
If this pull request fixes an open issue, don't forget to link it with `Fix #NNNN`
-->

View File

@ -5,16 +5,20 @@ on:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.9"
cache: pip
- name: Run pre-commit
uses: pre-commit/action@v2.0.3
tox:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tox-env:
- py39
- black-template
name: "tox env ${{ matrix.tox-env }}"
name: "Test with tox"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
@ -25,8 +29,8 @@ jobs:
run: |
python -m pip install -U pip
python -m pip install -U tox
- name: Tox ${{ matrix.tox-env }}
run: tox -e ${{ matrix.tox-env }}
- name: Run tox
run: tox -e py39
docker:
runs-on: ubuntu-latest

29
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,29 @@
exclude: "{{cookiecutter.project_slug}}"
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: check-yaml
- repo: https://github.com/psf/black
rev: 21.11b1
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
ci:
autoupdate_schedule: weekly
skip: []
submodules: false

View File

@ -1066,7 +1066,7 @@ All enhancements and patches to Cookiecutter Django will be documented in this f
### Removed
- Remove the user list view (@browniebroke)
### Fixed
### Fixed
- Static storage default ACL (@browniebroke)
## [2019-05-17]
@ -1102,7 +1102,7 @@ All enhancements and patches to Cookiecutter Django will be documented in this f
## [2019-03-11]
### Changed
- Sentry integration from Raven to Sentry-SDK (@gfabricio)
- Made Redis config conditional on Celery locally (@demestav)
- Made Redis config conditional on Celery locally (@demestav)
## [2019-03-11]
### Added
@ -1171,7 +1171,7 @@ All enhancements and patches to Cookiecutter Django will be documented in this f
### Changed
- Test commands to use pytest (@jcass77)
### Removed
### Removed
- Some hacks leftovers from Bootstrap v4 beta in `project.js` (@hendrikschneider)
## [2018-07-12]

View File

@ -7,10 +7,7 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
from datetime import datetime
import os
import sys
now = datetime.now()
@ -242,7 +239,8 @@ texinfo_documents = [
"Cookiecutter Django documentation",
"Daniel Roy Greenfeld",
"Cookiecutter Django",
"A Cookiecutter template for creating production-ready Django projects quickly.",
"A Cookiecutter template for creating production-ready "
"Django projects quickly.",
"Miscellaneous",
)
]

View File

@ -10,7 +10,7 @@ Run these commands to deploy the project to Heroku:
.. code-block:: bash
heroku create --buildpack heroku/python
heroku create --buildpack heroku/python
heroku addons:create heroku-postgresql:hobby-dev
# On Windows use double quotes for the time zone, e.g.

View File

@ -216,17 +216,17 @@ Increasingly it is becoming necessary to develop software in a secure environmen
In order to create a secure environment, we need to have a trusted SSL certficate installed in our Docker application.
#. **Let's Encrypt**
The official line from Lets Encrypt is:
[For local development section] ... The best option: Generate your own certificate, either self-signed or signed by a local root, and trust it in your operating systems trust store. Then use that certificate in your local web server. See below for details.
The official line from Lets Encrypt is:
[For local development section] ... The best option: Generate your own certificate, either self-signed or signed by a local root, and trust it in your operating systems trust store. Then use that certificate in your local web server. See below for details.
See `letsencrypt.org - certificates-for-localhost`_
.. _`letsencrypt.org - certificates-for-localhost`: https://letsencrypt.org/docs/certificates-for-localhost/
#. **mkcert: Valid Https Certificates For Localhost**
`mkcert`_ is a simple by design tool that hides all the arcane knowledge required to generate valid TLS certificates. It works for any hostname or IP, including localhost. It supports macOS, Linux, and Windows, and Firefox, Chrome and Java. It even works on mobile devices with a couple manual steps.
See https://blog.filippo.io/mkcert-valid-https-certificates-for-localhost/
@ -261,11 +261,11 @@ local.yml
restart: always
depends_on:
- django
...
#. Link the ``nginx-proxy`` to ``django`` through environment variables.
``django`` already has an ``.env`` file connected to it. Add the following variables. You should do this especially if you are working with a team and you want to keep your local environment details to yourself.
::

View File

@ -5,7 +5,8 @@ NOTE:
can potentially be run in Python 2.x environment
(at least so we presume in `pre_gen_project.py`).
TODO: ? restrict Cookiecutter Django project initialization to Python 3.x environments only
TODO: restrict Cookiecutter Django project initialization to
Python 3.x environments only
"""
from __future__ import print_function
@ -164,8 +165,8 @@ def set_flag(file_path, flag, value=None, formatted=None, *args, **kwargs):
random_string = generate_random_string(*args, **kwargs)
if random_string is None:
print(
"We couldn't find a secure pseudo-random number generator on your system. "
"Please, make sure to manually {} later.".format(flag)
"We couldn't find a secure pseudo-random number generator on your "
"system. Please, make sure to manually {} later.".format(flag)
)
random_string = flag
if formatted is not None:

View File

@ -4,7 +4,8 @@ NOTE:
as the whole Cookiecutter Django project initialization
can potentially be run in Python 2.x environment.
TODO: ? restrict Cookiecutter Django project initialization to Python 3.x environments only
TODO: restrict Cookiecutter Django project initialization
to Python 3.x environments only
"""
from __future__ import print_function
@ -39,7 +40,7 @@ if "{{ cookiecutter.use_docker }}".lower() == "n":
)
yes_options, no_options = frozenset(["y"]), frozenset(["n"])
while True:
choice = raw_input().lower()
choice = raw_input().lower() # noqa: F821
if choice in yes_options:
break
@ -65,7 +66,8 @@ if (
and "{{ cookiecutter.cloud_provider }}" == "None"
):
print(
"You should either use Whitenoise or select a Cloud Provider to serve static files"
"You should either use Whitenoise or select a "
"Cloud Provider to serve static files"
)
sys.exit(1)
@ -77,6 +79,7 @@ if (
and "{{ cookiecutter.mail_service }}" == "Amazon SES"
):
print(
"You should either use AWS or select a different Mail Service for sending emails."
"You should either use AWS or select a different "
"Mail Service for sending emails."
)
sys.exit(1)

View File

@ -1 +0,0 @@

View File

@ -85,7 +85,7 @@ def group_pulls_by_change_type(
"Updated": [],
}
for pull in pull_requests_list:
label_names = {l.name for l in pull.labels}
label_names = {label.name for label in pull.labels}
if "update" in label_names:
group_name = "Updated"
elif "bug" in label_names:

7
setup.cfg Normal file
View File

@ -0,0 +1,7 @@
[flake8]
exclude = docs
max-line-length = 88
[isort]
profile = black
known_first_party = tests,scripts,hooks

View File

@ -13,7 +13,10 @@ with open("README.rst") as readme_file:
setup(
name="cookiecutter-django",
version=version,
description="A Cookiecutter template for creating production-ready Django projects quickly.",
description=(
"A Cookiecutter template for creating production-ready "
"Django projects quickly."
),
long_description=long_description,
author="Daniel Roy Greenfeld",
author_email="pydanny@gmail.com",

View File

@ -2,10 +2,10 @@ import os
import re
import pytest
from cookiecutter.exceptions import FailedHookException
import sh
import yaml
from binaryornot.check import is_binary
from cookiecutter.exceptions import FailedHookException
PATTERN = r"{{(\s?cookiecutter)[.](.*?)}}"
RE_OBJ = re.compile(PATTERN)