summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorMikhail f. Shiryaev <mr.felixoid@gmail.com>2023-04-30 22:48:34 +0200
committerGitHub <noreply@github.com>2023-04-30 22:48:34 +0200
commitf8288842e58a8b6007ff15ab380c84b00eb9b7a3 (patch)
tree727cd5397b5fa88d9fa3f0d7f55af36280911bc9 /pylint
parentc2ac6f1e905b263adb32102c87150a0c607e4db0 (diff)
downloadpylint-git-f8288842e58a8b6007ff15ab380c84b00eb9b7a3.tar.gz
Search for pyproject.toml config file in parent dirs (#7163)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com> Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
Diffstat (limited to 'pylint')
-rw-r--r--pylint/config/find_default_config_files.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/pylint/config/find_default_config_files.py b/pylint/config/find_default_config_files.py
index a121b32a3..3b03f6357 100644
--- a/pylint/config/find_default_config_files.py
+++ b/pylint/config/find_default_config_files.py
@@ -16,7 +16,28 @@ else:
import tomli as tomllib
RC_NAMES = (Path("pylintrc"), Path(".pylintrc"))
-CONFIG_NAMES = (*RC_NAMES, Path("pyproject.toml"), Path("setup.cfg"))
+PYPROJECT_NAME = Path("pyproject.toml")
+CONFIG_NAMES = (*RC_NAMES, PYPROJECT_NAME, Path("setup.cfg"))
+
+
+def _find_pyproject() -> Path:
+ """Search for file pyproject.toml in the parent directories recursively.
+
+ It resolves symlinks, so if there is any symlink up in the tree, it does not respect them
+ """
+ current_dir = Path.cwd().resolve()
+ is_root = False
+ while not is_root:
+ if (current_dir / PYPROJECT_NAME).is_file():
+ return current_dir / PYPROJECT_NAME
+ is_root = (
+ current_dir == current_dir.parent
+ or (current_dir / ".git").is_dir()
+ or (current_dir / ".hg").is_dir()
+ )
+ current_dir = current_dir.parent
+
+ return current_dir
def _toml_has_config(path: Path | str) -> bool:
@@ -100,6 +121,13 @@ def find_default_config_files() -> Iterator[Path]:
pass
try:
+ parent_pyproject = _find_pyproject()
+ if parent_pyproject.is_file() and _toml_has_config(parent_pyproject):
+ yield parent_pyproject.resolve()
+ except OSError:
+ pass
+
+ try:
yield from _find_config_in_home_or_environment()
except OSError:
pass