cdxcore 0.1.24__py3-none-any.whl → 0.1.27__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cdxcore might be problematic. Click here for more details.
- cdxcore/__init__.py +1 -1
- cdxcore/deferred.py +11 -56
- cdxcore/dynaplot.py +12 -1
- cdxcore/subdir.py +447 -396
- cdxcore/uniquehash.py +1 -1
- {cdxcore-0.1.24.dist-info → cdxcore-0.1.27.dist-info}/METADATA +1 -1
- {cdxcore-0.1.24.dist-info → cdxcore-0.1.27.dist-info}/RECORD +10 -10
- {cdxcore-0.1.24.dist-info → cdxcore-0.1.27.dist-info}/WHEEL +0 -0
- {cdxcore-0.1.24.dist-info → cdxcore-0.1.27.dist-info}/licenses/LICENSE +0 -0
- {cdxcore-0.1.24.dist-info → cdxcore-0.1.27.dist-info}/top_level.txt +0 -0
cdxcore/__init__.py
CHANGED
cdxcore/deferred.py
CHANGED
|
@@ -180,7 +180,6 @@ from .err import verify
|
|
|
180
180
|
from. util import qualified_name, fmt_list
|
|
181
181
|
from .verbose import Context
|
|
182
182
|
from collections.abc import Collection, Sequence, Mapping
|
|
183
|
-
import gc as gc
|
|
184
183
|
|
|
185
184
|
class _ParentDeleted:
|
|
186
185
|
pass
|
|
@@ -273,48 +272,7 @@ class Deferred(object):
|
|
|
273
272
|
----------
|
|
274
273
|
info : str
|
|
275
274
|
Descriptive name of the usually not-yet-created object deferred actions
|
|
276
|
-
will act upon.
|
|
277
|
-
|
|
278
|
-
deferred__eq__ : bool, optional
|
|
279
|
-
If ``False``, the default, the ``__eq__`` operator will not be deferred. That means
|
|
280
|
-
that you are able to use :func:`cdxcore.deferred.Deferred.Create` and :class:`cdxcore.deferred.Deferred`
|
|
281
|
-
objects in Python contexts which require ``__eq__``, for example using them in lists.
|
|
282
|
-
|
|
283
|
-
By default this works:
|
|
284
|
-
|
|
285
|
-
.. code-block:: python
|
|
286
|
-
|
|
287
|
-
a = Create("A")
|
|
288
|
-
b = Create("B")
|
|
289
|
-
a in [b] # -> returns False
|
|
290
|
-
b in [b] # -> returns True
|
|
291
|
-
|
|
292
|
-
*However* that may also break your deferred semantics as the boolean returned by a deferred operator
|
|
293
|
-
may differ from the boolean returned by the non-deferred ``__eq__`` operator (e.g. comparison using ``id``).
|
|
294
|
-
|
|
295
|
-
Accordingly,
|
|
296
|
-
|
|
297
|
-
.. code-block:: python
|
|
298
|
-
|
|
299
|
-
a = Create("A",deferred__eq__=True)
|
|
300
|
-
b = Create("B",deferred__eq__=True)
|
|
301
|
-
a in [b]
|
|
302
|
-
|
|
303
|
-
will raise an error.
|
|
304
|
-
Note that this will be a :class:`cdxcore.deferred.NotSupportedError` for the attempt
|
|
305
|
-
to call ``__bool__`` on the
|
|
306
|
-
deferred ``__eq__`` operator:
|
|
307
|
-
|
|
308
|
-
.. code-block:: python
|
|
309
|
-
|
|
310
|
-
NotSupportedError:(
|
|
311
|
-
'__bool__',
|
|
312
|
-
"Deferring action `__bool__` for '($A!=$B)' is "\
|
|
313
|
-
"not possible: '__bool__' must return a 'bool'.")
|
|
314
|
-
|
|
315
|
-
Note that this setting does not affect ``__neq__`` or any other relational opertors.
|
|
316
|
-
|
|
317
|
-
Set to ``True`` to defer ``__eq__``.
|
|
275
|
+
will act upon.
|
|
318
276
|
"""
|
|
319
277
|
@classmethod
|
|
320
278
|
def Create( cls, info : str ):
|
|
@@ -330,10 +288,11 @@ class Deferred(object):
|
|
|
330
288
|
def __init__(self, info : str, *,
|
|
331
289
|
action : str = "",
|
|
332
290
|
#
|
|
333
|
-
parent : type
|
|
291
|
+
parent : type|None = None,
|
|
292
|
+
base_info : bool|None = None,
|
|
334
293
|
# arguments passed to the action
|
|
335
|
-
args : Collection
|
|
336
|
-
kwargs : Mapping
|
|
294
|
+
args : Collection|None = None,
|
|
295
|
+
kwargs : Mapping|None = None,
|
|
337
296
|
):
|
|
338
297
|
"""
|
|
339
298
|
Initialize a deferred action.
|
|
@@ -353,8 +312,7 @@ class Deferred(object):
|
|
|
353
312
|
self._deferred_action = action # action code
|
|
354
313
|
self._deferred_parent = parent
|
|
355
314
|
self._deferred_depth = parent._deferred_depth+1 if not parent is None else 0
|
|
356
|
-
self.
|
|
357
|
-
self._deferred__hash__ = False
|
|
315
|
+
self._deferred_base_info = parent._deferred_base_info if not parent is None else ( base_info if not base_info is None else False )
|
|
358
316
|
self._deferred_args = [] if args is None else list(args)
|
|
359
317
|
self._deferred_kwargs = {} if kwargs is None else dict(kwargs)
|
|
360
318
|
self._deferred_live = None # once the object exists, it goes here.
|
|
@@ -621,7 +579,7 @@ class Deferred(object):
|
|
|
621
579
|
for _ in sources:
|
|
622
580
|
s += _+","
|
|
623
581
|
s = s[:-1]
|
|
624
|
-
verbose.write( f"{self._deferred_info} <= {s}" )
|
|
582
|
+
verbose.write( lambda : f"{self._deferred_info} <= {s}" )
|
|
625
583
|
else:
|
|
626
584
|
verbose.write( self._deferred_info )
|
|
627
585
|
|
|
@@ -688,7 +646,6 @@ class Deferred(object):
|
|
|
688
646
|
raise e
|
|
689
647
|
|
|
690
648
|
try:
|
|
691
|
-
|
|
692
649
|
live = action( *args, **kwargs )
|
|
693
650
|
except Exception as e:
|
|
694
651
|
arguments = self._deferred_fmt_args(args,kwargs)
|
|
@@ -701,7 +658,7 @@ class Deferred(object):
|
|
|
701
658
|
raise e
|
|
702
659
|
del action
|
|
703
660
|
|
|
704
|
-
verbose.write(f"{self._deferred_info} -> '{qualified_name(live)}' : {self._deferred_to_str(live)}")
|
|
661
|
+
verbose.write(lambda : f"{self._deferred_info} -> '{qualified_name(live)}' : {self._deferred_to_str(live)}")
|
|
705
662
|
|
|
706
663
|
# clear object
|
|
707
664
|
# note that as soon as we write to self._deferred_live we can no longer
|
|
@@ -715,7 +672,6 @@ class Deferred(object):
|
|
|
715
672
|
self._deferred_kwargs = None
|
|
716
673
|
self._deferred_args = None
|
|
717
674
|
self._deferred_parent = _ParentDeleted() # None is a valid parent --> choose someting bad
|
|
718
|
-
gc.collect()
|
|
719
675
|
|
|
720
676
|
# action
|
|
721
677
|
self._deferred_was_resolved = True
|
|
@@ -755,7 +711,7 @@ class Deferred(object):
|
|
|
755
711
|
verify( not element is None, lambda : f"You cannot resolve '{self._deferred_info}' with an empty 'element'")
|
|
756
712
|
verbose = Context.quiet if verbose is None else verbose
|
|
757
713
|
|
|
758
|
-
verbose.write(f"{self._deferred_info} -> '{qualified_name(element)}' : {self._deferred_to_str(element)}")
|
|
714
|
+
verbose.write(lambda : f"{self._deferred_info} -> '{qualified_name(element)}' : {self._deferred_to_str(element)}")
|
|
759
715
|
self._deferred_live = element
|
|
760
716
|
self._deferred_was_resolved = True
|
|
761
717
|
|
|
@@ -764,8 +720,7 @@ class Deferred(object):
|
|
|
764
720
|
dlevel = daction._deferred_depth
|
|
765
721
|
daction._deferred_resolve( verbose=verbose(dlevel) )
|
|
766
722
|
del daction
|
|
767
|
-
|
|
768
|
-
gc.collect()
|
|
723
|
+
|
|
769
724
|
return element
|
|
770
725
|
|
|
771
726
|
# Iteration
|
|
@@ -810,7 +765,7 @@ class Deferred(object):
|
|
|
810
765
|
verify( not fmt is None, lambda : f"Error defining action '{action}' for '{self._deferred_info}': 'fmt' not specified" )
|
|
811
766
|
|
|
812
767
|
def label(x):
|
|
813
|
-
return x if not isinstance(x, Deferred) else x.__dict__.get('_deferred_info',action)
|
|
768
|
+
return self._deferred_to_str(x) if not isinstance(x, Deferred) else x.__dict__.get('_deferred_info',action)
|
|
814
769
|
arguments = { f"arg{i}" : label(arg) for i, arg in enumerate(args) }
|
|
815
770
|
arguments['parent'] = self._deferred_info
|
|
816
771
|
try:
|
cdxcore/dynaplot.py
CHANGED
|
@@ -614,7 +614,8 @@ class DynaFig(_DynaDeferred):
|
|
|
614
614
|
verify( not 'figsize' in fig_kwargs, "Cannot specify both `figsize` and `fig_size`", exception=ValueError)
|
|
615
615
|
fig_kwargs['figsize'] = fig_size
|
|
616
616
|
|
|
617
|
-
|
|
617
|
+
dyna_title = title if len(title) <= 20 else ( title[:17] + "..." ) if not title is None else None
|
|
618
|
+
_DynaDeferred.__init__(self, f"figure('{dyna_title}')" if not title is None else "figure()" )
|
|
618
619
|
|
|
619
620
|
def __str__(self):
|
|
620
621
|
return self.deferred_info[1:]
|
|
@@ -953,6 +954,16 @@ class DynaFig(_DynaDeferred):
|
|
|
953
954
|
ax.remove()
|
|
954
955
|
if render:
|
|
955
956
|
self.render()
|
|
957
|
+
|
|
958
|
+
# context for cleaning up
|
|
959
|
+
# -----------------------
|
|
960
|
+
|
|
961
|
+
def __enter__(self):
|
|
962
|
+
return self
|
|
963
|
+
|
|
964
|
+
def __exit__(self, *args, **kwargs):
|
|
965
|
+
self.close()
|
|
966
|
+
return False
|
|
956
967
|
|
|
957
968
|
def figure( title : str = None, *,
|
|
958
969
|
row_size : int = 5,
|