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

skip skipping home if home does not exist #1642

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
5 changes: 4 additions & 1 deletion src/flake8/options/config.py
Expand Up @@ -23,7 +23,10 @@ def _stat_key(s: str) -> Tuple[int, int]:
def _find_config_file(path: str) -> Optional[str]:
# on windows if the homedir isn't detected this returns back `~`
home = os.path.expanduser("~")
home_stat = _stat_key(home) if home != "~" else None
try:
home_stat = _stat_key(home) if home != "~" else None
except OSError: # FileNotFoundError / PermissionError / etc.
home_stat = None

dir_stat = _stat_key(path)
cfg = configparser.RawConfigParser()
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_options_config.py
Expand Up @@ -78,6 +78,13 @@ def test_find_config_ignores_homedir(tmp_path):
assert config._find_config_file(str(subdir)) is None


def test_find_config_ignores_unknown_homedir(tmp_path):
subdir = tmp_path.joinpath("d")

with mock.patch.object(os.path, "expanduser", return_value=str(subdir)):
assert config._find_config_file(str(tmp_path)) is None


def test_load_config_config_specified_skips_discovery(tmpdir):
tmpdir.join("setup.cfg").write("[flake8]\nindent-size=2\n")
custom_cfg = tmpdir.join("custom.cfg")
Expand Down