summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-05-06 21:56:09 +0200
committerGitHub <noreply@github.com>2022-05-06 21:56:09 +0200
commitd4631afcca3a712c020d7fa068c2d84d95a86af2 (patch)
tree72927780c5ec0590e4041db7ba3a751446e02c7c
parent0220a39f6d4dddd1bf8f2f6d83e11db58a093fbe (diff)
downloadpylint-git-d4631afcca3a712c020d7fa068c2d84d95a86af2.tar.gz
Fix saving of persistent data files on different drives (#6526)
-rw-r--r--ChangeLog5
-rw-r--r--doc/whatsnew/2.14.rst5
-rw-r--r--pylint/lint/caching.py7
-rw-r--r--tests/lint/test_caching.py65
4 files changed, 75 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 405d85f4e..aec24186b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -293,6 +293,11 @@ Release date: TBA
Closes #5502
+* Fix saving of persistent data files in environments where the user's cache
+ directory and the linted file are on a different drive.
+
+ Closes #6394
+
..
Insert your changelog randomly, it will reduce merge conflicts
(Ie. not necessarily at the end)
diff --git a/doc/whatsnew/2.14.rst b/doc/whatsnew/2.14.rst
index bf97f475d..d59c4792e 100644
--- a/doc/whatsnew/2.14.rst
+++ b/doc/whatsnew/2.14.rst
@@ -266,6 +266,11 @@ Other Changes
Closes #5670
+* Fix saving of persistent data files in environments where the user's cache
+ directory and the linted file are on a different drive.
+
+ Closes #6394
+
* The ``method-cache-max-size-none`` checker will now also check ``functools.cache``.
Closes #5670
diff --git a/pylint/lint/caching.py b/pylint/lint/caching.py
index ec5a9f78a..573b97628 100644
--- a/pylint/lint/caching.py
+++ b/pylint/lint/caching.py
@@ -16,7 +16,12 @@ from pylint.utils import LinterStats
def _get_pdata_path(
base_name: Path, recurs: int, pylint_home: Path = Path(PYLINT_HOME)
) -> Path:
- underscored_name = "_".join(str(p) for p in base_name.parts)
+ # We strip all characters that can't be used in a filename
+ # Also strip '/' and '\\' because we want to create a single file, not sub-directories
+ underscored_name = "_".join(
+ str(p.replace(":", "_").replace("/", "_").replace("\\", "_"))
+ for p in base_name.parts
+ )
return pylint_home / f"{underscored_name}_{recurs}.stats"
diff --git a/tests/lint/test_caching.py b/tests/lint/test_caching.py
index 8d3f7afd4..fe6ccc234 100644
--- a/tests/lint/test_caching.py
+++ b/tests/lint/test_caching.py
@@ -5,6 +5,7 @@
# Pytest fixtures work like this by design
# pylint: disable=redefined-outer-name
+import sys
from pathlib import Path
import pytest
@@ -18,15 +19,67 @@ PYLINT_HOME_PATH = Path(PYLINT_HOME)
@pytest.mark.parametrize(
- "path,recur,expected",
+ "path,recur,pylint_home,expected",
[
- ["", 1, PYLINT_HOME_PATH / "_1.stats"],
- ["", 2, PYLINT_HOME_PATH / "_2.stats"],
- ["a/path", 42, PYLINT_HOME_PATH / "a_path_42.stats"],
+ ["", 1, PYLINT_HOME_PATH, PYLINT_HOME_PATH / "_1.stats"],
+ ["", 2, PYLINT_HOME_PATH, PYLINT_HOME_PATH / "_2.stats"],
+ ["a/path", 42, PYLINT_HOME_PATH, PYLINT_HOME_PATH / "a_path_42.stats"],
],
)
-def test__get_pdata_path(path: str, recur: int, expected: Path) -> None:
- assert _get_pdata_path(Path(path), recur) == expected
+def test__get_pdata_path(
+ path: str, recur: int, pylint_home: Path, expected: Path
+) -> None:
+ assert _get_pdata_path(Path(path), recur, pylint_home) == expected
+
+
+@pytest.mark.skipif(sys.platform == "win32", reason="Path type of *nix")
+@pytest.mark.parametrize(
+ "path,recur,pylint_home,expected",
+ [
+ [
+ "/workspace/MyDir/test.py",
+ 1,
+ Path("/root/.cache/pylint"),
+ Path("/root/.cache/pylint") / "__workspace_MyDir_test.py_1.stats",
+ ],
+ [
+ "/workspace/MyDir/test.py",
+ 1,
+ Path("//host/computer/.cache"),
+ Path("//host/computer/.cache") / "__workspace_MyDir_test.py_1.stats",
+ ],
+ ],
+)
+def test__get_pdata_path_nix(
+ path: str, recur: int, pylint_home: Path, expected: Path
+) -> None:
+ """test__get_pdata_path but specifically for *nix system paths."""
+ assert _get_pdata_path(Path(path), recur, pylint_home) == expected
+
+
+@pytest.mark.skipif(sys.platform != "win32", reason="Path type of windows")
+@pytest.mark.parametrize(
+ "path,recur,pylint_home,expected",
+ [
+ [
+ "D:\\MyDir\\test.py",
+ 1,
+ Path("C:\\Users\\MyPylintHome"),
+ Path("C:\\Users\\MyPylintHome") / "D___MyDir_test.py_1.stats",
+ ],
+ [
+ "C:\\MyDir\\test.py",
+ 1,
+ Path("C:\\Users\\MyPylintHome"),
+ Path("C:\\Users\\MyPylintHome") / "C___MyDir_test.py_1.stats",
+ ],
+ ],
+)
+def test__get_pdata_path_windows(
+ path: str, recur: int, pylint_home: Path, expected: Path
+) -> None:
+ """test__get_pdata_path but specifically for windows."""
+ assert _get_pdata_path(Path(path), recur, pylint_home) == expected
@pytest.fixture