-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global pylint config and new CI check (#176)
* 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
1 parent
a27def6
commit cee2175
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters