Skip to content

Commit 15470d1

Browse files
Fix recognition of config files named setup.cfg (#3630) (#6577)
Co-authored-by: Daniël van Noord <[email protected]>
1 parent e820200 commit 15470d1

File tree

8 files changed

+47
-4
lines changed

8 files changed

+47
-4
lines changed

doc/whatsnew/2/2.14/full.rst

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Release date: TBA
2727

2828
Closes #6965
2929

30+
* Fixed an issue with the recognition of ``setup.cfg`` files.
31+
Only ``.cfg`` files that are exactly named ``setup.cfg`` require section names that
32+
start with ``pylint.``.
33+
34+
Closes #3630
35+
3036
* Don't report ``import-private-name`` for relative imports.
3137

3238
Closes #7078

pylint/config/config_file_parser.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _parse_ini_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
4242
config_content: dict[str, str] = {}
4343
options: list[str] = []
4444
for section in parser.sections():
45-
if self._ini_file_with_sections(str(file_path)) and not section.startswith(
45+
if self._ini_file_with_sections(file_path) and not section.startswith(
4646
"pylint"
4747
):
4848
if section.lower() == "master":
@@ -61,11 +61,11 @@ def _parse_ini_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
6161
return config_content, options
6262

6363
@staticmethod
64-
def _ini_file_with_sections(file_path: str) -> bool:
64+
def _ini_file_with_sections(file_path: Path) -> bool:
6565
"""Return whether the file uses sections."""
66-
if "setup.cfg" in file_path:
66+
if "setup.cfg" in file_path.parts:
6767
return True
68-
if "tox.ini" in file_path:
68+
if "tox.ini" in file_path.parts:
6969
return True
7070
return False
7171

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
I should just print
2+
************* Module Command line or configuration file
3+
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# We load all sections as this is not a file that requires correct section headers
2+
[tool.pylint.MASTER]
3+
init-hook='print("I should just print")'
4+
5+
# We still load from pylint.
6+
[pylint.MASTER]
7+
load-plugins=pylint_flask
8+
9+
# We even load from section without pylint in their name
10+
[FORMAT]
11+
max-line-length=220
12+
max-module-lines=2001
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"load_plugins": ["pylint_flask"],
3+
"max_line_length": 220,
4+
"max_module_lines": 2001
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
************* Module Command line or configuration file
2+
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Don't load from tool.pylint, we only support pylint.
2+
[tool.pylint.MASTER]
3+
init-hook='print("I should NOT print in setup.cfg we only parse 'pylint.'")'
4+
5+
# We do load from pylint.
6+
[pylint.MASTER]
7+
load-plugins=pylint_flask
8+
9+
# We don't load options from random sections
10+
[FORMAT]
11+
max-line-length=220
12+
max-module-lines=2001
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"load_plugins": ["pylint_flask"]
3+
}

0 commit comments

Comments
 (0)