mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Fixed a bug where providing a cache_path did not really affect anything.
This commit is contained in:
@@ -152,8 +152,9 @@ def clear_cache(cache_path=None):
|
|||||||
|
|
||||||
|
|
||||||
def _get_hashed_path(grammar, path, cache_path=None):
|
def _get_hashed_path(grammar, path, cache_path=None):
|
||||||
|
directory = _get_cache_directory_path(cache_path=cache_path)
|
||||||
|
|
||||||
file_hash = hashlib.sha256(path.encode("utf-8")).hexdigest()
|
file_hash = hashlib.sha256(path.encode("utf-8")).hexdigest()
|
||||||
directory = _get_cache_directory_path()
|
|
||||||
return os.path.join(directory, '%s-%s.pkl' % (grammar.sha256, file_hash))
|
return os.path.join(directory, '%s-%s.pkl' % (grammar.sha256, file_hash))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def isolated_jedi_cache(monkeypatch, tmpdir):
|
|||||||
monkeypatch.setattr(cache, '_default_cache_path', str(tmpdir))
|
monkeypatch.setattr(cache, '_default_cache_path', str(tmpdir))
|
||||||
|
|
||||||
|
|
||||||
def test_modulepickling_change_cache_dir(monkeypatch, tmpdir):
|
def test_modulepickling_change_cache_dir(tmpdir):
|
||||||
"""
|
"""
|
||||||
ParserPickling should not save old cache when cache_directory is changed.
|
ParserPickling should not save old cache when cache_directory is changed.
|
||||||
|
|
||||||
@@ -37,22 +37,20 @@ def test_modulepickling_change_cache_dir(monkeypatch, tmpdir):
|
|||||||
path_1 = 'fake path 1'
|
path_1 = 'fake path 1'
|
||||||
path_2 = 'fake path 2'
|
path_2 = 'fake path 2'
|
||||||
|
|
||||||
monkeypatch.setattr(cache, '_default_cache_path', dir_1)
|
|
||||||
grammar = load_grammar()
|
grammar = load_grammar()
|
||||||
_save_to_file_system(grammar, path_1, item_1)
|
_save_to_file_system(grammar, path_1, item_1, cache_path=dir_1)
|
||||||
parser_cache.clear()
|
parser_cache.clear()
|
||||||
cached = load_stored_item(grammar, path_1, item_1)
|
cached = load_stored_item(grammar, path_1, item_1, cache_path=dir_1)
|
||||||
assert cached == item_1.node
|
assert cached == item_1.node
|
||||||
|
|
||||||
monkeypatch.setattr(cache, '_default_cache_path', dir_2)
|
_save_to_file_system(grammar, path_2, item_2, cache_path=dir_2)
|
||||||
_save_to_file_system(grammar, path_2, item_2)
|
cached = load_stored_item(grammar, path_1, item_1, cache_path=dir_2)
|
||||||
cached = load_stored_item(grammar, path_1, item_1)
|
|
||||||
assert cached is None
|
assert cached is None
|
||||||
|
|
||||||
|
|
||||||
def load_stored_item(grammar, path, item):
|
def load_stored_item(grammar, path, item, cache_path):
|
||||||
"""Load `item` stored at `path` in `cache`."""
|
"""Load `item` stored at `path` in `cache`."""
|
||||||
item = _load_from_file_system(grammar, path, item.change_time - 1)
|
item = _load_from_file_system(grammar, path, item.change_time - 1, cache_path)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user