From 49c8f318be1f7c60d45e34ca96fda49303027b6b Mon Sep 17 00:00:00 2001 From: Aaron Zuspan Date: Wed, 9 Nov 2022 21:40:37 -0800 Subject: [PATCH] Formatting --- eerepr/__init__.py | 6 +++--- eerepr/repr.py | 21 +++++++++++---------- tests/test_cache.py | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/eerepr/__init__.py b/eerepr/__init__.py index df1f2a3..251a369 100644 --- a/eerepr/__init__.py +++ b/eerepr/__init__.py @@ -1,9 +1,9 @@ import ee -from eerepr.repr import initialize from eerepr.config import options +from eerepr.repr import initialize -__version__ = '0.0.2' -__all__ = ['clear_cache', 'initialize', 'options'] +__version__ = "0.0.2" +__all__ = ["clear_cache", "initialize", "options"] initialize(max_cache_size=options.max_cache_size) diff --git a/eerepr/repr.py b/eerepr/repr.py index 9e22587..f3e4b80 100644 --- a/eerepr/repr.py +++ b/eerepr/repr.py @@ -1,15 +1,14 @@ +import uuid from functools import _lru_cache_wrapper, lru_cache from html import escape from importlib.resources import read_text from typing import Callable, Type, Union from warnings import warn -import uuid import ee -from eerepr.html import convert_to_html from eerepr.config import options - +from eerepr.html import convert_to_html REPR_HTML = "_repr_html_" # Track which html reprs have been set so we can overwrite them if needed. @@ -39,7 +38,7 @@ def _attach_html_repr(cls: Type, repr: Callable) -> None: def _is_nondeterministic(obj): """Check if an object returns nondeterministic results which would break caching. - + Currently, this only tests for the case of `ee.List.shuffle(seed=False)`. """ invocation = obj.serialize() @@ -83,11 +82,13 @@ def _ee_repr(obj: Union[ee.Element, ee.ComputedObject]) -> str: rep = _repr_html_(obj) mbs = len(rep) / 1e6 if mbs > options.max_repr_mbs: - warn(message=( - f"HTML repr size ({mbs:.0f}mB) exceeds maximum ({options.max_repr_mbs:.0f}mB), falling" - " back to string repr. You can set `eerepr.options.max_repr_mbs` to print larger" - " objects, but this may cause performance issues." - )) + warn( + message=( + f"HTML repr size ({mbs:.0f}mB) exceeds maximum ({options.max_repr_mbs:.0f}mB), falling" + " back to string repr. You can set `eerepr.options.max_repr_mbs` to print larger" + " objects, but this may cause performance issues." + ) + ) return f"
{escape(repr(obj))}
" return rep @@ -107,7 +108,7 @@ def initialize(max_cache_size=None) -> None: global _repr_html_ if isinstance(_repr_html_, _lru_cache_wrapper): _repr_html_ = _repr_html_.__wrapped__ - + if max_cache_size != 0: _repr_html_ = lru_cache(maxsize=max_cache_size)(_repr_html_) diff --git a/tests/test_cache.py b/tests/test_cache.py index b18bc86..c2563e4 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -22,4 +22,4 @@ def test_nondeterministic_caching(): x = ee.List([0, 1, 2]).shuffle(seed=False) x._repr_html_() x._repr_html_() - assert cache.cache_info().misses == 2 \ No newline at end of file + assert cache.cache_info().misses == 2