Skip to content
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

load-plugins not working if configured in setup.cfg [pylint.MASTER] #4272

Closed
mteiste opened this issue Mar 31, 2021 · 6 comments · Fixed by #6335
Closed

load-plugins not working if configured in setup.cfg [pylint.MASTER] #4272

mteiste opened this issue Mar 31, 2021 · 6 comments · Fixed by #6335
Labels
Bug 🪲 Configuration Related to configuration
Milestone

Comments

@mteiste
Copy link

mteiste commented Mar 31, 2021

load_plugins option does not work if defined in [pylint.MASTER] section of setup.cfg

Steps to reproduce

Given a config file setup.cfg

[pylint.MASTER]
load_plugins=pylint.extensions.bad_builtin
[pylint.DEPRECATED_BUILTINS]
bad-functions=print

and a python file a.py

print("Hello World!")

Current behavior

Result of `pylint --rcfile=setup.cfg a.py

************* Module a
a.py:1:0: C0114: Missing module docstring (missing-module-docstring)

-----------------------------------
Your code has been rated at 0.00/10

Expected behavior

************* Module a
a.py:1:0: C0114: Missing module docstring (missing-module-docstring)
a.py:1:0: W0141: Used builtin function 'print' (bad-builtin)

---------------------------------------------------------------------
Your code has been rated at -10.00/10

pylint --version output

Result of pylint --version output:

pylint 2.7.4
astroid 2.5.2
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0]
@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 Configuration Related to configuration labels Apr 1, 2021
@cdce8p
Copy link
Member

cdce8p commented Apr 1, 2021

If you use setup.cfg the correct config should be

[MASTER]
load-plugins=pylint.extensions.bad_builtin

[pylint.DEPRECATED_BUILTINS]
bad-functions=print

Notice that it's only [MASTER] not [pylint.MASTER]

You could also use pyproject.toml. In that case, this would be the correct config

[tool.pylint.MASTER]
load-plugins= "pylint.extensions.bad_builtin"

[tool.pylint.DEPRECATED_BUILTINS]
bad-functions= ["print"]

Here you shouldn't need to specify the --rcfile option.

@cdce8p cdce8p mentioned this issue Apr 1, 2021
4 tasks
@mteiste
Copy link
Author

mteiste commented Apr 1, 2021

Not argument from me against using toml. Just that "setup.cfg" support is a bit patchy and confusing (using [pylint.master]as the section does work). Actually the only config values that are affected by this are load-plugins and init-hook.

I just assumed that only sections marked with pylint.* would be the ones pylint uses and it would ignore any other sections that are not specifically marked for pylint.

@mteiste
Copy link
Author

mteiste commented Apr 1, 2021

There is also an other slightly nasty side effect from this. If you have setup.cfg with sections for other tools that use same option names those will be taken in by pylint. For example the following setup.cfg

[MASTER]
load-plugins=pylint.extensions.bad_builtin

[pylint.DEPRECATED_BUILTINS]
bad-functions=print

[pycodestyle]
ignore=E722,W503

has the effect of setting pylint's exclude to E722,W503, hence there is a lot of possibilities to have hard to find configuration problems when using setup.cfg.

@cdce8p
Copy link
Member

cdce8p commented Apr 1, 2021

I almost always use a pylintrc file for my pylint config, not setup.cfg
As for the pylint. prefix, I think this isn't used because it should be a separate file. Could be wrong though, maybe @Pierre-Sassoulas knows more?

@mteiste
Copy link
Author

mteiste commented Apr 1, 2021

True, there are workarounds / arguably better options, just commenting that the current support for setup.cfg is slightly confusing. Apart from not ignoring sections not marked with pylint, using lowercase for all the pylint.sections actually works as expected (due to how the section title normalization is implemented in OptionManagerMixin::read_config_file()).

@Pierre-Sassoulas
Copy link
Member

Thank you for the issue @mteiste, evidentely setup.cfg is not super well supported.

I did not modify a lot of configuration code, but I think we'd get some benefit of having a single standardized point of entry like flake8 (ask for pyproject.toml or setup.cfg support here, see how fast assotile closes the issue 😄 ). @AWhetter convinced me that actually merging #3769 would be shooting ourselves in the foot. Maybe we need to consider a breaking change in 3.0.0 where we only support .pylintrc and local pyproject.toml

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 15, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 16, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 16, 2022
Closes pylint-dev#4272. The problem was fixed during the migration from optparse
to argparse.
@DanielNoord DanielNoord added this to the 2.14.0 milestone May 5, 2022
Pierre-Sassoulas added a commit that referenced this issue May 5, 2022
…ing silently (#6335)

* Regression tests for #4272

Closes #4272. The problem was fixed during the migration from optparse
to argparse.

Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Configuration Related to configuration
Projects
None yet
4 participants