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

cache per interpreter #62

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions memestra/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down