Skip to content

Commit 5e69ba9

Browse files
authored
Merge pull request #1642 from PyCQA/no-home
skip skipping home if home does not exist
2 parents 446b18d + 8b51ee4 commit 5e69ba9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/flake8/options/config.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def _stat_key(s: str) -> Tuple[int, int]:
2323
def _find_config_file(path: str) -> Optional[str]:
2424
# on windows if the homedir isn't detected this returns back `~`
2525
home = os.path.expanduser("~")
26-
home_stat = _stat_key(home) if home != "~" else None
26+
try:
27+
home_stat = _stat_key(home) if home != "~" else None
28+
except OSError: # FileNotFoundError / PermissionError / etc.
29+
home_stat = None
2730

2831
dir_stat = _stat_key(path)
2932
cfg = configparser.RawConfigParser()

tests/unit/test_options_config.py

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ def test_find_config_ignores_homedir(tmp_path):
7878
assert config._find_config_file(str(subdir)) is None
7979

8080

81+
def test_find_config_ignores_unknown_homedir(tmp_path):
82+
subdir = tmp_path.joinpath("d")
83+
84+
with mock.patch.object(os.path, "expanduser", return_value=str(subdir)):
85+
assert config._find_config_file(str(tmp_path)) is None
86+
87+
8188
def test_load_config_config_specified_skips_discovery(tmpdir):
8289
tmpdir.join("setup.cfg").write("[flake8]\nindent-size=2\n")
8390
custom_cfg = tmpdir.join("custom.cfg")

0 commit comments

Comments
 (0)