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

ignore config files that partially parse as flake8 configs #1648

Merged
merged 1 commit into from Aug 1, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/flake8/options/config.py
Expand Up @@ -29,9 +29,9 @@ def _find_config_file(path: str) -> Optional[str]:
home_stat = None

dir_stat = _stat_key(path)
cfg = configparser.RawConfigParser()
while True:
for candidate in ("setup.cfg", "tox.ini", ".flake8"):
cfg = configparser.RawConfigParser()
cfg_path = os.path.join(path, candidate)
try:
cfg.read(cfg_path, encoding="UTF-8")
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_options_config.py
Expand Up @@ -21,7 +21,9 @@ def test_config_file_without_section_is_not_considered(tmp_path):


def test_config_file_with_parse_error_is_not_considered(tmp_path, caplog):
tmp_path.joinpath("setup.cfg").write_text("[error")
# the syntax error here is deliberately to trigger a partial parse
# https://github.com/python/cpython/issues/95546
tmp_path.joinpath("setup.cfg").write_text("[flake8]\nx = 1\n...")

assert config._find_config_file(str(tmp_path)) is None

Expand Down