Skip to content

Commit 6a5b411

Browse files
author
Aleksey Petryankin
committed
Unify use-parent-configs and use-local-configs
1 parent 66f2cf1 commit 6a5b411

File tree

5 files changed

+10
-37
lines changed

5 files changed

+10
-37
lines changed

doc/user_guide/configuration/all-options.rst

+1-10
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,7 @@ Standard Checkers
218218

219219
--use-local-configs
220220
"""""""""""""""""""
221-
*When some of the linted files or modules have pylint config in the same directory, use their local configs for checking these files.*
222-
223-
**Default:** ``False``
224-
225-
226-
--use-parent-configs
227-
""""""""""""""""""""
228-
*Search for local pylint configs up until current working directory or root.*
221+
*When some of the linted modules have a pylint config in the same directory (or one of the parent directories), use this config for checking these files.*
229222

230223
**Default:** ``False``
231224

@@ -301,8 +294,6 @@ Standard Checkers
301294
302295
use-local-configs = false
303296
304-
use-parent-configs = false
305-
306297
307298
308299
.. raw:: html

doc/whatsnew/fragments/618.feature

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
Add 2 new command line options: use-local-configs and use-parent-configs.
1+
Add new command line option: use-local-configs.
22

3-
use-local-configs enables searching for local pylint configurations in the same directory where linted file is located.
3+
use-local-configs enables searching for local pylint configurations in the same directory where linted file is located and upwards until $PWD or root.
44
For example:
55
if there exists package/pylintrc, then
66
pylint --use-local-configs=y package/file.py
77
will use package/pylintrc instead of default config from $PWD.
88

9-
use-parent-configs enables searching for local pylint configurations upwards from the directory where linted file is located.
10-
For example:
119
if there exists package/pylintrc, and doesn't exist package/subpackage/pylintrc, then
12-
pylint --use-local-configs=y --use-parent-configs=y package/subpackage/file.py
10+
pylint --use-local-configs=y package/subpackage/file.py
1311
will use package/pylintrc instead of default config from $PWD.
1412

1513
Closes #618

pylint/lint/base_options.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -420,17 +420,8 @@ def _make_linter_options(linter: PyLinter) -> Options:
420420
"default": False,
421421
"type": "yn",
422422
"metavar": "<y or n>",
423-
"help": "When some of the linted files or modules have pylint config in the same directory, "
424-
"use their local configs for checking these files.",
425-
},
426-
),
427-
(
428-
"use-parent-configs",
429-
{
430-
"default": False,
431-
"type": "yn",
432-
"metavar": "<y or n>",
433-
"help": "Search for local pylint configs up until current working directory or root.",
423+
"help": "When some of the linted modules have a pylint config in the same directory "
424+
"(or one of the parent directories), use this config for checking these files.",
434425
},
435426
),
436427
)

pylint/lint/pylinter.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,7 @@ def register_local_config(self, file_or_dir: str) -> None:
624624
else:
625625
basedir = Path(os.path.dirname(file_or_dir))
626626

627-
if self.config.use_parent_configs is False:
628-
# exit loop after first iteration
629-
scan_root_dir = basedir
630-
elif _is_relative_to(basedir, Path(os.getcwd())):
627+
if _is_relative_to(basedir, Path(os.getcwd())):
631628
scan_root_dir = Path(os.getcwd())
632629
else:
633630
scan_root_dir = Path("/")

tests/config/test_per_directory_config.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ def _create_subconfig_test_fs(tmp_path: Path) -> tuple[Path, ...]:
6262
return level1_dir, test_file1, test_file2, test_file3, test_file4
6363

6464

65-
# check that use-parent-configs doesn't break anything
6665
@pytest.mark.parametrize(
6766
"local_config_args",
68-
[["--use-local-configs=y"], ["--use-local-configs=y", "--use-parent-configs=y"]],
67+
[["--use-local-configs=y"]],
6968
)
7069
# check modules and use of configuration files from top-level package or subpackage
7170
@pytest.mark.parametrize("test_file_index", [0, 1, 2])
@@ -119,10 +118,9 @@ def test_subconfig_vs_root_config(
119118
assert "LEVEL1" not in output[2], assert_message
120119

121120

122-
# check that use-parent-configs doesn't break anything
123121
@pytest.mark.parametrize(
124122
"local_config_args",
125-
[["--use-local-configs=y"], ["--use-local-configs=y", "--use-parent-configs=y"]],
123+
[["--use-local-configs=y"]],
126124
)
127125
# check cases when test_file without local config belongs to cwd subtree or not
128126
@pytest.mark.parametrize(
@@ -203,9 +201,7 @@ def test_subconfig_in_parent(tmp_path: Path, capsys: CaptureFixture) -> None:
203201
test_file = _create_parent_subconfig_fs(tmp_path)
204202
orig_cwd = os.getcwd()
205203
os.chdir(tmp_path)
206-
LintRun(
207-
["--use-parent-configs=y", "--use-local-configs=y", str(test_file)], exit=False
208-
)
204+
LintRun(["--use-local-configs=y", str(test_file)], exit=False)
209205
output1 = capsys.readouterr().out.replace("\\n", "\n")
210206
os.chdir(orig_cwd)
211207

0 commit comments

Comments
 (0)