PySimultan 0.5.0__py3-none-any.whl → 0.5.2.5__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ Version 0.5.1 (25.11.2024)
2
+
3
+ - setting re-register default in Mapper to True
4
+ - added uncache method to utils for monkey patching
PySimultan2/__about__.py CHANGED
@@ -1 +1 @@
1
- version = '0.5.0'
1
+ version = '0.5.2.5'
@@ -1,14 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
- import xxsubtype
4
3
  from collections.abc import Iterable
5
4
  import numpy as np
6
- import pandas as pd
7
5
  import colorlog
8
6
  from typing import Union, List, Type, Set, Tuple, Any, Optional
9
7
 
10
- from reactivex import return_value
11
-
12
8
  from .utils import (sort_slots, create_simultan_component_for_taxonomy, create_mapped_python_object,
13
9
  set_property_to_sim_component, set_property_to_parameter, set_property_to_file_info,
14
10
  set_property_to_list, set_property_to_value_field, set_property_to_unknown_type,
@@ -32,9 +32,21 @@ default_taxonomy_maps = {'ComponentList': component_list_map,
32
32
 
33
33
  class PythonMapper(object):
34
34
 
35
+ mappers = {}
36
+
35
37
  def __new__(cls, *args, **kwargs):
36
38
  instance = super(PythonMapper, cls).__new__(cls)
37
39
  config.set_default_mapper(instance)
40
+
41
+ if kwargs.get('add_to_mappers', True):
42
+ initial_module_name = kwargs.get('module', 'unknown_module')
43
+ module_name = initial_module_name
44
+ i = 0
45
+ while module_name in cls.mappers.keys():
46
+ module_name = f'{initial_module_name}_{i}'
47
+ i+=1
48
+ cls.mappers[module_name] = instance
49
+
38
50
  return instance
39
51
 
40
52
  def __init__(self, *args, **kwargs):
@@ -42,6 +54,9 @@ class PythonMapper(object):
42
54
  self._mapped_classes = {}
43
55
 
44
56
  self.name = kwargs.get('name', 'PythonMapper')
57
+ self._module = kwargs.get('module', 'unknown_module')
58
+ self.submodules = kwargs.get('submodules', {})
59
+
45
60
  self.registered_classes: dict[str: SimultanObject] = copy(default_registered_classes) # dict with all registered classes: {taxonomy: class}
46
61
 
47
62
  self.undefined_registered_classes: dict[str: SimultanObject] = {} # dict with all registered classes: {taxonomy: class}
@@ -59,6 +74,18 @@ class PythonMapper(object):
59
74
  self.re_register = False
60
75
  self.load_undefined = False
61
76
 
77
+ @property
78
+ def module(self):
79
+ return self._module
80
+
81
+ @module.setter
82
+ def module(self, value):
83
+ if self._module != value:
84
+ del self.mappers[self._module]
85
+
86
+ self._module = value
87
+ self.mappers[value] = self
88
+
62
89
  @property
63
90
  def mapped_classes(self):
64
91
  if len(self.registered_classes) > len(self._mapped_classes):
@@ -73,10 +100,14 @@ class PythonMapper(object):
73
100
  self._mapped_classes = value
74
101
 
75
102
  def register(self,
76
- taxonomy,
77
- cls,
78
- re_register=False,
103
+ taxonomy: str,
104
+ cls: Type[Any],
105
+ re_register=True,
106
+ update_in_other_mappers=False,
79
107
  taxonomy_map=None):
108
+
109
+ # print(f'Registering {taxonomy} with {cls} {hash(cls)}')
110
+
80
111
  if not (self.re_register or re_register) and taxonomy in self.registered_classes.keys():
81
112
  return
82
113
 
@@ -95,8 +126,28 @@ class PythonMapper(object):
95
126
  self.registered_classes[taxonomy] = cls
96
127
  self.taxonomy_maps[taxonomy] = taxonomy_map
97
128
 
129
+ if update_in_other_mappers:
130
+ self.update_from_other_mappers()
131
+
98
132
  return self.get_mapped_class(taxonomy)
99
133
 
134
+ def update_from_other_mappers(self):
135
+ for mapper in self.mappers.values():
136
+ if mapper is not self:
137
+ for cls, taxonomy in mapper.registered_classes.items():
138
+ if cls in self.registered_classes.values():
139
+ key = list(filter(lambda x: mapper.registered_classes[x] == cls,
140
+ mapper.registered_classes)
141
+ )[0]
142
+ mapper.registered_classes[key] = cls
143
+ print(f'Updated {cls} in {mapper.module} with {taxonomy}')
144
+
145
+ def update_from_submodules(self):
146
+ for submodule in self.submodules.values():
147
+ self.registered_classes.update(submodule.registered_classes)
148
+ self.taxonomy_maps.update(submodule.taxonomy_maps)
149
+ self.registered_geometry_classes.update(submodule.registered_geometry_classes)
150
+
100
151
  def create_mapped_class(self, taxonomy, cls):
101
152
 
102
153
  if any([issubclass(cls, x) for x in (SimultanObject, UserList)]):
@@ -342,19 +393,31 @@ class PythonMapper(object):
342
393
  def copy(self,
343
394
  *args,
344
395
  **kwargs) -> 'PythonMapper':
345
- new_mapper = PythonMapper()
396
+
397
+ orig_new_module_name = kwargs.get('module', self.module)
398
+ new_module_name = orig_new_module_name
399
+ i = 0
400
+ while new_module_name in self.mappers.keys():
401
+ new_module_name = f'copy_{i}_of_{new_module_name}'
402
+ i+=1
403
+
404
+ new_mapper = PythonMapper(add_to_mappers=kwargs.get('add_to_mappers', True),
405
+ module=new_module_name)
346
406
  new_mapper.registered_classes = self.registered_classes
347
407
  new_mapper.taxonomy_maps = self.taxonomy_maps
348
408
  new_mapper.registered_geometry_classes = self.registered_geometry_classes
349
409
  new_mapper.load_undefined = self.load_undefined
410
+
350
411
  return new_mapper
351
412
 
352
413
  def __add__(self, other: 'PythonMapper') -> 'PythonMapper':
353
- new_mapper = self.copy()
354
- new_mapper.registered_classes.update(other.registered_classes)
355
- new_mapper.taxonomy_maps.update(other.taxonomy_maps)
356
- new_mapper.registered_geometry_classes.update(other.registered_geometry_classes)
357
- return new_mapper
414
+ # new_mapper = self.copy(add_to_mappers=True)
415
+ self.submodules[other.module] = other
416
+ self.submodules.update(other.submodules)
417
+ self.registered_classes.update(other.registered_classes)
418
+ self.taxonomy_maps.update(other.taxonomy_maps)
419
+ self.registered_geometry_classes.update(other.registered_geometry_classes)
420
+ return self
358
421
 
359
422
  def get_mapped_class_for_python_type(self, python_type: type) -> Optional[Type[SimultanObject]]:
360
423
  try:
@@ -366,6 +429,29 @@ class PythonMapper(object):
366
429
  except IndexError:
367
430
  return None
368
431
 
432
+ def __repr__(self):
433
+ return f'PythonMapper(module={self.module}, {len(self.registered_classes)} registered classes)'
434
+
369
435
 
370
436
  if config.get_default_mapper() is None:
371
- config.set_default_mapper(PythonMapper())
437
+ config.set_default_mapper(PythonMapper(module='default'))
438
+
439
+
440
+ def register(taxonomy: str,
441
+ taxonomy_map: TaxonomyMap,
442
+ re_register=True,
443
+ module: str = 'unknown_module') -> Any:
444
+
445
+ if module not in PythonMapper.mappers.keys():
446
+ PythonMapper(module=module)
447
+
448
+ mapper = PythonMapper.mappers[module]
449
+
450
+ def decorator(cls):
451
+ mapper.register(taxonomy,
452
+ cls,
453
+ re_register=re_register,
454
+ taxonomy_map=taxonomy_map)
455
+ return cls
456
+
457
+ return decorator
PySimultan2/utils.py CHANGED
@@ -1448,3 +1448,33 @@ def add_properties(prop_name: str,
1448
1448
  delx.__taxonomy__ = taxonomy
1449
1449
 
1450
1450
  return property(getx, setx, delx, "automatic created property")
1451
+
1452
+
1453
+ def uncache(exclude):
1454
+ """Remove package modules from cache except excluded ones.
1455
+ On next import they will be reloaded.
1456
+
1457
+ Args:
1458
+ exclude (iter<str>): Sequence of module paths.
1459
+ """
1460
+ pkgs = []
1461
+ for mod in exclude:
1462
+ pkg = mod.split('.', 1)[0]
1463
+ pkgs.append(pkg)
1464
+
1465
+ to_uncache = []
1466
+ for mod in sys.modules:
1467
+ if mod in exclude:
1468
+ continue
1469
+
1470
+ if mod in pkgs:
1471
+ to_uncache.append(mod)
1472
+ continue
1473
+
1474
+ for pkg in pkgs:
1475
+ if mod.startswith(pkg + '.'):
1476
+ to_uncache.append(mod)
1477
+ break
1478
+
1479
+ for mod in to_uncache:
1480
+ del sys.modules[mod]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: PySimultan
3
- Version: 0.5.0
3
+ Version: 0.5.2.5
4
4
  Project-URL: Documentation, https://github.com/Bühler Maximilian/PySimultan2#readme
5
5
  Project-URL: Issues, https://github.com/Bühler Maximilian/PySimultan2/issues
6
6
  Project-URL: Source, https://github.com/Bühler Maximilian/PySimultan2
@@ -1,14 +1,15 @@
1
- PySimultan2/__about__.py,sha256=r3KZ-VR8WzImzZtG_Cy9406RiC9eKWaqtTphrx4AlGw,19
1
+ PySimultan2/CHANGELOG.md,sha256=kzZ_OWSL_ov67WjTEONAHoDsIf9YrbMva3g2L_ECCAw,132
2
+ PySimultan2/__about__.py,sha256=DzvKElNXxadVB8RhRx00rjp7pH4Z08fLEOKXuSsr0HE,21
2
3
  PySimultan2/__init__.py,sha256=PGVR1uhY01dF5tHyad-znURUZ_LVB95vsjId2BT0aJM,3245
3
4
  PySimultan2/data_model.py,sha256=wSEHnx5uU81CSbUpKkmpQ2gbWfDziDxNGIiKnF9-Bck,31731
4
- PySimultan2/default_types.py,sha256=xJ7nSdUhNj9P_WX_OoEo6gmvJ0P3I33k160nOsMbkAU,27234
5
+ PySimultan2/default_types.py,sha256=K-Eka5BCKk8DT3HU5761Ym_-ZFmu1_Dro0zW0LVGoHA,27157
5
6
  PySimultan2/files.py,sha256=_KQNn1WS9LEETSADbxaFXNaTZ9e66dAGhPU5K1iOcOk,14068
6
7
  PySimultan2/multi_values.py,sha256=ZFXlTLuZo32x7_7diYAp2XEjp5uwgHLgNOzN7v74-5I,13650
7
- PySimultan2/object_mapper.py,sha256=Inx7jj8VkuvjMibWiP3PcymATllvP2prUW-pRQaT15M,15535
8
+ PySimultan2/object_mapper.py,sha256=hfb28szyH_AeGetYm3ij_RTV2eBdPaBUeHZuagoYRFQ,18630
8
9
  PySimultan2/simultan_object.py,sha256=akaSUZZWIVfwx1wT5EdOgRR2UeShUthX-LE2Uk6w8CQ,19058
9
10
  PySimultan2/taxonomy_maps.py,sha256=abMB2RSKEaliW-Ewegq-Inq9npHeOD1VVrMYoKJAlC0,8762
10
11
  PySimultan2/type_setter_lookup.py,sha256=WtopIR2Z3v3wNFtqmeVorH7ZUbKoJYTTe5I3vfQuKUI,3404
11
- PySimultan2/utils.py,sha256=wIN169fAne6xc_DgppscyB17uj8pAkptyaX_89CcJrc,63110
12
+ PySimultan2/utils.py,sha256=_GnKNdpCTQaYg4XYvaSSV1LeVOcTiKhFmUOfHc7YiH0,63805
12
13
  PySimultan2/geometry/__init__.py,sha256=nJolTD1i5J8qUkOQa-r3D20aq3Co3sN31Xc0n4wJpJo,248
13
14
  PySimultan2/geometry/geometry_base.py,sha256=nbb9U2W3vFviVLxISLHRi2CVyLEM-3zIKvoZ1uSYs_8,23420
14
15
  PySimultan2/geometry/utils.py,sha256=J25YsK8sso_UL7xRusItQZvyjtvxdOsSPelBQYFABhY,8519
@@ -74,7 +75,7 @@ PySimultan2/resources/assimp.dll,sha256=HwfDwXqoPDTFRyoQpA3qmgZoUdFtziJkV5fNtktE
74
75
  PySimultan2/resources/componentmanager.user,sha256=hrzr1US4pqkFnLHXcvPkvrgGd7QvlxaV8mhS6fuikEs,760
75
76
  PySimultan2/resources/defaultsettings.xml,sha256=s6Tk1tubLz5UYqXZWpD42EDHzedemRY1nEneoIVcUfg,392
76
77
  PySimultan2/resources/setup.bat,sha256=fjvvYfVM6TalS-QTSiKAbAId5nTsk8kGGo06ba-wWaY,32
77
- pysimultan-0.5.0.dist-info/METADATA,sha256=ija9DqBqK2nmbyuXJ1h6EboV-sWF_M6vx5n6IZjaQY0,2665
78
- pysimultan-0.5.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
79
- pysimultan-0.5.0.dist-info/licenses/LICENSE.txt,sha256=pmSr98k6N005KMojnZxzLGRuRlDjDx3PUrK1lFj53HA,1126
80
- pysimultan-0.5.0.dist-info/RECORD,,
78
+ pysimultan-0.5.2.5.dist-info/METADATA,sha256=7FPc9s_qFPm-LzcXJG9G1WxikeyZHKmm2SBzJJ_TkIA,2667
79
+ pysimultan-0.5.2.5.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
80
+ pysimultan-0.5.2.5.dist-info/licenses/LICENSE.txt,sha256=pmSr98k6N005KMojnZxzLGRuRlDjDx3PUrK1lFj53HA,1126
81
+ pysimultan-0.5.2.5.dist-info/RECORD,,