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

feat: Allow all config formats in all config locations #3769

Closed
wants to merge 7 commits into from

Conversation

danrneal
Copy link
Contributor

@danrneal danrneal commented Aug 8, 2020

Steps

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

Type of Changes

Type
✨ New feature
🔨 Refactoring
📜 Docs

This PR would allow a pylintrc, .pylintrc, pyproject.toml, or setup.cfg in any location that config files are stored. For example, currently pyproject.toml will only be read from the project root but not from the home directory. This PR would allow it to be read from the home directory. This is helpful when creating a global default config as other projects (such as isort) allow this config format in the home director. Let me know if this is a welcome change with or without revision or an unwelcome one.

@coveralls
Copy link

coveralls commented Aug 8, 2020

Coverage Status

Coverage increased (+0.1%) to 91.692% when pulling 13d3f4e on danrneal:allow-all-config-formats into d0591ba on PyCQA:master.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a welcome change, and a very important one, but also a very sensible one that could make a lot of CI/run fails if not done correctly. Could you add tests for this, please ? In particular for the get_config_path function. I'm also going to wait for another review before merging it for this reason.

pylint/config/find_default_config_files.py Outdated Show resolved Hide resolved
@danrneal danrneal force-pushed the allow-all-config-formats branch 3 times, most recently from 116425b to d573222 Compare September 7, 2020 00:21
@danrneal
Copy link
Contributor Author

danrneal commented Sep 7, 2020

I rebased onto master, added typing, and added a test case. Thanks for the input. Let me know if I need more tests or can improve in another way.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking my review into account. I don't have enough time right now to check that it's not breaking the current expected order of configuration file priority, Please don't hesitate to ping me if I still did not review it properly by october.

.gitignore Outdated Show resolved Hide resolved
pylint/config/find_default_config_files.py Outdated Show resolved Hide resolved
@danrneal
Copy link
Contributor Author

danrneal commented Sep 7, 2020

The only place it may break current order of priority is in the home folder. Previously it only looked for .pylintrc. Now it looks for pylintrc before .pylintrc. In fact it prioritizes configs in the same order in every location now. pylintrc, .pylintrc, pyproject.toml, and lastly for setup.cfg. I updated documentation with the PR to be more clear about priority as well.

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Needs review 🔍 Needs to be reviewed by one or multiple more persons labels Dec 31, 2020
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long time between first fast review and actual review. I don't see a problem here but I'm going to wait for another review before putting it in 2.7.0.

@Pierre-Sassoulas Pierre-Sassoulas added the Configuration Related to configuration label Feb 20, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.7.0 milestone Feb 20, 2021
@danrneal
Copy link
Contributor Author

Sounds good, just let me know of any feedback and/or changes needed :)

Copy link
Contributor

@hippo91 hippo91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danrneal thanks for this clear and welcomed PR!
I just have few comments/questions.

doc/user_guide/run.rst Outdated Show resolved Hide resolved
doc/user_guide/run.rst Outdated Show resolved Hide resolved
Comment on lines +105 to +108
#. ``pylintrc``
#. ``.pylintrc``
#. ``pyproject.toml``, provided it has at least one ``tool.pylint.`` section.
#. ``setup.cfg``, provided it has at least one ``pylint.`` section.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if two or more valid files are found in the same location?
Maybe the doc should explain this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added that they were listed in order or priority. So if .pylintrc and setup.cfg are in the same location it'll pick .pylintrc. Is that clearer or do I need to expand more than just the note?


if os.path.isfile("/etc/pylintrc"):
yield "/etc/pylintrc"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did the else statement disappear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the else is redundant when there is a yield or return statement inside and if block?

@Pierre-Sassoulas Pierre-Sassoulas added Waiting on author Indicate that maintainers are waiting for a message of the author and removed Needs review 🔍 Needs to be reviewed by one or multiple more persons labels Feb 21, 2021
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.7.0, 2.7.1 Feb 21, 2021
@Pierre-Sassoulas
Copy link
Member

I'm moving this to 2.7.1, I think it's addable as a minor feature later.

Copy link
Contributor

