diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst index d0f64f790a..34ebdc50c8 100644 --- a/doc/whatsnew/2/2.14/full.rst +++ b/doc/whatsnew/2/2.14/full.rst @@ -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 diff --git a/pylint/config/config_file_parser.py b/pylint/config/config_file_parser.py index 3d76949561..b6809d9847 100644 --- a/pylint/config/config_file_parser.py +++ b/pylint/config/config_file_parser.py @@ -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": @@ -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 diff --git a/tests/config/functional/setup_cfg/issue_3630/not_setup.2.out b/tests/config/functional/setup_cfg/issue_3630/not_setup.2.out new file mode 100644 index 0000000000..1e104d8f89 --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/not_setup.2.out @@ -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) diff --git a/tests/config/functional/setup_cfg/issue_3630/not_setup.cfg b/tests/config/functional/setup_cfg/issue_3630/not_setup.cfg new file mode 100644 index 0000000000..87d19d6812 --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/not_setup.cfg @@ -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 diff --git a/tests/config/functional/setup_cfg/issue_3630/not_setup.result.json b/tests/config/functional/setup_cfg/issue_3630/not_setup.result.json new file mode 100644 index 0000000000..799f47e826 --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/not_setup.result.json @@ -0,0 +1,5 @@ +{ + "load_plugins": ["pylint_flask"], + "max_line_length": 220, + "max_module_lines": 2001 +} diff --git a/tests/config/functional/setup_cfg/issue_3630/setup.2.out b/tests/config/functional/setup_cfg/issue_3630/setup.2.out new file mode 100644 index 0000000000..39887eed3a --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/setup.2.out @@ -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) diff --git a/tests/config/functional/setup_cfg/issue_3630/setup.cfg b/tests/config/functional/setup_cfg/issue_3630/setup.cfg new file mode 100644 index 0000000000..26ade91eed --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/setup.cfg @@ -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 diff --git a/tests/config/functional/setup_cfg/issue_3630/setup.result.json b/tests/config/functional/setup_cfg/issue_3630/setup.result.json new file mode 100644 index 0000000000..091cf1e7b8 --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/setup.result.json @@ -0,0 +1,3 @@ +{ + "load_plugins": ["pylint_flask"] +}