cdxcore 0.1.26__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 CHANGED
@@ -4,4 +4,4 @@ Created on June 2022
4
4
  @author: hansb
5
5
  """
6
6
 
7
- __version__ = "0.1.26" # auto-updated by setup.py
7
+ __version__ = "0.1.27" # auto-updated by setup.py
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 = None,
291
+ parent : type|None = None,
292
+ base_info : bool|None = None,
334
293
  # arguments passed to the action
335
- args : Collection = None,
336
- kwargs : Mapping = None,
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._deferred__eq__ = parent._deferred__eq__ if not parent is None else False
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
- _DynaDeferred.__init__(self, f"figure('{str(title)[:20]}')" if not title is None else"figure()" )
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,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cdxcore
3
- Version: 0.1.26
3
+ Version: 0.1.27
4
4
  Summary: Basic Python Tools; upgraded cdxbasics
5
5
  Author-email: Hans Buehler <github@buehler.london>
6
6
  License-Expression: MIT
@@ -1,8 +1,8 @@
1
- cdxcore/__init__.py,sha256=fkVQQ_XdGdXhWA35RMrTjwmBD2jNYOcKPhNKMgPF8Vw,127
1
+ cdxcore/__init__.py,sha256=IQ_905FfCmwI896RBhTOXXYbKrOeTfPDFB4bjP-09Sg,127
2
2
  cdxcore/config.py,sha256=RaxpAnTEyGXLiq-1O2prXFBb2sdyqB6hHDHPAFGe2k0,98472
3
- cdxcore/deferred.py,sha256=5bREI2IQ3uW3EMDcAO17gJbVnbUIV__-bdEUQpZIEeU,44684
3
+ cdxcore/deferred.py,sha256=41buUit1SOAnhVSrzlzM5hd2OOhnAS2QRDSWEpjXfdE,43138
4
4
  cdxcore/dynalimits.py,sha256=TXEwa4wCdeM5epG1ceezaHwvmhnbU-oXlXpHNbOMQR8,11293
5
- cdxcore/dynaplot.py,sha256=1g4IFTfUir13BEDNxDXxUvlwh__kq5n0kgehZ-e8ah4,51031
5
+ cdxcore/dynaplot.py,sha256=Bnjt9GEkPRXcsSqbVSsr08d71dhTZXrVab-zPxLEkaA,51355
6
6
  cdxcore/err.py,sha256=3JP1IZDMIKayTt-ZNV9PCYdjtvkybQTjZOrRmBZWyfg,14709
7
7
  cdxcore/filelock.py,sha256=D2U8rzxYkeuDc8RLRbePBQ939PPxcJuRC8sahmVx-x8,34781
8
8
  cdxcore/jcpool.py,sha256=Vw8o8S4_qTVQNIr2sRaBR_kHz_wO0zpYs0QjlKSYFz8,27280
@@ -14,7 +14,7 @@ cdxcore/uniquehash.py,sha256=WCtieiRBavfpSVT-hW4QNYGHFrfgXG3kJuTUtAi9_b0,50729
14
14
  cdxcore/util.py,sha256=dqCEhrDvUM4qjeUwb6n8jPfS8WC4Navcj83gDjXfRFE,39349
15
15
  cdxcore/verbose.py,sha256=vsjGTVnAHMPg2L2RfsowWKKPjUSnQJ3F653vDTydBkI,30223
16
16
  cdxcore/version.py,sha256=S3H0ktEZsM0zAj3EQ5AdrZ2KxWhQtemd8clzEFE9hOQ,27160
17
- cdxcore-0.1.26.dist-info/licenses/LICENSE,sha256=M-cisgK9kb1bqVRJ7vrCxHcMQQfDxdY3c2YFJJWfNQg,1090
17
+ cdxcore-0.1.27.dist-info/licenses/LICENSE,sha256=M-cisgK9kb1bqVRJ7vrCxHcMQQfDxdY3c2YFJJWfNQg,1090
18
18
  docs/source/conf.py,sha256=yn3LYgw3sT45mUyll-B2emVp6jg7H6KfAHOcBg_MNv4,4182
19
19
  tests/test_config.py,sha256=N86mH3y7k3LXEmU8uPLfrmRMZ-80VhlD35nBbpLmebg,15617
20
20
  tests/test_deferred.py,sha256=4Xsb76r-XqHKiBuHa4jbErjMWbrgHXfPwewzzY4lf9Y,7922
@@ -34,7 +34,7 @@ tmp/npsh1.py,sha256=mNucUl2-jNmE84GlMlliB4aJ0UQ9FqdymgcY_9mLeZY,15432
34
34
  tmp/sharedarray.py,sha256=dNOT1ObCc3nM3qA3OA508NcENIBnkmWMxRPCqvMVa8A,12862
35
35
  up/git_message.py,sha256=EfSH7Pit3ZoCiRqSMwRCUN_QyuwreU4LTIyGSutBlm4,123
36
36
  up/pip_modify_setup.py,sha256=Esaml4yA9tFsqxLhk5bWSwvKCURONjQqfyChgFV2TSY,1584
37
- cdxcore-0.1.26.dist-info/METADATA,sha256=YT7I_dWXka3a7RSKznr_zZO-9WC_LFmMy0DkyGSDJdE,5939
38
- cdxcore-0.1.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
39
- cdxcore-0.1.26.dist-info/top_level.txt,sha256=phNSwCyJFe7UP2YMoi8o6ykhotatlIbJHjTp9EHM51k,26
40
- cdxcore-0.1.26.dist-info/RECORD,,
37
+ cdxcore-0.1.27.dist-info/METADATA,sha256=7l4RtZbBD1kcAmBi-4jMAwkbV74SY50bbcKq0vOWKhQ,5939
38
+ cdxcore-0.1.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
39
+ cdxcore-0.1.27.dist-info/top_level.txt,sha256=phNSwCyJFe7UP2YMoi8o6ykhotatlIbJHjTp9EHM51k,26
40
+ cdxcore-0.1.27.dist-info/RECORD,,