Skip to content

Commit

Permalink
Fix a bug where a tox.ini file with pylint configuration was igno…
Browse files Browse the repository at this point in the history
…red and it exists in the current directory.

Closes pylint-dev#9727
  • Loading branch information
mbyrnepr2 committed Jun 12, 2024
1 parent 2ba88b9 commit 63ed122
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9727.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a bug where a ``tox.ini`` file with pylint configuration was ignored and it exists in the current directory.

Closes #9727
5 changes: 3 additions & 2 deletions pylint/config/find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
Path(".pylintrc.toml"),
)
PYPROJECT_NAME = Path("pyproject.toml")
CONFIG_NAMES = (*RC_NAMES, PYPROJECT_NAME, Path("setup.cfg"))
TOX_NAME = Path("tox.ini")
CONFIG_NAMES = (*RC_NAMES, PYPROJECT_NAME, Path("setup.cfg"), TOX_NAME)


def _find_pyproject() -> Path:
Expand Down Expand Up @@ -71,7 +72,7 @@ def _yield_default_files() -> Iterator[Path]:
if config_name.is_file():
if config_name.suffix == ".toml" and not _toml_has_config(config_name):
continue
if config_name.suffix == ".cfg" and not _cfg_has_config(config_name):
if config_name.suffix in (".cfg", ".ini") and not _cfg_has_config(config_name):
continue

yield config_name.resolve()
Expand Down
9 changes: 7 additions & 2 deletions tests/config/test_find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,18 @@ def test_toml_has_config(content: str, expected: bool, tmp_path: Path) -> None:
],
],
)
def test_cfg_has_config(content: str, expected: bool, tmp_path: Path) -> None:
"""Test that a cfg file has a pylint config."""
def test_has_config(content: str, expected: bool, tmp_path: Path) -> None:
"""Test that a .cfg file or .ini file has a pylint config."""
fake_cfg = tmp_path / "fake.cfg"
with open(fake_cfg, "w", encoding="utf8") as f:
f.write(content)
assert _cfg_has_config(fake_cfg) == expected

fake_ini = tmp_path / "tox.ini"
with open(fake_ini, "w", encoding="utf8") as f:
f.write(content)
assert _cfg_has_config(fake_ini) == expected


def test_non_existent_home() -> None:
"""Test that we handle a non-existent home directory.
Expand Down

0 comments on commit 63ed122

Please sign in to comment.