diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 028b535b366dc2b694c202f3a0ac7c83c6c68f8c..7c07058b63ae6bde2d6562aa6933ad5ef7871f10 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ Python 2.7: script: - py_version=2.7 + - export EXTRA_INSTALL="numpy" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" tags: @@ -11,6 +12,7 @@ Python 2.7: Python 3.5: script: - py_version=3.5 + - export EXTRA_INSTALL="numpy" - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project.sh - ". ./build-and-test-py-project.sh" tags: diff --git a/pytools/persistent_dict.py b/pytools/persistent_dict.py index 9bc9438f398467592df6d26362cabb8a7453efae..0a9fe6cdf2e942299d9dfa61fc2aab9b84807074 100644 --- a/pytools/persistent_dict.py +++ b/pytools/persistent_dict.py @@ -170,24 +170,44 @@ class ItemDirManager(CleanupBase): class KeyBuilder(object): def rec(self, key_hash, key): - try: - method = key.update_persistent_hash - except AttributeError: - pass - else: - method(key_hash, self) - return + digest = None try: - method = getattr(self, "update_for_"+type(key).__name__) + digest = key._pytools_persistent_hash_digest except AttributeError: pass - else: - method(key_hash, key) - return - raise TypeError("unsupported type for persistent hash keying: %s" - % type(key)) + if digest is None: + try: + method = key.update_persistent_hash + except AttributeError: + pass + else: + inner_key_hash = new_hash() + method(inner_key_hash, self) + digest = inner_key_hash.digest() + + if digest is None: + try: + method = getattr(self, "update_for_"+type(key).__name__) + except AttributeError: + pass + else: + inner_key_hash = new_hash() + method(inner_key_hash, key) + digest = inner_key_hash.digest() + + if digest is None: + raise TypeError("unsupported type for persistent hash keying: %s" + % type(key)) + + if not isinstance(key, type): + try: + key._pytools_persistent_hash_digest = digest + except Exception: + pass + + key_hash.update(digest) def __call__(self, key): key_hash = new_hash() diff --git a/test/test_persistent_dict.py b/test/test_persistent_dict.py index c1f7ec76024e94db6dd73b9b410698a88a4f794b..3da5748140e6e6512f877834df109f7dfd6ccc86 100644 --- a/test/test_persistent_dict.py +++ b/test/test_persistent_dict.py @@ -1,5 +1,4 @@ -from __future__ import division, with_statement -from __future__ import absolute_import +from __future__ import division, with_statement, absolute_import import pytest # noqa import sys # noqa