@AWhetter AWhetter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to jump in so late in the game. I don't think that it makes much sense to look for a pyproject.toml or a setup.cfg anywhere other than in the project because those files store metadata about a specific project. It's in the name of the pyproject file and in the PEP of the file (https://www.python.org/dev/peps/pep-0621/). Those files don't really belong outside of a project, so I can't think of a good reason to look for them anywhere other than the current directory.
Looking for a .pylintrc anywhere other than in the currently working directory also seems out of place. It makes sense to allow it in the current working directory because maybe you want to obscure it from view to keep the project tree looking tidy. But the directories ~/.config and /etc are the places for config files, so I can't think of a reason why you would want to obscure a config file from view in those places.

Side note: For a while I've been feeling like the config system in pylint is not great and it needs a bit of attention. The code itself is pretty unwieldy and I think the user experience of configuration isn't great either. Changes like this make me nervous because some day we'll want to give the configuration the attention it deserves, but that means making breaking changes. So I'd rather not expand the bounds of the configuration system too much so that aren't breaking as much for people later on and so we can focus more on what the config system should do, rather than needing to worry about what we might break.

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Feb 22, 2021

@AWhetter I agree that the configuration need to be redesigned and that we don't want to have too much to break when we do that. I also agree pyproject.toml or setup.cfg makes no sense outside of the current project directory and you convinced me we should not start maintaining and documenting things that do not make sense (especially considering the fact that we had two possible names for pylintrc already .pylintrc and pylintrc).

But isn't etc/ or ~/.config the right place for a global pylint configuration used for all projects on a computer ? I was thinking of maybe using confuse for the configuration redesign and they put their configuration file in XDG_CONFIG_HOME :

Look for configuration files in platform-specific paths. Like $XDG_CONFIG_HOME or ~/.config on Unix; “Application Support” on macOS; %APPDATA% on Windows. Your program gets its own directory, which you can use to store additional data. You can transparently create this directory on demand if, for example, you need to initialize the configuration file on first run. And an environment variable can be used to override the directory’s location.

Source: https://pypi.org/project/confuse/

@AWhetter
Copy link
Contributor

But isn't etc/ or ~/.config the right place for a global pylint configuration used for all projects on a computer

Yes absolutely! I like both of these places for a pylintrc file. But not for .pylintrc, pyproject.toml, or setup.cfg.

@Pierre-Sassoulas
Copy link
Member

I think the pylintrc could also be global ? For example you have a default value in pylint, you can change it in etc/ with a pylintrc file, then you can change both in your repository with the local file. I get it would means we need an option for a local config to signal that it's bypassing the global config for all value and define pylint's default unless explicitly overridden. Or do you want to change the name of the file during the refactor ?

@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.7.1, 2.7.2 Feb 23, 2021
@AWhetter
Copy link
Contributor

Yes that's what I meant. pylintrc should be global. .pylintrc, pyproject.toml, and setup.cfg should no be global.

I definitely think that config inheritance is something that we should consider in the future, but we shouldn't implement it now.

@danrneal
Copy link
Contributor Author

Both isort and black stop going up directories when they get to a .git or .hg directory. But the use case for having a single config for isort, pylint, and black in the home directory is for coding that isn't part of a project. If you had a global default pyproject.toml then your code can still be linted and checked for style even if your code is not part of a project.

I can address the comments in the PR and get it back into ship shape. However, if this isn't the direction to go in, then there probably isn't a lot of value in me doing that. I'll wait for more discussion.

@Pierre-Sassoulas Pierre-Sassoulas removed the Waiting on author Indicate that maintainers are waiting for a message of the author label Apr 10, 2021
@Pierre-Sassoulas
Copy link
Member

I think we could mirror what isort and black do, what do you think @AWhetter ? Maybe we need to refactor this for 3.0 as a real breaking change ?

@Pierre-Sassoulas Pierre-Sassoulas removed this from the 2.9.0 milestone May 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.14.0 milestone Jan 10, 2022
@Pierre-Sassoulas Pierre-Sassoulas mentioned this pull request Mar 31, 2022
2 tasks
@Pierre-Sassoulas
Copy link
Member

I'm going to close as we're going to move to non global configuration files. Thank you for your contribution and sorry for being indecisive @danrneal

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

Successfully merging this pull request may close these issues.

5 participants