FoSpy 0.0.1__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.
FoSpy/__init__.py ADDED
@@ -0,0 +1,50 @@
1
+ def inherit_docstring(parent, label="Parent"):
2
+ def decorator(func):
3
+ parent_doc = getattr(parent, func.__name__).__doc__
4
+ if parent_doc:
5
+ func.__doc__ = (func.__doc__ or "") + f"\n\n{label} doc: `{parent.__name__}.{func.__name__}`\n" + parent_doc
6
+ return func
7
+ return decorator
8
+
9
+ def attach_doc(source, label="Related"):
10
+ """
11
+ Attach the docstring from `source` to the decorated function or class.
12
+
13
+ `source` may be:
14
+ • a function
15
+ • a class
16
+ • any object with a __doc__ attribute
17
+ • a literal string (treated as a docstring)
18
+ """
19
+ # Resolve the docstring
20
+ if isinstance(source, str):
21
+ source_doc = source
22
+ source_name = None
23
+ else:
24
+ source_doc = getattr(source, "__doc__", None)
25
+ source_name = getattr(source, "__qualname__", None)
26
+
27
+ def decorator(obj):
28
+ if source_doc:
29
+ header = f"\n\n{label} doc"
30
+ if source_name:
31
+ header += f": `{source_name}`"
32
+ header += "\n"
33
+
34
+ obj.__doc__ = (obj.__doc__ or "") + header + source_doc
35
+ return obj
36
+
37
+ return decorator
38
+
39
+
40
+ def inherit_class_doc(parent):
41
+ def decorator(cls):
42
+ parent_doc = parent.__doc__
43
+ if parent_doc:
44
+ cls.__doc__ = (cls.__doc__ or "") + f"\n\nParent doc: `{parent.__name__}`\n" + parent_doc
45
+ return cls
46
+ return decorator
47
+
48
+
49
+ from FoSpy.blocks import *
50
+ from FoSpy.parsing import *
FoSpy/_debug.py ADDED
@@ -0,0 +1,72 @@
1
+ from pprint import pprint
2
+ import sys
3
+ import inspect
4
+ import io
5
+
6
+ DEBUG_WIDTH = 120
7
+
8
+ class Debug:
9
+ def __init__(self):
10
+ self.on = False
11
+
12
+ frame = inspect.currentframe().f_back
13
+ self.module_name = frame.f_globals.get("__name__", "<unknown>")
14
+ self.label = f"|(Debug message from {self.module_name})"
15
+ self.label_width = len(self.label)
16
+
17
+ def msg(self,msg):
18
+ self.pmsg(str(msg))
19
+
20
+ def pmsg(self,msg,**kwargs):
21
+ if self.on:
22
+ text_width = DEBUG_WIDTH - self.label_width
23
+
24
+ buf = io.StringIO()
25
+ pprint(msg,stream=buf, width=text_width,**kwargs)
26
+ txt = buf.getvalue()
27
+ for line in txt.splitlines():
28
+ print(f'{line:<{text_width}}{self.label:>{self.label_width}}')
29
+
30
+ def _find_debugs():
31
+ results = []
32
+ for name, module in sys.modules.items():
33
+ # Some entries in sys.modules are None (partially imported modules)
34
+ if module is None:
35
+ continue
36
+
37
+ if hasattr(module, "_debug"):
38
+ results.append((name, module._debug))
39
+ return results
40
+
41
+ def debug_status():
42
+ results = []
43
+ for module, debug_obj in _find_debugs():
44
+ if hasattr(debug_obj,"on"):
45
+ results.append((module, 'ON' if debug_obj.on else "OFF"))
46
+ return results
47
+
48
+
49
+ def all_debugs_on(soundoff=True):
50
+ for module, debug_obj in _find_debugs():
51
+ if hasattr(debug_obj,"on"):
52
+ debug_obj.on = True
53
+ if soundoff:
54
+ debug_obj.msg("Turning Debug On")
55
+
56
+ def all_debugs_off(soundoff=True):
57
+ all_debugs_on(soundoff=False)
58
+ for module, debug_obj in _find_debugs():
59
+ if hasattr(debug_obj,"on"):
60
+ if soundoff:
61
+ debug_obj.msg("Turning Debug Off")
62
+ debug_obj.on = False
63
+
64
+
65
+ if __name__ == "__main__":
66
+ from pprint import pp
67
+ from FoSpy import *
68
+ pp(debug_status())
69
+
70
+
71
+
72
+
@@ -0,0 +1,30 @@
1
+ """Classes for representing blocks of information in a FOS file.
2
+
3
+ Synthesis objects are constructed as a FileBlock subclass, which contain
4
+ attributes specified by headers in the file. Each FileBlock attribute
5
+ is a subclass object of another block class (either SingleBlock or ListBlock)
6
+ ListBlocks wrap a list of SingleBlock objects.
7
+ SingleBlock attributes can be assigned to simple values or other blocks.
8
+
9
+ Typical usage:
10
+ ```
11
+ mySyn = Synthesis.fromFile("C:\\my.fos")
12
+
13
+ # mySyn.reaction is a SingleBlock object
14
+ # mySyn.reaction.nominal_mass is a Decimal value
15
+ nom_mass = mySyn.reaction.nominal_mass
16
+
17
+ # mySyn.materials is a ListBlock object containing SingleBlock Material objects.
18
+ zinc = mySyn.materials[0]
19
+ print(zinc.formula)
20
+ """
21
+
22
+
23
+ from .blocks import *
24
+ from .embedded import *
25
+ from .template import *
26
+ from .synthesis import *
27
+ from .materials import *
28
+ from .metadata import *
29
+ from .treatments import *
30
+