Skip to content

Commit ce4b166

Browse files
committed
Search for config files in parent dirs
1 parent 2e2f8f8 commit ce4b166

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

.pyenchant_pylint_custom_dict.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pylint
252252
pylintdict
253253
pylintrc
254254
pylint's
255+
pyproject
255256
pypy
256257
pyreverse
257258
pytest
@@ -305,6 +306,8 @@ subtree
305306
supcls
306307
superclass
307308
symilar
309+
symlink
310+
symlinks
308311
sys
309312
tbump
310313
tempfile

doc/user_guide/usage/run.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ configuration file in the following order and uses the first one it finds:
8787
in on the command line.
8888
#. ``setup.cfg`` in the current working directory,
8989
providing it has at least one ``pylint.`` section
90+
#. Pylint will search for the ``pyproject.toml`` file up the directories hierarchy
91+
until the root and will use the first met. Usually it placed in the project repository.
9092
#. If the current working directory is in a Python package, Pylint searches \
9193
up the hierarchy of Python packages until it finds a ``pylintrc`` file. \
9294
This allows you to specify coding standards on a module-by-module \

pylint/config/find_default_config_files.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
CONFIG_NAMES = RC_NAMES + (Path("pyproject.toml"), Path("setup.cfg"))
2121

2222

23+
def _find_config_in_tree(path: Path) -> Path:
24+
"""Search for file pyproject.toml in the parent directories recursively. It resolves
25+
symlinks, so if there is any symlink up in the tree, it does not respect them"""
26+
current_dir = Path.cwd().resolve()
27+
is_root = False
28+
while not is_root:
29+
if (current_dir / path).is_file():
30+
return current_dir / path
31+
is_root = (
32+
current_dir == current_dir.parent
33+
or (current_dir / ".git").is_dir()
34+
or (current_dir / ".hg").is_dir()
35+
)
36+
current_dir = current_dir.parent
37+
38+
return current_dir
39+
40+
2341
def _toml_has_config(path: Path | str) -> bool:
2442
with open(path, mode="rb") as toml_handle:
2543
try:
@@ -42,6 +60,7 @@ def _cfg_has_config(path: Path | str) -> bool:
4260
def find_default_config_files() -> Iterator[Path]:
4361
"""Find all possible config files."""
4462
for config_name in CONFIG_NAMES:
63+
config_name = _find_config_in_tree(config_name)
4564
if config_name.is_file():
4665
if config_name.suffix == ".toml" and not _toml_has_config(config_name):
4766
continue

0 commit comments

Comments
 (0)