Add a local flake8 AST check that detects set literals passed where
a dict is expected in logging calls with %-style named placeholders.
For example, LOG.info("%(key)s", {"key", val}) uses a comma instead
of a colon, creating a set instead of a dict, which causes TypeError
at runtime.
This re-adds the cyborg/hacking/ local plugin directory (removed in
8eb3a5a during the ruff migration) with a new C-prefix code range.
The old M-prefix checks are not restored as they are now covered by
ruff. The check is registered via [flake8:local-plugins] in tox.ini
and runs as part of the existing pre-commit hacking hook.
Also adds pycodestyle to test-requirements.txt, needed by the test
to exercise the check through pycodestyle's checker infrastructure.
Related-Bug: #2157892
Assisted-by: Claude claude-opus-4-6 claude-code/2.1.196
Change-Id: Ib88b17d7087f475b741a3f0ce349654f3ae20d22
Signed-off-by: melanie witt <melwittt@gmail.com>
128 lines
3.6 KiB
INI
128 lines
3.6 KiB
INI
[tox]
|
|
minversion = 3.18.0
|
|
envlist = py3,pep8
|
|
|
|
[testenv]
|
|
usedevelop = True
|
|
allowlist_externals =
|
|
rm
|
|
env
|
|
make
|
|
setenv =
|
|
OS_TEST_PATH=cyborg/tests/unit
|
|
deps =
|
|
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
|
-r{toxinidir}/requirements.txt
|
|
-r{toxinidir}/test-requirements.txt
|
|
|
|
commands = stestr run --slowest {posargs}
|
|
|
|
[testenv:genpolicy]
|
|
sitepackages = False
|
|
commands =
|
|
oslopolicy-sample-generator --config-file=tools/config/cyborg-policy-generator.conf
|
|
|
|
[testenv:genconfig]
|
|
sitepackages = False
|
|
commands =
|
|
oslo-config-generator --config-file=tools/config/cyborg-config-generator.conf
|
|
|
|
[testenv:bindep]
|
|
# Do not install any requirements. We want this to be fast and work even if
|
|
# system dependencies are missing, since it's used to tell you what system
|
|
# dependencies are missing! This also means that bindep must be installed
|
|
# separately, outside of the requirements files, and develop mode disabled
|
|
# explicitly to avoid unnecessarily installing the checked-out repo too (this
|
|
# further relies on "tox.skipsdist = True" above).
|
|
deps = bindep
|
|
commands = bindep test
|
|
usedevelop = False
|
|
|
|
[testenv:pep8]
|
|
description =
|
|
Run style checks.
|
|
deps = pre-commit
|
|
skip_install = true
|
|
commands = pre-commit run -a --show-diff-on-failure
|
|
|
|
[testenv:venv]
|
|
commands = {posargs}
|
|
|
|
[testenv:cover]
|
|
setenv =
|
|
PYTHON=coverage run --source cyborg --parallel-mode
|
|
commands =
|
|
coverage erase
|
|
stestr run {posargs}
|
|
coverage combine
|
|
coverage html -d cover
|
|
coverage xml -o cover/coverage.xml
|
|
coverage report
|
|
|
|
[doc8]
|
|
ignore-path = .venv,.git,.tox,*cyborg/locale*,*lib/python*,*cyborg.egg*,api-ref/build,doc/build,doc/source/contributor/api
|
|
|
|
|
|
[testenv:docs]
|
|
description =
|
|
Build main documentation.
|
|
allowlist_externals =
|
|
sphinx-build
|
|
rm
|
|
deps =
|
|
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
|
-r{toxinidir}/doc/requirements.txt
|
|
commands =
|
|
rm -rf doc/build/html doc/build/doctrees
|
|
sphinx-build -W --keep-going -b html -j auto doc/source doc/build/html
|
|
|
|
[testenv:pdf-docs]
|
|
description =
|
|
Build PDF documentation.
|
|
deps = {[testenv:docs]deps}
|
|
commands =
|
|
rm -rf doc/build/pdf
|
|
sphinx-build -W --keep-going -b latex -j auto doc/source doc/build/pdf
|
|
make -C doc/build/pdf
|
|
|
|
[testenv:releasenotes]
|
|
description =
|
|
Generate release notes.
|
|
deps = {[testenv:docs]deps}
|
|
commands =
|
|
rm -rf releasenotes/build
|
|
sphinx-build -W --keep-going -b html -j auto releasenotes/source releasenotes/build/html
|
|
|
|
[testenv:debug]
|
|
commands = oslo_debug_helper -t cyborg/tests {posargs}
|
|
|
|
[testenv:api-ref]
|
|
description =
|
|
Generate the API ref. Called from CI scripts to test and publish to docs.openstack.org.
|
|
# This environment is called from CI scripts to test and publish
|
|
# the API Ref to docs.openstack.org.
|
|
deps = {[testenv:docs]deps}
|
|
commands =
|
|
rm -rf api-ref/build
|
|
sphinx-build -W --keep-going -b html -j auto api-ref/source api-ref/build/html
|
|
allowlist_externals = rm
|
|
|
|
[flake8]
|
|
# We only enable the hacking (H) checks; ruff handles everything else
|
|
select = H,C
|
|
# H301 ruff-I enforces one-symbol-per-line where needed
|
|
# H306 ruff-I (rule I001) handles import ordering; its sort key (by
|
|
# from-module path) differs from H306's (fully-qualified name),
|
|
# so H306 is redundant and would produce false positives
|
|
# H404 Docstrings don't always start with a newline
|
|
# H405 Multiline docstrings are okay
|
|
ignore = H301,H306,H404,H405
|
|
show-source = True
|
|
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,releasenotes,*sqlalchemy/alembic/versions/*
|
|
|
|
[flake8:local-plugins]
|
|
extension =
|
|
C300 = checks:CheckSetLiteralInLogging
|
|
paths =
|
|
./cyborg/hacking
|