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

Use already existing cache if found during build #1747

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,9 @@ def _build_cache(self, loaded_files=None) -> None:
if cache is None:
self._build_cache()
diskcache.save(self._cache, loaded_files, "build_cache")
return
else:
self._cache = cache
return

self._cache = RegistryCache()

Expand Down
10 changes: 10 additions & 0 deletions pint/testsuite/test_diskcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,13 @@ def test_change_file(tmp_path):
assert ureg.x == 1235
files = tuple(ureg._diskcache.cache_folder.glob("*.pickle"))
assert len(files) == 4


def test_dimensional_equivalent_are_cached(tmp_path):
ureg = pint.UnitRegistry(cache_folder=tmp_path)
t = ureg.get_compatible_units("L")
assert len(t) > 0

ureg = pint.UnitRegistry(cache_folder=tmp_path)
t = ureg.get_compatible_units("L")
assert len(t) > 0