Skip to content

Commit d4631af

Browse files
authored
Fix saving of persistent data files on different drives (#6526)
1 parent 0220a39 commit d4631af

File tree

4 files changed

+75
-7
lines changed

4 files changed

+75
-7
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ Release date: TBA
293293

294294
Closes #5502
295295

296+
* Fix saving of persistent data files in environments where the user's cache
297+
directory and the linted file are on a different drive.
298+
299+
Closes #6394
300+
296301
..
297302
Insert your changelog randomly, it will reduce merge conflicts
298303
(Ie. not necessarily at the end)

doc/whatsnew/2.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ Other Changes
266266

267267
Closes #5670
268268

269+
* Fix saving of persistent data files in environments where the user's cache
270+
directory and the linted file are on a different drive.
271+
272+
Closes #6394
273+
269274
* The ``method-cache-max-size-none`` checker will now also check ``functools.cache``.
270275

271276
Closes #5670

pylint/lint/caching.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
def _get_pdata_path(
1717
base_name: Path, recurs: int, pylint_home: Path = Path(PYLINT_HOME)
1818
) -> Path:
19-
underscored_name = "_".join(str(p) for p in base_name.parts)
19+
# We strip all characters that can't be used in a filename
20+
# Also strip '/' and '\\' because we want to create a single file, not sub-directories
21+
underscored_name = "_".join(
22+
str(p.replace(":", "_").replace("/", "_").replace("\\", "_"))
23+
for p in base_name.parts
24+
)
2025
return pylint_home / f"{underscored_name}_{recurs}.stats"
2126

2227

tests/lint/test_caching.py

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Pytest fixtures work like this by design
66
# pylint: disable=redefined-outer-name
77

8+
import sys
89
from pathlib import Path
910

1011
import pytest
@@ -18,15 +19,67 @@
1819

1920

2021
@pytest.mark.parametrize(
21-
"path,recur,expected",
22+
"path,recur,pylint_home,expected",
2223
[
23-
["", 1, PYLINT_HOME_PATH / "_1.stats"],
24-
["", 2, PYLINT_HOME_PATH / "_2.stats"],
25-
["a/path", 42, PYLINT_HOME_PATH / "a_path_42.stats"],
24+
["", 1, PYLINT_HOME_PATH, PYLINT_HOME_PATH / "_1.stats"],
25+
["", 2, PYLINT_HOME_PATH, PYLINT_HOME_PATH / "_2.stats"],
26+
["a/path", 42, PYLINT_HOME_PATH, PYLINT_HOME_PATH / "a_path_42.stats"],
2627
],
2728
)
28-
def test__get_pdata_path(path: str, recur: int, expected: Path) -> None:
29-
assert _get_pdata_path(Path(path), recur) == expected
29+
def test__get_pdata_path(
30+
path: str, recur: int, pylint_home: Path, expected: Path
31+
) -> None:
32+
assert _get_pdata_path(Path(path), recur, pylint_home) == expected
33+
34+
35+
@pytest.mark.skipif(sys.platform == "win32", reason="Path type of *nix")
36+
@pytest.mark.parametrize(
37+
"path,recur,pylint_home,expected",
38+
[
39+
[
40+
"/workspace/MyDir/test.py",
41+
1,
42+
Path("/root/.cache/pylint"),
43+
Path("/root/.cache/pylint") / "__workspace_MyDir_test.py_1.stats",
44+
],
45+
[
46+
"/workspace/MyDir/test.py",
47+
1,
48+
Path("//host/computer/.cache"),
49+
Path("//host/computer/.cache") / "__workspace_MyDir_test.py_1.stats",
50+
],
51+
],
52+
)
53+
def test__get_pdata_path_nix(
54+
path: str, recur: int, pylint_home: Path, expected: Path
55+
) -> None:
56+
"""test__get_pdata_path but specifically for *nix system paths."""
57+
assert _get_pdata_path(Path(path), recur, pylint_home) == expected
58+
59+
60+
@pytest.mark.skipif(sys.platform != "win32", reason="Path type of windows")
61+
@pytest.mark.parametrize(
62+
"path,recur,pylint_home,expected",
63+
[
64+
[
65+
"D:\\MyDir\\test.py",
66+
1,
67+
Path("C:\\Users\\MyPylintHome"),
68+
Path("C:\\Users\\MyPylintHome") / "D___MyDir_test.py_1.stats",
69+
],
70+
[
71+
"C:\\MyDir\\test.py",
72+
1,
73+
Path("C:\\Users\\MyPylintHome"),
74+
Path("C:\\Users\\MyPylintHome") / "C___MyDir_test.py_1.stats",
75+
],
76+
],
77+
)
78+
def test__get_pdata_path_windows(
79+
path: str, recur: int, pylint_home: Path, expected: Path
80+
) -> None:
81+
"""test__get_pdata_path but specifically for windows."""
82+
assert _get_pdata_path(Path(path), recur, pylint_home) == expected
3083

3184

3285
@pytest.fixture

0 commit comments

Comments
 (0)