Skip to content

Fix parsing of unrelated options in tox.ini #6801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ What's New in Pylint 2.14.1?
----------------------------
Release date: TBA

* Fixed parsing of unrelated options in ``tox.ini``.

Closes #6800

* Don't crash if we can't find the user's home directory.

Closes #6802
Expand Down
16 changes: 13 additions & 3 deletions pylint/config/config_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def __init__(self, verbose: bool, linter: PyLinter) -> None:
self.verbose_mode = verbose
self.linter = linter

@staticmethod
def _parse_ini_file(file_path: Path) -> tuple[dict[str, str], list[str]]:
def _parse_ini_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tremor of the removal of no-self-use 😄 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

"""Parse and handle errors of a ini configuration file."""
parser = configparser.ConfigParser(inline_comment_prefixes=("#", ";"))

Expand All @@ -43,7 +42,9 @@ def _parse_ini_file(file_path: Path) -> tuple[dict[str, str], list[str]]:
config_content: dict[str, str] = {}
options: list[str] = []
for section in parser.sections():
if "setup.cfg" in str(file_path) and not section.startswith("pylint"):
if self._ini_file_with_sections(str(file_path)) and not section.startswith(
"pylint"
):
if section.lower() == "master":
# TODO: 3.0: Remove deprecated handling of master, only allow 'pylint.' sections
warnings.warn(
Expand All @@ -60,6 +61,15 @@ def _parse_ini_file(file_path: Path) -> tuple[dict[str, str], list[str]]:
options += [f"--{opt}", value]
return config_content, options

@staticmethod
def _ini_file_with_sections(file_path: str) -> bool:
"""Return whether the file uses sections."""
if "setup.cfg" in file_path:
return True
if "tox.ini" in file_path:
return True
return False
Comment on lines +67 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if "setup.cfg" in file_path:
return True
if "tox.ini" in file_path:
return True
return False
return any(n in file_path for n in ["setup.cfg", "tox.ini"])

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave this as is.

I can imagine we want to expand this. For example, by checking if a section starts with tool:pylint if we are in a setup.cfg file.


def _parse_toml_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
"""Parse and handle errors of a toml configuration file."""
try:
Expand Down
16 changes: 16 additions & 0 deletions tests/config/functional/tox/unrecognized_options/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; Test for https://github.com/PyCQA/pylint/issues/6800

[tox]
skipsdist = True
envlist = py3, pylint

[testenv]
setenv = PYTHONWARNINGS=ignore

[testenv:pylint]
deps =
pylint


[pylint]
jobs = 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"jobs": 10
}