Skip to content
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

Support for resolving external toml files #9230

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/user_guide/usage/run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ command line using the ``--rcfile`` option. Otherwise, Pylint searches for a
configuration file in the following order and uses the first one it finds:

#. ``pylintrc`` in the current working directory
#. ``pylintrc.toml`` in the current working directory,
providing it has at least one ``tool.pylint.`` section.
#. ``.pylintrc`` in the current working directory
#. ``.pylintrc.toml`` in the current working directory,
providing it has at least one ``tool.pylint.`` section.
#. ``pyproject.toml`` in the current working directory,
providing it has at least one ``tool.pylint.`` section.
The ``pyproject.toml`` must prepend section names with ``tool.pylint.``,
Expand Down
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9228.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Support for resolving external toml files named pylintrc.toml and .pylintrc.toml.

Closes #9228
7 changes: 6 additions & 1 deletion pylint/config/find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
else:
import tomli as tomllib

RC_NAMES = (Path("pylintrc"), Path(".pylintrc"))
RC_NAMES = (
Path("pylintrc"),
Path("pylintrc.toml"),
Path(".pylintrc"),
Path(".pylintrc.toml"),
)
PYPROJECT_NAME = Path("pyproject.toml")
CONFIG_NAMES = (*RC_NAMES, PYPROJECT_NAME, Path("setup.cfg"))

Expand Down
35 changes: 35 additions & 0 deletions tests/config/test_find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,41 @@ def test_pylintrc_parentdir() -> None:
assert next(config.find_default_config_files()) == expected


@pytest.mark.usefixtures("pop_pylintrc")
def test_pylintrc_toml_parentdir() -> None:
"""Test that the first pylintrc.toml we find is the first parent directory."""
# pylint: disable=duplicate-code
with tempdir() as chroot:
chroot_path = Path(chroot)
files = [
"a/pylintrc.toml",
"a/b/__init__.py",
"a/b/pylintrc.toml",
"a/b/c/__init__.py",
"a/b/c/d/__init__.py",
"a/b/c/d/e/.pylintrc.toml",
]
testutils.create_files(files)
for config_file in files:
if config_file.endswith("pylintrc.toml"):
with open(config_file, "w", encoding="utf-8") as fd:
fd.write('[tool.pylint."messages control"]\n')

with fake_home():
assert not list(config.find_default_config_files())

results = {
"a": chroot_path / "a" / "pylintrc.toml",
"a/b": chroot_path / "a" / "b" / "pylintrc.toml",
"a/b/c": chroot_path / "a" / "b" / "pylintrc.toml",
"a/b/c/d": chroot_path / "a" / "b" / "pylintrc.toml",
"a/b/c/d/e": chroot_path / "a" / "b" / "c" / "d" / "e" / ".pylintrc.toml",
}
for basedir, expected in results.items():
os.chdir(chroot_path / basedir)
assert next(config.find_default_config_files()) == expected


@pytest.mark.usefixtures("pop_pylintrc")
def test_pyproject_toml_parentdir() -> None:
"""Test the search of pyproject.toml file in parent directories"""
Expand Down