Skip to content

Commit

Permalink
Move the find_pylintrc function in find_default_config_files.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Oct 26, 2021
1 parent b659722 commit 17d6926
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
14 changes: 4 additions & 10 deletions pylint/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
from datetime import datetime

from pylint.config.configuration_mixin import ConfigurationMixIn
from pylint.config.find_default_config_files import find_default_config_files
from pylint.config.find_default_config_files import (
find_default_config_files,
find_pylintrc,
)
from pylint.config.man_help_formatter import _ManHelpFormatter
from pylint.config.option import Option
from pylint.config.option_manager_mixin import OptionsManagerMixIn
Expand Down Expand Up @@ -139,13 +142,4 @@ def save_results(results, base):
print(f"Unable to create file {data_file}: {ex}", file=sys.stderr)


def find_pylintrc():
"""search the pylint rc file and return its path if it find it, else None"""
for config_file in find_default_config_files():
if config_file.endswith("pylintrc"):
return config_file

return None


PYLINTRC = find_pylintrc()
11 changes: 10 additions & 1 deletion pylint/config/find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import configparser
import os
from typing import Iterator, Optional

import toml
from toml import TomlDecodeError
Expand Down Expand Up @@ -30,7 +31,7 @@ def _cfg_has_config(path):
return any(section.startswith("pylint.") for section in parser.sections())


def find_default_config_files():
def find_default_config_files() -> Iterator[str]:
"""Find all possible config files."""
rc_names = ("pylintrc", ".pylintrc")
config_names = rc_names + ("pyproject.toml", "setup.cfg")
Expand Down Expand Up @@ -67,3 +68,11 @@ def find_default_config_files():

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


def find_pylintrc() -> Optional[str]:
"""search the pylint rc file and return its path if it find it, else None"""
for config_file in find_default_config_files():
if config_file.endswith("pylintrc"):
return config_file
return None

0 comments on commit 17d6926

Please sign in to comment.