This tool looks for configuration in a pyproject.toml
file in the root of the codebase being analysed.
The default configuration values are:
[tool.plone-code-analysis]
checkers = ["black", "flake8", "isort", "pyroma", "zpretty"]
formatters = ["black", "isort", "zpretty"]
paths = "."
paths_pyroma = "."
paths_black = "."
paths_flake8 = "."
paths_isort = "."
paths_pyroma = "."
paths_zpretty = "."
If you want to change only the paths
, you should add to your pyproject.toml
the following settings:
[tool.plone-code-analysis]
paths = "src/ setup.py"
Also, it is possible to change the paths used for individual tools:
[tool.plone-code-analysis]
paths_black = "src/ tests/ setup.py"
paths_flake8 = "src/ setup.py"
Or explicitly set checkers
or formatters
to be used:
[tool.plone-code-analysis]
checkers = ["black", "flake8", "isort", "pyroma", ]
formatters = ["black", "isort",]
To configure black, flake8 (via flakeheaven) and isort, also use the pyproject.toml
file in the root of the directory you are mounting.
An example configuration, used by this image, follows:
[tool.black]
line-length = 88
target-version = ['py38']
include = '\.pyi?$'
[tool.isort]
profile = "black"
force_alphabetical_sort = true
force_single_line = true
lines_after_imports = 2
line_length = 120
[tool.flakeheaven]
format="grouped"
max_line_length=88
show_source=true
max-complexity=25
[tool.flakeheaven.plugins]
pycodestyle = ["+*"]
pyflakes = ["+*"]
"flake8-*" = ["+*"]
[tool.plone-code-analysis]
paths = "docker-entrypoint.py src/setup.py src/plone_code_analysis tests/fixtures/packages/ok tests/package tests/conftest.py"
paths_pyroma = "src/ tests/fixtures/packages/ok"
First, go to the repository you want to check or format.
Using the configuration available in pyproject.toml
, run:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check
Check with black
Check with pyproject.toml
settings:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check black
Explicitly check src directory and setup.py file.
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check black src setup.py
Check with flake8
Flake8 checks, using flakeheaven configuration format.
Current plugins in use:
Check with pyproject.toml
settings:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check flake8
Explicitly check src directory and setup.py file.
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check flake8 src setup.py
Check with isort
Check with pyproject.toml
settings:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check isort
Explicitly check src directory and setup.py file.
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check isort src setup.py
Check with pyroma
Check with pyproject.toml
settings:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check pyroma
Explicitly check src/mypackage directory .
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check pyroma src/mypackage
Check with zpretty
Check with pyproject.toml
settings:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check zpretty
Explicitly check src directory .
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check zpretty src
To avoid rewriting the owner and group information of the formatted files, we need to pass the correct --user
option to the docker run
command.
In all examples bellow we use the "$(id -u $(whoami)):$(getent group $(whoami)|cut -d: -f3)"
snippet to set the --user
option to the current user running the formatter.
Using the configuration available in pyproject.toml
, run:
docker run --user="$(id -u $(whoami)):$(getent group $(whoami)|cut -d: -f3)" --rm -v "${PWD}":/github/workspace plone/code-quality:latest format
Format with black
Format with pyproject.toml
settings:
docker run --user="$(id -u $(whoami)):$(getent group $(whoami)|cut -d: -f3)" --rm -v "${PWD}":/github/workspace plone/code-quality:latest format black
Explicitly format src directory and setup.py file.
docker run --user="$(id -u $(whoami)):$(getent group $(whoami)|cut -d: -f3)" --rm -v "${PWD}":/github/workspace plone/code-quality:latest format src setup.py
Format with isort
Format with pyproject.toml
settings:
docker run --user="$(id -u $(whoami)):$(getent group $(whoami)|cut -d: -f3)" --rm -v "${PWD}":/github/workspace plone/code-quality:latest format isort
Explicitly format src directory and setup.py file.
docker run --user="$(id -u $(whoami)):$(getent group $(whoami)|cut -d: -f3)" --rm -v "${PWD}":/github/workspace plone/code-quality:latest format src setup.py
Format with zpretty
Format with pyproject.toml
settings:
docker run --user="$(id -u $(whoami)):$(getent group $(whoami)|cut -d: -f3)" --rm -v "${PWD}":/github/workspace plone/code-quality:latest format zpretty
Explicitly format the src directory .
docker run --user="$(id -u $(whoami)):$(getent group $(whoami)|cut -d: -f3)" --rm -v "${PWD}":/github/workspace plone/code-quality:latest format src
Please DO NOT commit to version branches directly. Even for the smallest and most trivial fix.
ALWAYS open a pull request and ask somebody else to merge your code. NEVER merge it yourself.
Use this tool to lint its own codebase:
make lint-all
You can also increase the verbosity with:
LOG_LEVEL=DEBUG make lint-all
Use this tool to format its own codebase:
make format
You can also increase the verbosity with:
LOG_LEVEL=DEBUG make format
Tests are implemented with pytest
and can be run with:
make build
make test
Based on a solution originally developed by kitconcept GmbH.
The project is licensed under the GPLv2.