Skip to content

Commit

Permalink
Fix recognition of config files named setup.cfg (#3630) (#6577)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniël van Noord <[email protected]>
  • Loading branch information
Pierre-Sassoulas and DanielNoord committed Jun 29, 2022
1 parent e820200 commit 15470d1
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 4 deletions.
6 changes: 6 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Release date: TBA

Closes #6965

* Fixed an issue with the recognition of ``setup.cfg`` files.
Only ``.cfg`` files that are exactly named ``setup.cfg`` require section names that
start with ``pylint.``.

Closes #3630

* Don't report ``import-private-name`` for relative imports.

Closes #7078
Expand Down
8 changes: 4 additions & 4 deletions pylint/config/config_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _parse_ini_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
config_content: dict[str, str] = {}
options: list[str] = []
for section in parser.sections():
if self._ini_file_with_sections(str(file_path)) and not section.startswith(
if self._ini_file_with_sections(file_path) and not section.startswith(
"pylint"
):
if section.lower() == "master":
Expand All @@ -61,11 +61,11 @@ def _parse_ini_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
return config_content, options

@staticmethod
def _ini_file_with_sections(file_path: str) -> bool:
def _ini_file_with_sections(file_path: Path) -> bool:
"""Return whether the file uses sections."""
if "setup.cfg" in file_path:
if "setup.cfg" in file_path.parts:
return True
if "tox.ini" in file_path:
if "tox.ini" in file_path.parts:
return True
return False

Expand Down
3 changes: 3 additions & 0 deletions tests/config/functional/setup_cfg/issue_3630/not_setup.2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I should just print
************* Module Command line or configuration file
Command line or configuration file:1:0: E0013: Plugin 'pylint_flask' is impossible to load, is it installed ? ('No module named 'pylint_flask'') (bad-plugin-value)
12 changes: 12 additions & 0 deletions tests/config/functional/setup_cfg/issue_3630/not_setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# We load all sections as this is not a file that requires correct section headers
[tool.pylint.MASTER]
init-hook='print("I should just print")'

# We still load from pylint.
[pylint.MASTER]
load-plugins=pylint_flask

# We even load from section without pylint in their name
[FORMAT]
max-line-length=220
max-module-lines=2001
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"load_plugins": ["pylint_flask"],
"max_line_length": 220,
"max_module_lines": 2001
}
2 changes: 2 additions & 0 deletions tests/config/functional/setup_cfg/issue_3630/setup.2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
************* Module Command line or configuration file
Command line or configuration file:1:0: E0013: Plugin 'pylint_flask' is impossible to load, is it installed ? ('No module named 'pylint_flask'') (bad-plugin-value)
12 changes: 12 additions & 0 deletions tests/config/functional/setup_cfg/issue_3630/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Don't load from tool.pylint, we only support pylint.
[tool.pylint.MASTER]
init-hook='print("I should NOT print in setup.cfg we only parse 'pylint.'")'

# We do load from pylint.
[pylint.MASTER]
load-plugins=pylint_flask

# We don't load options from random sections
[FORMAT]
max-line-length=220
max-module-lines=2001
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"load_plugins": ["pylint_flask"]
}

0 comments on commit 15470d1

Please sign in to comment.