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

pylint not finding the tox.ini config #9727

Closed
rlalik opened this issue Jun 12, 2024 · 12 comments · Fixed by #9728 or #9940
Closed

pylint not finding the tox.ini config #9727

rlalik opened this issue Jun 12, 2024 · 12 comments · Fixed by #9728 or #9940
Labels
Enhancement ✨ Improvement to a component
Milestone

Comments

@rlalik
Copy link

rlalik commented Jun 12, 2024

Bug description

According to documentation: https://pylint.readthedocs.io/en/v3.2.3/user_guide/usage/run.html
pylint should be able to find tox.ini and use configuration from it.

In my case however it is not doing it. It works if I explicitely ask to use tox.ini with --rcfile.

Configuration

[tox]
env_list =
    py313
    py312
    py311
    py310
    py39
    py38
    type
    linter
    flake8

[testenv]
deps = -r {toxinidir}/requirements_test.txt
commands = pytest

[testenv:flake8]
deps = -r {toxinidir}/requirements_test.txt
commands = flake8

[flake8]
exclude = .tox,tests
max-line-length = 120


[testenv:type]
deps = -r {toxinidir}/requirements_test.txt
commands = mypy --ignore-missing-imports .

[testenv:pylint]
deps = pylint
commands = pylint *.py

[pylint]
disable = C0114,C0115,C0116

Command used

pylint fraction.py -v

Pylint output

No config file found, using default configuration
************* Module fraction
fraction.py:1:0: C0114: Missing module docstring (missing-module-docstring)
fraction.py:4:0: C0115: Missing class docstring (missing-class-docstring)
fraction.py:63:4: C0116: Missing function or method docstring (missing-function-docstring)
fraction.py:66:4: C0116: Missing function or method docstring (missing-function-docstring)

---------------------------------------------------------------------------------------------------
Your code has been rated at 9.02/10 (previous run: 9.02/10, +0.00)
Checked 1 files, skipped 1 files

Expected behavior

Same as using with --rcfile:

$ pylint fraction.py -v --rcfile=tox.ini
Using config file tox.ini

----------------------------------------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 9.02/10, +0.98)
Checked 1 files, skipped 1 files

Pylint version

pylint 3.2.3
astroid 3.2.2
Python 3.12.3 (main, May 22 2024, 16:56:59) [GCC 13.3.0]

OS / Environment

Gentoo

Additional dependencies

No response

@rlalik rlalik added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 12, 2024
@mbyrnepr2
Copy link
Member

mbyrnepr2 commented Jun 12, 2024

Hi! I don’t know for certain what is going on but the docs also say that without the rcfile option, Pylint will use the first configuration file it can find, based on a specific order mentioned in same doc page.
So, do you also have, for example, a pyproject.toml file in the current directory which is getting picked up instead of the tox.ini because of the precedence?
Edit: just noticed the message says no config is found😅

@mbyrnepr2 mbyrnepr2 added Bug 🪲 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jun 12, 2024
@mbyrnepr2
Copy link
Member

Need to verify when not on mobile but it could be because the config needs to be [pylint.main]

@mbyrnepr2 mbyrnepr2 added Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Bug 🪲 labels Jun 12, 2024
@rlalik
Copy link
Author

rlalik commented Jun 12, 2024

I've checked options 1-5 from doc by putting dummy files and the config file is detected properly. I skipped setup.cfg. In my project there are no files from 1-6 which could be read before. If there was, the pylint would display it like this:

$ touch .pylintrc
$ pylint -v fraction
Using config file (...)/.pylintrc

So I assume it is not able to detect tox.ini.

Also, I tried [pylint] and [pylint.main]. According to

if ini_file_with_sections and not section.startswith("pylint"):
it looks for anything starting with pylint. I also tried with dummy setup.cfg where I just copied tox.ini as setup.cfg and the result was the same.

@mbyrnepr2 mbyrnepr2 added Bug 🪲 and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Jun 12, 2024
@mbyrnepr2
Copy link
Member

Thanks @rlalik for the details. Makes perfect sense and I see what is missing from the code now. PR coming.

mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Jun 12, 2024
…red and it exists in the current directory.

Closes pylint-dev#9727
@rlalik
Copy link
Author

rlalik commented Jun 12, 2024

I think you still might have issuie with setup.cfg:

$ cp tox.ini setup.cfg
$ pylint fraction.py -v
No config file found, using default configuration
$ pylint fraction.py -v --rcfile=setup.cfg 
Using config file setup.cfg

By looking at your PR it seems that is not fixing it.

@mbyrnepr2
Copy link
Member

I think you still might have issuie with setup.cfg:

$ cp tox.ini setup.cfg
$ pylint fraction.py -v
No config file found, using default configuration
$ pylint fraction.py -v --rcfile=setup.cfg 
Using config file setup.cfg

By looking at your PR it seems that is not fixing it.

I can't reproduce that unfortunately. Does your tox.ini have a valid configuration section ([pylint])?

@rlalik
Copy link
Author

rlalik commented Jun 12, 2024

$ cp tox.ini setup.cfg
$ grep "\[pylint\]" setup.cfg -A 5
37:[pylint]
38-disable = C0114,C0115,C0116
39-

$ pylint fraction.py -v
No config file found, using default configuration

So unless setup.cfg must be a valid setuptools file, if it is only required to have [pylint] then it is not working.

@mbyrnepr2
Copy link
Member

mbyrnepr2 commented Jun 12, 2024

I see the problem - .cfg and .ini config files' config need to begin with pylint. (note the dot and that's also mentioned in the documentation). So something like [pylint.main] is expected there; I can reproduce your issue with [pylint] but not [pylint.main].

@rlalik
Copy link
Author

rlalik commented Jun 12, 2024

So, is it something else than in this line:

if ini_file_with_sections and not section.startswith("pylint"):
?

@rlalik
Copy link
Author

rlalik commented Jun 12, 2024

And it works with [pylint] and --rcfile for both tox.ini and setup.cfg. So there must be some other issue about autodetection?

@rlalik
Copy link
Author

rlalik commented Jun 12, 2024

And it says the same for e.g. pylintrc.toml but works without dot as well:

$ cat pylintrc.toml 
[tool.pylint]
disable = ["C0114", "C0115", "C0116"]

$ pylint fraction.py -v
Using config file (...)/pylintrc.toml

@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.3.0 milestone Jun 12, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component and removed Bug 🪲 labels Jun 12, 2024
@mbyrnepr2
Copy link
Member

Thanks again @rlalik. Good feedback.
If you have time please check out the new changes and see if it hits the right notes 👍

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
3 participants