This tool looks for configuration in a pyproject.tomlfile 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 checkCheck with black
Check with pyproject.toml settings:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check blackExplicitly check src directory and setup.py file.
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check black src setup.pyCheck 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 flake8Explicitly check src directory and setup.py file.
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check flake8 src setup.pyCheck with isort
Check with pyproject.toml settings:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check isortExplicitly check src directory and setup.py file.
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check isort src setup.pyCheck with pyroma
Check with pyproject.toml settings:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check pyromaExplicitly check src/mypackage directory .
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check pyroma src/mypackageCheck with zpretty
Check with pyproject.toml settings:
docker run --rm -v "${PWD}":/github/workspace plone/code-quality:latest check zprettyExplicitly 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 formatFormat 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 blackExplicitly 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.pyFormat 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 isortExplicitly 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.pyFormat 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 zprettyExplicitly 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-allYou can also increase the verbosity with:
LOG_LEVEL=DEBUG make lint-allUse this tool to format its own codebase:
make formatYou can also increase the verbosity with:
LOG_LEVEL=DEBUG make formatTests are implemented with pytest and can be run with:
make build
make testBased on a solution originally developed by kitconcept GmbH.
The project is licensed under the GPLv2.
