-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Allow all config formats in all config locations #3769
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e7a79bf
feat: Allow all config formats in all config locations
danrneal d866dfa
Upgrade the documentation
Pierre-Sassoulas 1869189
Update run.rst
danrneal 1a94758
Update run.rst
danrneal ad67baf
Merge branch 'master' into allow-all-config-formats
danrneal e7d1f5e
Update run.rst
danrneal 13d3f4e
fix pyupgrade precommit
danrneal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
import configparser | ||
import os | ||
from pathlib import Path | ||
from typing import Generator, List, Union | ||
|
||
import toml | ||
from toml.decoder import TomlDecodeError | ||
|
@@ -30,40 +32,40 @@ def _cfg_has_config(path): | |
return any(section.startswith("pylint.") for section in parser.sections()) | ||
|
||
|
||
def find_default_config_files(): | ||
"""Find all possible config files.""" | ||
rc_names = ("pylintrc", ".pylintrc") | ||
config_names = rc_names + ("pyproject.toml", "setup.cfg") | ||
def _get_config_paths(curdir: Union[Path, str]) -> List[str]: | ||
paths = [] | ||
config_names = ("pylintrc", ".pylintrc", "pyproject.toml", "setup.cfg") | ||
for config_name in config_names: | ||
if os.path.isfile(config_name): | ||
if config_name.endswith(".toml") and not _toml_has_config(config_name): | ||
config_path = os.path.join(curdir, config_name) | ||
if os.path.isfile(config_path): | ||
if config_name.endswith(".toml") and not _toml_has_config(config_path): | ||
continue | ||
if config_name.endswith(".cfg") and not _cfg_has_config(config_name): | ||
if config_name.endswith(".cfg") and not _cfg_has_config(config_path): | ||
continue | ||
|
||
yield os.path.abspath(config_name) | ||
paths.append(config_path) | ||
|
||
return paths | ||
|
||
|
||
def find_default_config_files() -> Generator: | ||
"""Find all possible config files.""" | ||
yield from _get_config_paths(os.path.abspath(".")) | ||
|
||
if os.path.isfile("__init__.py"): | ||
curdir = os.path.abspath(os.getcwd()) | ||
while os.path.isfile(os.path.join(curdir, "__init__.py")): | ||
curdir = os.path.abspath(os.path.join(curdir, "..")) | ||
for rc_name in rc_names: | ||
rc_path = os.path.join(curdir, rc_name) | ||
if os.path.isfile(rc_path): | ||
yield rc_path | ||
yield from _get_config_paths(curdir) | ||
|
||
if "PYLINTRC" in os.environ and os.path.exists(os.environ["PYLINTRC"]): | ||
if os.path.isfile(os.environ["PYLINTRC"]): | ||
yield os.environ["PYLINTRC"] | ||
else: | ||
user_home = os.path.expanduser("~") | ||
if user_home not in ("~", "/root"): | ||
home_rc = os.path.join(user_home, ".pylintrc") | ||
if os.path.isfile(home_rc): | ||
yield home_rc | ||
home_rc = os.path.join(user_home, ".config", "pylintrc") | ||
if os.path.isfile(home_rc): | ||
yield home_rc | ||
|
||
if os.path.isfile("/etc/pylintrc"): | ||
yield "/etc/pylintrc" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
user_home = os.path.expanduser("~") | ||
if user_home not in ("~", "/root"): | ||
yield from _get_config_paths(user_home) | ||
yield from _get_config_paths(os.path.join(user_home, ".config")) | ||
|
||
curdir = os.path.abspath("/etc") | ||
yield from _get_config_paths(curdir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?