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

Search pylint configuration in setup.cfg and pyproject.toml #617

Closed
pylint-bot opened this issue Aug 6, 2015 · 23 comments · Fixed by #3169
Closed

Search pylint configuration in setup.cfg and pyproject.toml #617

pylint-bot opened this issue Aug 6, 2015 · 23 comments · Fixed by #3169
Labels
Enhancement ✨ Improvement to a component

Comments

@pylint-bot
Copy link

Originally reported by: Fabio C. Barrionuevo da Luz (BitBucket: luzfcb, GitHub: @luzfcb?)


It would be great if pylint also seek the settings in a special section in setup.cfg file.

the same reasons as described by @bittner in
https://bitbucket.org/logilab/pylint/issues/121/search-pylintrc-in-config-directory#comment-13136390


@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Why? This would complicate the configuration parsing and requires a lot of work to accommodate the internal implementation for little benefit. It will be yet another way to look for the configuration options, which increases the maintenance burden. And it will not be obvious where pylint will look first, in the setup.cfg or in pylintrc.

@pylint-bot
Copy link
Author

Original comment by Fabio C. Barrionuevo da Luz (BitBucket: luzfcb, GitHub: @luzfcb?):


if the "pylintrc" file exist, stop search and get settings .

if the "pylintrc" file does not exist, verify that "setup.cfg" file exists.

If "setup.cfg" exist, get the settings.

if "pylintrc" file and "setup.cfg" exist, ignore "setup.cfg"

to make obvious what order the pylint use, just enter in the documentation something like:

pylint seeks the configuration file in the following order:

1 - project_dir/pylintrc
2 - project_dir/setup.cfg 
3 - ~/.pylintrc
4 - foo another location

@pylint-bot
Copy link
Author

Original comment by Peter Bittner (BitBucket: bittner, GitHub: @bittner?):


JFYI, I had prepared pull request #276 to implement those changes. It was rejected, though.

@matrixik
Copy link

https://github.com/python/mypy added support for setup.cfg in python/mypy#2761

@sobolevn
Copy link
Contributor

sobolevn commented Feb 3, 2018

setup.cfg should be the default place to configure things.

@NeilGirdhar
Copy link

@PCManticore It might be good to take a look at this again if you haven't recently.

@PCManticore
Copy link
Contributor

If pylint should support an additional format, that should be pyproject.toml not setup.cfg. setup.cfg doesn't seem to support nested sections, as our INI structure does, unless I'm missing something.

@sobolevn
Copy link
Contributor

sobolevn commented Sep 22, 2018

@PCManticore it is possible via something like this:

[pytest]
general_options = ...

[pytest.messages]
messages = ...

But supporting pyproject.toml is a good thing too.

@PCManticore
Copy link
Contributor

If that's the case then, I don't mind supporting setup.cfg and pyproject.toml.

@PCManticore PCManticore reopened this Sep 22, 2018
@pradyunsg
Copy link

@PCManticore Could you update the issue title to reflect the current plan moving forward?

heilaaks added a commit to heilaaks/snippy that referenced this issue May 12, 2019
Test tools Pylint, Flake8 and Bandit configurations were
simplified.

The Pylint configuration was a long default configuration
that contained all the options with most of the options
in default values. There was also a separate files for the
tests and snippy source code. Now only the needed options
are configured and the files are merged to one default
file 'pylintrc'.

The Flake8 configuration was moved to setup.cfg to remove
own configuration file.

The result files for Pylint and Bandit were removed. This
was not a good idea in the past.

The configuration should be read from pyproject.toml. But
the tools do not yet support this feature.

[1] pylint-dev/pylint#617
[2] https://gitlab.com/pycqa/flake8/issues/428
[3] pytest-dev/pytest#1556

Signed-off-by: Heikki Laaksonen <[email protected]>
@flying-sheep
Copy link
Contributor

@PCManticore should we file a new issue for pyproject.toml or will you update the title for this one?

@PCManticore PCManticore changed the title search pylint configuration in setup.cfg too Search pylint configuration in setup.cfg and pyproject.toml Sep 25, 2019
@PCManticore
Copy link
Contributor

@flying-sheep Done! Thanks again for the reminder.

AWhetter added a commit that referenced this issue Oct 7, 2019
AWhetter added a commit that referenced this issue Oct 7, 2019
AWhetter added a commit that referenced this issue Oct 7, 2019
AWhetter added a commit that referenced this issue Oct 8, 2019
AWhetter added a commit that referenced this issue Oct 10, 2019
AWhetter added a commit that referenced this issue Oct 10, 2019
AWhetter added a commit that referenced this issue Oct 10, 2019
@fgimian
Copy link

fgimian commented Oct 13, 2019

Huge thanks for supporting this. Just one little thought. Since TOML is more advanced than INI, you could actually support a list of disables for message control like so:

