diff --git a/memestra/caching.py b/memestra/caching.py index 01df70e..0ebb5e9 100644 --- a/memestra/caching.py +++ b/memestra/caching.py @@ -265,8 +265,15 @@ def __init__(self, cache_dir=None): else: user_config_dir = xdg_config_home memestra_dir = 'memestra' - self.cachedir = os.path.expanduser(os.path.join(user_config_dir, - memestra_dir)) + + # use a path that is dependent on the interpeter version to avoid + # polluting the cache from other interpreters + interpreter_path = os.path.join( + *os.path.abspath(sys.executable).split(os.sep)[1:] + ) + self.cachedir = os.path.expanduser( + os.path.join(user_config_dir, memestra_dir, interpreter_path) + ) os.makedirs(self.cachedir, exist_ok=True) def _get_path(self, key): diff --git a/tests/test_caching.py b/tests/test_caching.py index f9b41c7..b07e4b5 100644 --- a/tests/test_caching.py +++ b/tests/test_caching.py @@ -70,6 +70,16 @@ def test_invalid_version(self): finally: shutil.rmtree(tmpdir) + def test_cache_is_tied_to_interpreter(self): + with tempfile.TemporaryDirectory() as tmpdir: + os.environ['XDG_CONFIG_HOME'] = tmpdir + cache = memestra.caching.Cache() + self.assertIn( + os.path.join(*sys.executable.split(os.sep)[1:]), + cache.cachedir, + ) + + class TestCLI(TestCase): def test_docparse(self):