Skip to content

Commit

Permalink
Added Flake8 (#36)
Browse files Browse the repository at this point in the history
* added flake8 to main repo
* added flake8 to cookiecutter
  • Loading branch information
Florian Maas authored Apr 26, 2022
1 parent 05cc75d commit 28553fb
Show file tree
Hide file tree
Showing 26 changed files with 217 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on-merge-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
needs: quality
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10']
steps:

- name: Check out
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
needs: quality
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10']
steps:

- name: Check out
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on-release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
needs: quality
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10']
steps:
- name: Check out
uses: actions/checkout@v2
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ format: ## Format code using isort and black.
@isort .
@black .

check: ## Check code formatting using isort, black, and mypy.
@echo "🚀 Checking code formatting: Running isort and black"
check: ## Check code formatting using isort, black, flake8 and mypy.
@echo "🚀 Checking code formatting: Running isort"
@isort --check-only --diff .
@echo "🚀 Checking code formatting: Running black"
@black --check .
@echo "🚀 Checking code formatting: Running flake8"
@flake8 .
@echo "🚀 Checking code formatting: Running mypy"
@mypy .

test: ## Test the code with pytest
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ repository to generate the file structure for a Python project that uses
- [Poetry](https://python-poetry.org/), obviously.
- CI/CD with [GitHub Actions](https://github.com/features/actions)
- Formatting with [black](https://pypi.org/project/black/) and [isort](https://pycqa.github.io/isort/index.html)
- Linting with [flake8](https://flake8.pycqa.org/en/latest/)
- Publishing to [Pypi](https://pypi.org) or [Artifactory](https://jfrog.com/artifactory) by creating a new release on GitHub
- Testing with [pytest](https://docs.pytest.org/en/7.1.x/)
- Documentation with [MkDocs](https://www.mkdocs.org/)
Expand Down
32 changes: 28 additions & 4 deletions docs/features/formatting.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: Formatting
---
# Formatting with black and isort


[isort](https://pycqa.github.io/isort/index.html) and
[black](https://pypi.org/project/black/) are added as development
Expand All @@ -13,7 +12,32 @@ make format
And the code style can be checked with

``` bash
make lint
make check
```

Settings for both `black` and `isort` can be edited in `pyproject.toml`. The default settings are:

```
[tool.black]
line-length = 120
include = '\.pyi?$'
target-version = ['py39']
fast = true
exclude = '''
(
/( # exclude a few common directories in the
\.git # root of the project
| \.pytest_cache
| python-venv
| \.venv
| build
| dist
| \.tox
))
'''
[tool.isort]
profile = "black"
```

If `include_github_actions` is set to `"y"`, code formatting is checked
Expand Down
29 changes: 29 additions & 0 deletions docs/features/linting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Linting with flake8

[flake8](https://flake8.pycqa.org/en/latest/) is added as development
dependency. The settings for `flake8` can be found in `tox.ini`, and they are defaulted to:

```
[flake8]
per-file-ignores = __init__.py:F401
# PEP-8 The following are ignored:
# E731 do not assign a lambda expression, use a def
# E203 whitespace before ':'
# E501 line too long
# W503 line break before binary operator
# W605 invalid escape sequence
ignore = E731, E203, E501, W503, W605
exclude =
.git,
__pycache__,
docs/source/conf.py,
old,
build,
dist,
.venv,
max-complexity = 10
max-line-length = 120
```

If `include_github_actions` is set to `"y"`, code linting is checked with `flake8`
for every merge request, every merge to main, and every release.
6 changes: 2 additions & 4 deletions docs/features/makefile.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
title: Makefile
---
# Makefile

The generated repository will have a `Makefile` available. A list of all
available commands that are available can be obtained by running
Expand All @@ -10,7 +8,7 @@ available:
```
install Install the poetry environment
format Format code using isort and black.
check Check code formatting using isort, black and mypy.
check Check code formatting using isort, black, flake8 and mypy.
test Test the code with pytest
mypy Check types with mypy
build Build wheel file using poetry
Expand Down
4 changes: 1 addition & 3 deletions docs/features/mypy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
title: Mypy
---
# Static type checking with Mypy

If `mypy` is set to `"y"`, static type checking is added with [mypy](https://mypy.readthedocs.io/en/stable/).
If `"github_actions` is also set to `"y"`, the code is checked with `mypy` during every workflow that is triggered.
Expand Down
5 changes: 2 additions & 3 deletions docs/features/poetry.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: Poetry
---
# Dependency management with Poetry


The generated repository will uses [Poetry](https://python-Poetry.org/)
for its dependency management. When you have created your repository
Expand Down
3 changes: 1 addition & 2 deletions docs/features/publishing.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

# Publishing to Pypi or Artifactory

# Releasing from Github
## Releasing from Github

When `publish_to` is set to `"pypi"` or `"artifactory"`, the
`on-release-main.yml` workflow publishes the code to
Expand Down
4 changes: 1 addition & 3 deletions docs/features/pytest.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
title: Pytest
---
# Unittesting with Pytest

[pytest](https://docs.pytest.org/en/7.1.x/) is automatically added to
the environment. There will be a template unittest in the `tests`
Expand Down
6 changes: 2 additions & 4 deletions docs/features/tox.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
title: Tox
---
# Compatibility testing with Tox

If `tox` is set to `"y"` project uses [Tox](https://tox.wiki/en/latest/)
to test compatibility with multiple Python versions. By default, the
project is tested with Python `3.7`, `3.8`, `3.9`, and `3.10`. Testing
project is tested with Python `3.8`, `3.9`, and `3.10`. Testing
is done automatically in the CI/CD pipeline on every pull request, merge
to main, and on each release.

Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A project generated with ``cookiecutter-poetry`` supports the following features
- [Poetry](https://python-poetry.org/), obviously.
- CI/CD with [GitHub Actions](https://github.com/features/actions)
- Formatting with [black](https://pypi.org/project/black/) and [isort](https://pycqa.github.io/isort/index.html)
- Linting with [flake8](https://flake8.pycqa.org/en/latest/)
- Publishing to [Pypi](https://pypi.org) or [Artifactory](https://jfrog.com/artifactory) by creating a new release on GitHub
- Testing with [pytest](https://docs.pytest.org/en/7.1.x/)
- Documentation with [MkDocs](https://www.mkdocs.org/)
Expand Down
3 changes: 0 additions & 3 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ def remove_dir(filepath: str) -> None:
if "{{cookiecutter.include_github_actions}}" != "y":
remove_dir(".github")

if "{{cookiecutter.tox}}" != "y":
remove_file("tox.ini")

if "{{cookiecutter.mkdocs}}" != "y":
remove_dir("docs")
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nav:
- Features:
- CI/CD with Github Actions: features/cicd.md
- Formatting with black and isort: features/formatting.md
- Linting with flake8: features/linting.md
- Makefile: features/makefile.md
- Dependency management with Poetry: features/poetry.md
- Publishing to PyPi or Artifactory: features/publishing.md
Expand Down
Loading

0 comments on commit 28553fb

Please sign in to comment.