Skip to content

Commit

Permalink
Global pylint config and new CI check (#176)
Browse files Browse the repository at this point in the history
* Added union of all exceptions to the global pylint config

* Hacky script to ensure that tox.ini and pyproject.toml have fitting pylint exceptions

* Better and more explanatory script

* Moved script and added it to CI

* Added a small message to state that everything worked fine
  • Loading branch information
nathanaelbosch authored Aug 26, 2020
1 parent a27def6 commit cee2175
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ jobs:
run: pip install tox
- name: Run pylint through tox
run: tox -e pylint

pylint-tox-config-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Check if ./tox.ini and ./pyproject.toml are correctly synchronized
run: python .github/workflows/pylint_check.py
79 changes: 79 additions & 0 deletions .github/workflows/pylint_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from pathlib import Path

TOXINI_FILE = Path("tox.ini")
PYPROJECTTOML_FILE = Path("pyproject.toml")
GLOBAL_DISABLES = {
"invalid-name",
"no-else-raise",
"no-else-return",
}


# Parse ./tox.ini
tox_lines = TOXINI_FILE.read_text().splitlines()
tox_pylint_lines = [l for l in tox_lines if l.strip().startswith("pylint")]
tox_disables = {i for l in tox_pylint_lines for i in l.split('"')[1].split(",")}


# Parse ./pyproject.toml
pyproject_lines = PYPROJECTTOML_FILE.read_text().splitlines()
is_in_disable_string = False
pyproject_disables = set()
for line in pyproject_lines:
if is_in_disable_string and line.startswith('"""'):
is_in_disable_string = False

if is_in_disable_string and line:
pyproject_disables.add(line.strip().strip(","))

if line.startswith("disable"):
is_in_disable_string = True


# Check correctness and raise errors
try:
in_pyproject_butnot_tox = pyproject_disables.difference(tox_disables).difference(
GLOBAL_DISABLES
)
assert not in_pyproject_butnot_tox
except AssertionError:
raise Exception(
f"""
The following pylint messages seem to be disabled in `./pyproject.toml`, but not in
any of the pylint calls in `./tox.ini`: {in_pyproject_butnot_tox}. This could have
two reasons with different solutions:
1. You fixed one or many pylint errors in one of the modules and there is no module
left that needs this specific message disabled. Then, please also remove it from
the `./pyproject.toml` file such that pylint uses the most up-to-date
configuration file.
2. You added a new global exception to `./pyproject.toml` after deciding that this
is a message that we do not want to enforce anywhere currently. Then, please add
this exception also to the `GLOBAL_DISABLES` variable in this this python script
(`./github/workflows/pylint_check.py`).
If you are not sure what exactly you are supposed to do, or if you think that this
message is wrong please feel free to ping @nathanaelbosch.
"""
)


try:
in_tox_butnot_pyproject = tox_disables.difference(pyproject_disables)
assert not in_tox_butnot_pyproject
except AssertionError:
raise Exception(
f"""
The following pylint messages seem to be disabled in `./tox.ini`, but not in
`./pyproject.toml`: {in_tox_butnot_pyproject}. Please make sure to add them to
`./pyproject.toml` such that pylint does not raise any warnings that are not
supposed to be fixed right now.
If you are not sure what exactly you are supposed to do, or if you think that this
message is wrong please feel free to ping @nathanaelbosch.
"""
)


print(
"The pylint exceptions in `./tox.ini` and `./pyproject.toml` seem to be correctly synchronized."
)
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,33 @@ invalid-name,
no-else-return,
no-else-raise,
abstract-class-instantiated,
too-many-locals,
too-few-public-methods,
too-many-arguments,
unused-argument,
missing-module-docstring,
missing-function-docstring,
duplicate-code,
protected-access,
no-self-use,
arguments-differ,
attribute-defined-outside-init,
too-many-statements,
too-many-instance-attributes,
too-complex,
too-many-lines,
redefined-builtin,
abstract-method,
too-many-branches,
fixme,
broad-except,
raise-missing-from,
line-too-long,
missing-class-docstring,
unnecessary-pass,
unused-variable,
"""
# Many more `disable`s are defined in `./tox.ini` on a per-module basis!

Expand Down

0 comments on commit cee2175

Please sign in to comment.