Skip to content

Commit 7b78663

Browse files
committed
Initial commit
0 parents  commit 7b78663

File tree

16 files changed

+367
-0
lines changed

16 files changed

+367
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Sourcery
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Python Best Practices Cookiecutter
2+
3+
Best practices [cookiecutter](https://github.com/audreyr/cookiecutter) template as described in this [blogpost](https://sourcery.ai/blog/python-best-practices/).
4+
5+
## Features
6+
- Testing with [pytest](https://docs.pytest.org/en/latest/)
7+
- Formatting with [black](https://github.com/psf/black)
8+
- Import sorting with [isort](https://github.com/timothycrosley/isort)
9+
- Static typing with [mypy](http://mypy-lang.org/)
10+
- Linting with [flake8](http://flake8.pycqa.org/en/latest/)
11+
- Git hooks that run all the above with [pre-commit](https://pre-commit.com/)
12+
13+
## Quickstart
14+
```sh
15+
# Install pipx if pipenv and cookiecutter are not installed
16+
python3 -m pip install pipx
17+
python3 -m pipx ensurepath
18+
19+
# Install pipenv using pipx
20+
pipx install pipenv
21+
22+
# Use cookiecutter to create project from this template
23+
pipx run cookiecutter gh:sourceryai/python-best-practices-cookiecutter
24+
25+
# Enter project directory
26+
cd <repo_name>
27+
28+
# Initialise git repo
29+
git init
30+
31+
# Install dependencies
32+
pipenv install --dev
33+
34+
# Setup pre-commit and pre-push hooks
35+
pipenv run pre-commit install -t pre-commit
36+
pipenv run pre-commit install -t pre-push
37+
```

cookiecutter.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"project_name": "Best Practices",
3+
"repo_name": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}"
4+
}

hooks/post_gen_project.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
3+
python_version = str(sys.version_info.major) + '.' + str(sys.version_info.minor)
4+
5+
6+
with open('Pipfile') as f:
7+
pipfile = f.read()
8+
pipfile = pipfile.replace(r'{python_version}', python_version)
9+
10+
11+
with open('Pipfile', 'w') as f:
12+
f.write(pipfile)

hooks/pre_gen_project.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import re
2+
import sys
3+
4+
MODULE_REGEX = r'^[a-zA-Z][_a-zA-Z0-9]+$'
5+
module_name = '{{ cookiecutter.repo_name }}'
6+
7+
if not re.match(MODULE_REGEX, module_name):
8+
print('ERROR: %s is not a valid Python module name!' % module_name)
9+
sys.exit(1)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[run]
2+
source = {{cookiecutter.project_name}}
3+
4+
[report]
5+
exclude_lines =
6+
# Have to re-enable the standard pragma
7+
pragma: no cover
8+
9+
# Don't complain about missing debug-only code:
10+
def __repr__
11+
if self\.debug
12+
13+
# Don't complain if tests don't hit defensive assertion code:
14+
raise AssertionError
15+
raise NotImplementedError
16+
17+
# Don't complain if non-runnable code isn't run:
18+
if 0:
19+
if __name__ == .__main__.:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# http://editorconfig.org/#file-format-details
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 4
8+
indent_style = space
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.md]
13+
indent_size = 4
14+
15+
[*.md]
16+
indent_size = 4
17+
trim_trailing_whitespace = false
18+
19+
[Makefile]
20+
indent_style = tab
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Created by https://www.gitignore.io/api/python
2+
# Edit at https://www.gitignore.io/?templates=python
3+
4+
### Python ###
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
pip-wheel-metadata/
28+
share/python-wheels/
29+
*.egg-info/
30+
.installed.cfg
31+
*.egg
32+
MANIFEST
33+
34+
# PyInstaller
35+
# Usually these files are written by a python script from a template
36+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
37+
*.manifest
38+
*.spec
39+
40+
# Installer logs
41+
pip-log.txt
42+
pip-delete-this-directory.txt
43+
44+
# Unit test / coverage reports
45+
htmlcov/
46+
.tox/
47+
.nox/
48+
.coverage
49+
.coverage.*
50+
.cache
51+
nosetests.xml
52+
coverage.xml
53+
*.cover
54+
.hypothesis/
55+
.pytest_cache/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
73+
74+
# Sphinx documentation
75+
docs/_build/
76+
77+
# PyBuilder
78+
target/
79+
80+
# Jupyter Notebook
81+
.ipynb_checkpoints
82+
83+
# IPython
84+
profile_default/
85+
ipython_config.py
86+
87+
# pyenv
88+
.python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# celery beat schedule file
98+
celerybeat-schedule
99+
100+
# SageMath parsed files
101+
*.sage.py
102+
103+
# Environments
104+
.env
105+
.venv
106+
env/
107+
venv/
108+
ENV/
109+
env.bak/
110+
venv.bak/
111+
112+
# Spyder project settings
113+
.spyderproject
114+
.spyproject
115+
116+
# Rope project settings
117+
.ropeproject
118+
119+
# mkdocs documentation
120+
/site
121+
122+
# mypy
123+
.mypy_cache/
124+
.dmypy.json
125+
dmypy.json
126+
127+
# Pyre type checker
128+
.pyre/
129+
130+
# End of https://www.gitignore.io/api/python
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# See https://pre-commit.com/ for usage and config
2+
repos:
3+
- repo: local
4+
hooks:
5+
- id: isort
6+
name: isort
7+
stages: [commit]
8+
language: system
9+
entry: pipenv run isort
10+
types: [python]
11+
12+
- id: black
13+
name: black
14+
stages: [commit]
15+
language: system
16+
entry: pipenv run black
17+
types: [python]
18+
19+
- id: flake8
20+
name: flake8
21+
stages: [commit]
22+
language: system
23+
entry: pipenv run flake8
24+
types: [python]
25+
exclude: setup.py
26+
27+
- id: mypy
28+
name: mypy
29+
stages: [commit]
30+
language: system
31+
entry: pipenv run mypy
32+
types: [python]
33+
pass_filenames: false
34+
35+
- id: pytest
36+
name: pytest
37+
stages: [commit]
38+
language: system
39+
entry: pipenv run pytest
40+
types: [python]
41+
42+
- id: pytest-cov
43+
name: pytest
44+
stages: [push]
45+
language: system
46+
entry: pipenv run pytest --cov --cov-fail-under=100
47+
types: [python]
48+
pass_filenames: false

{{cookiecutter.repo_name}}/Pipfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.python.org/simple"
4+
verify_ssl = true
5+
6+
[requires]
7+
python_version = "{python_version}"
8+
9+
[packages]
10+
11+
[dev-packages]
12+
black = "==19.3b0"
13+
flake8 = "*"
14+
isort = "*"
15+
mypy = "*"
16+
pre-commit = "*"
17+
pytest = "*"
18+
pytest-cov = "*"

0 commit comments

Comments
 (0)