[tool.pylint."messages control"]
disable = [
    "too-many-ancestors",
    "too-many-arguments",
    "too-many-boolean-expressions",
    "too-many-branches",

I believe this would be more elegant than a comma separated list in TOML personally. What do you think?

It may also be worth replacing underscores with spaces in section headings so we could do this:

[tool.pylint.messages_control]
disable = [
    "too-many-ancestors",
    "too-many-arguments",
    "too-many-boolean-expressions",
    "too-many-branches",

Huge love
Fotis

@laike9m
Copy link
Contributor

laike9m commented Oct 14, 2019

Huge thanks for supporting this. Just one little thought. Since TOML is more advanced than INI, you could actually support a list of disables for message control like so:

[tool.pylint."messages control"]
disable = [
    "too-many-ancestors",
    "too-many-arguments",
    "too-many-boolean-expressions",
    "too-many-branches",

I believe this would be more elegant than a comma separated list in TOML personally. What do you think?

It may also be worth replacing underscores with spaces in section headings so we could do this:

[tool.pylint.messages_control]
disable = [
    "too-many-ancestors",
    "too-many-arguments",
    "too-many-boolean-expressions",
    "too-many-branches",

Huge love
Fotis

@fgimian It seems the list version does not work, but this does
I misunderstand your comment. Yes, I think the list form should be supported.

After some trials and errors, I found this works

[tool.pylint.messages_control]
disable = "bad-continuation"

This also works

[tool.pylint.'MESSAGES CONTROL']
disable = "bad-continuation"

@impredicative
Copy link

impredicative commented Nov 30, 2019

Does anyone have a decent working example of pylint configuration in pyproject.toml and/or setup.cfg, or does everyone have to trial-and-error their way around it?

Also, why was support for this implemented without an option for --generate-rcfile to generate a sample config in the above formats?

@laike9m
Copy link
Contributor

laike9m commented Nov 30, 2019

@impredicative https://github.com/laike9m/Cyberbrain/blob/master/pyproject.toml#L41-L45
Took me quite a while to figure out.

@AWhetter
Copy link
Contributor

Also, why was support for this implemented without an option for --generate-rcfile to generate a sample config in the above formats?

This is a good suggestion! Feel free to make a separate issue for it.

@HitLuca
Copy link

HitLuca commented Mar 24, 2020

It seems that pylint correctly parses the [tool.pylint.messages_control] section from setup.cfg, but fails to also parse [tool.pylint.logging] and [tool.pylint.master]

@HitLuca
Copy link

HitLuca commented Mar 27, 2020

@laike9m please make sure that if you are using this structure for your entries in pyproject.toml

disable = """,
    bad-continuation,
    wrong-import-position,
    invalid-name,
    line-too-long,
    too-few-public-methods,
    import-outside-toplevel,
    logging-format-interpolation,
    """

you add a comma after the first three double quotes, otherwise the first message won't be disabled. Similarly, add a comma after the last message for the same reason

@K3UL
Copy link

K3UL commented May 22, 2020

For anyone looking for examples with pyproject.toml, here is a suggestion ; it is simple but took me a minute before thinking of it :
https://github.com/search?l=TOML&q="tool.pylint"&type=Code

@alexchandel
Copy link

pylint fails to find init-hook in setup.cfg.

@su1hang2
Copy link

for others looking for how to include an init-hook in setup.cfg: it worked after I took out the quotes around the command, e.g. in my case it was

[pylint.master]
init-hook = import sys; sys.path.append("/your/path/here");

@fgimian
Copy link

fgimian commented Jul 17, 2021

I'm not sure when this happened, but pylint now seems to support lists in message_control. Here's an excerpt of my pyproject.toml if it helps anyone.

[tool.pylint.basic]
# Allow shorter and longer variable names than the default.
argument-rgx = "[a-z_][a-z0-9_]*$"
attr-rgx = "[a-z_][a-z0-9_]*$"
variable-rgx = "[a-z_][a-z0-9_]*$"

# Ensure that orjson is analysed as a C extension by pylint.
extension-pkg-whitelist = "orjson"

[tool.pylint.messages_control]
disable = [
    # Disable too many and too few checks.
    "too-many-ancestors",
    "too-many-arguments",
    "too-many-boolean-expressions",
    "too-many-branches",
    "too-many-function-args",
    "too-many-instance-attributes",
    "too-many-lines",
    "too-many-locals",
    "too-many-nested-blocks",
    "too-many-public-methods",
    "too-many-return-statements",
    "too-many-statements",
    "too-few-public-methods",

    # Similar lines in files (often the case in tests).
    "duplicate-code",

    # Many functions (e.g. callbacks) will naturally have unused arguments.
    "unused-argument",

    # Disable checking that method could be a function in classes (often used for organisation).
    "no-self-use",

    # Disable failure for TODO items in the codebase (code will always have TODOs).
    "fixme",

    # Disable docstrings checks as we don't require excessive documentation.
    "missing-docstring"
]

[tool.pylint.format]
# Maximum number of characters on a single line.
max-line-length = 99

And yup, I find the defaults in pylint too noisy 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging a pull request may close this issue.