jaseci 1.4.2.6__py3-none-any.whl → 2.0.0__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 jaseci might be problematic. Click here for more details.

Files changed (187) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.6.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -118
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -77
  16. jaseci/extens/act_lib/file_handler.py +0 -190
  17. jaseci/extens/act_lib/internal.py +0 -19
  18. jaseci/extens/act_lib/jaseci.py +0 -62
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -192
  22. jaseci/extens/act_lib/rand.py +0 -83
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -170
  25. jaseci/extens/act_lib/std.py +0 -236
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -338
  28. jaseci/extens/act_lib/task.py +0 -14
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -80
  46. jaseci/extens/act_lib/vector.py +0 -158
  47. jaseci/extens/act_lib/webtool.py +0 -29
  48. jaseci/extens/act_lib/zip.py +0 -34
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -171
  51. jaseci/extens/api/alias_api.py +0 -140
  52. jaseci/extens/api/architype_api.py +0 -197
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -85
  55. jaseci/extens/api/graph_api.py +0 -168
  56. jaseci/extens/api/health_api.py +0 -21
  57. jaseci/extens/api/interface.py +0 -269
  58. jaseci/extens/api/jac_api.py +0 -172
  59. jaseci/extens/api/jsorc_api.py +0 -317
  60. jaseci/extens/api/logger_api.py +0 -90
  61. jaseci/extens/api/master_api.py +0 -134
  62. jaseci/extens/api/object_api.py +0 -102
  63. jaseci/extens/api/prometheus_api.py +0 -75
  64. jaseci/extens/api/queue_api.py +0 -141
  65. jaseci/extens/api/sentinel_api.py +0 -271
  66. jaseci/extens/api/share_api.py +0 -64
  67. jaseci/extens/api/super_api.py +0 -65
  68. jaseci/extens/api/tests/__init__.py +0 -0
  69. jaseci/extens/api/tests/test_architype_api.py +0 -66
  70. jaseci/extens/api/tests/test_global_api.py +0 -179
  71. jaseci/extens/api/tests/test_graph_api.py +0 -64
  72. jaseci/extens/api/tests/test_logger_api.py +0 -43
  73. jaseci/extens/api/tests/test_object_api.py +0 -20
  74. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  75. jaseci/extens/api/tests/test_uncommon.py +0 -107
  76. jaseci/extens/api/tests/test_user_api.py +0 -32
  77. jaseci/extens/api/tests/test_walker_api.py +0 -316
  78. jaseci/extens/api/user_api.py +0 -166
  79. jaseci/extens/api/walker_api.py +0 -299
  80. jaseci/extens/api/webhook_api.py +0 -77
  81. jaseci/extens/svc/__init__.py +0 -0
  82. jaseci/extens/svc/elastic_svc.py +0 -366
  83. jaseci/extens/svc/kube_svc.py +0 -432
  84. jaseci/extens/svc/mail_svc.py +0 -156
  85. jaseci/extens/svc/prome_svc.py +0 -378
  86. jaseci/extens/svc/redis_svc.py +0 -63
  87. jaseci/extens/svc/storage_svc.py +0 -193
  88. jaseci/extens/svc/stripe_svc.py +0 -51
  89. jaseci/extens/svc/task_svc.py +0 -155
  90. jaseci/extens/svc/tasks.py +0 -302
  91. jaseci/jac/__init__.py +0 -0
  92. jaseci/jac/interpreter/__init__.py +0 -0
  93. jaseci/jac/interpreter/architype_interp.py +0 -219
  94. jaseci/jac/interpreter/interp.py +0 -1784
  95. jaseci/jac/interpreter/sentinel_interp.py +0 -260
  96. jaseci/jac/interpreter/tests/__init__.py +0 -0
  97. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  98. jaseci/jac/interpreter/walker_interp.py +0 -249
  99. jaseci/jac/ir/__init__.py +0 -0
  100. jaseci/jac/ir/ast.py +0 -73
  101. jaseci/jac/ir/ast_builder.py +0 -249
  102. jaseci/jac/ir/jac_code.py +0 -151
  103. jaseci/jac/ir/passes/__init__.py +0 -6
  104. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  105. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  106. jaseci/jac/ir/passes/ir_pass.py +0 -29
  107. jaseci/jac/ir/passes/printer_pass.py +0 -23
  108. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  109. jaseci/jac/ir/passes/schedule.py +0 -23
  110. jaseci/jac/ir/passes/stats_pass.py +0 -16
  111. jaseci/jac/jac.g4 +0 -450
  112. jaseci/jac/jac_parse/__init__.py +0 -0
  113. jaseci/jac/jac_parse/jacLexer.py +0 -809
  114. jaseci/jac/jac_parse/jacListener.py +0 -853
  115. jaseci/jac/jac_parse/jacParser.py +0 -9192
  116. jaseci/jac/jac_set.py +0 -120
  117. jaseci/jac/jsci_vm/__init__.py +0 -0
  118. jaseci/jac/jsci_vm/disasm.py +0 -94
  119. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  120. jaseci/jac/jsci_vm/machine.py +0 -188
  121. jaseci/jac/jsci_vm/op_codes.py +0 -82
  122. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  123. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  124. jaseci/jac/machine/__init__.py +0 -0
  125. jaseci/jac/machine/jac_scope.py +0 -86
  126. jaseci/jac/machine/jac_value.py +0 -227
  127. jaseci/jac/machine/machine_state.py +0 -386
  128. jaseci/jac/tests/__init__.py +0 -0
  129. jaseci/jac/tests/book_code.py +0 -624
  130. jaseci/jac/tests/test_book.py +0 -380
  131. jaseci/jac/tests/test_lang_14.py +0 -49
  132. jaseci/jsorc/__init__.py +0 -7
  133. jaseci/jsorc/jsorc.py +0 -642
  134. jaseci/jsorc/jsorc_settings.py +0 -211
  135. jaseci/jsorc/jsorc_utils.py +0 -298
  136. jaseci/jsorc/live_actions.py +0 -365
  137. jaseci/jsorc/manifests/__init__.py +0 -0
  138. jaseci/jsorc/manifests/database.yaml +0 -109
  139. jaseci/jsorc/manifests/elastic.yaml +0 -6029
  140. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  141. jaseci/jsorc/manifests/redis.yaml +0 -64
  142. jaseci/jsorc/memory.py +0 -258
  143. jaseci/jsorc/redis.py +0 -140
  144. jaseci/jsorc/remote_actions.py +0 -158
  145. jaseci/jsorc/tests/__init__.py +0 -0
  146. jaseci/jsorc/tests/test_actions.py +0 -542
  147. jaseci/jsorc/tests/test_jsorc.py +0 -112
  148. jaseci/prim/__init__.py +0 -0
  149. jaseci/prim/ability.py +0 -94
  150. jaseci/prim/architype.py +0 -90
  151. jaseci/prim/edge.py +0 -173
  152. jaseci/prim/element.py +0 -233
  153. jaseci/prim/graph.py +0 -27
  154. jaseci/prim/master.py +0 -67
  155. jaseci/prim/node.py +0 -533
  156. jaseci/prim/obj_mixins.py +0 -238
  157. jaseci/prim/sentinel.py +0 -282
  158. jaseci/prim/super_master.py +0 -31
  159. jaseci/prim/walker.py +0 -261
  160. jaseci/svc/__init__.py +0 -0
  161. jaseci/tests/__init__.py +0 -0
  162. jaseci/tests/infer.py +0 -39
  163. jaseci/tests/jac_test_code.py +0 -1293
  164. jaseci/tests/jac_test_progs.py +0 -774
  165. jaseci/tests/test_core.py +0 -153
  166. jaseci/tests/test_jac.py +0 -824
  167. jaseci/tests/test_node.py +0 -89
  168. jaseci/tests/test_progs.py +0 -702
  169. jaseci/tests/test_stack.py +0 -220
  170. jaseci/tests/test_stripe.py +0 -225
  171. jaseci/utils/__init__.py +0 -0
  172. jaseci/utils/actions/__init__.py +0 -0
  173. jaseci/utils/actions/actions_manager.py +0 -254
  174. jaseci/utils/actions/actions_optimizer.py +0 -517
  175. jaseci/utils/actions/actions_state.py +0 -95
  176. jaseci/utils/file_handler.py +0 -171
  177. jaseci/utils/gprof2dot.py +0 -3786
  178. jaseci/utils/id_list.py +0 -169
  179. jaseci/utils/json_handler.py +0 -70
  180. jaseci/utils/log_utils.py +0 -57
  181. jaseci/utils/test_core.py +0 -62
  182. jaseci/utils/utils.py +0 -387
  183. jaseci-1.4.2.6.dist-info/LICENSE +0 -21
  184. jaseci-1.4.2.6.dist-info/METADATA +0 -39
  185. jaseci-1.4.2.6.dist-info/RECORD +0 -185
  186. jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
  187. jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
@@ -1,168 +0,0 @@
1
- """
2
- Graph api functions as a mixin
3
- """
4
-
5
- from jaseci.extens.api.interface import Interface
6
- from jaseci.utils.id_list import IdList
7
- from jaseci.prim.graph import Graph
8
- from jaseci.prim.node import Node
9
- import uuid
10
-
11
-
12
- class GraphApi:
13
- """
14
- Graph APIs
15
- """
16
-
17
- def __init__(self):
18
- self.active_gph_id = None
19
- self.graph_ids = IdList(self)
20
-
21
- @Interface.private_api()
22
- def graph_create(self, set_active: bool = True):
23
- """
24
- Create a graph instance and return root node graph object
25
- """
26
- gph = Graph(m_id=self._m_id, h=self._h)
27
- self.graph_ids.add_obj(gph)
28
- if set_active:
29
- self.graph_active_set(gph)
30
- return gph.serialize()
31
-
32
- @Interface.private_api()
33
- def graph_get(
34
- self,
35
- nd: Node = None,
36
- mode: str = "default",
37
- detailed: bool = False,
38
- depth: int = 0,
39
- ):
40
- """
41
- Return the content of the graph with mode
42
- Valid modes: {default, dot, }
43
- """
44
- if mode == "dot":
45
- return nd.traversing_dot_str(detailed, depth)
46
-
47
- nodes, edges = nd.get_all_architypes(depth)
48
- items = []
49
- for i in nodes.values():
50
- items.append(i.serialize(detailed=detailed))
51
- for i in edges.values():
52
- items.append(i.serialize(detailed=detailed))
53
- return items
54
-
55
- @Interface.private_api()
56
- def graph_list(self, detailed: bool = False):
57
- """
58
- Provide complete list of all graph objects (list of root node objects)
59
- """
60
- gphs = []
61
- for i in self.graph_ids.obj_list():
62
- gphs.append(i.serialize(detailed=detailed))
63
- return gphs
64
-
65
- @Interface.private_api(cli_args=["gph"])
66
- def graph_active_set(self, gph: Graph):
67
- """
68
- Sets the default graph master should use
69
- """
70
- self.active_gph_id = gph.jid
71
- self.alias_register("active:graph", gph.jid)
72
- return [f"Graph {gph.id} set as default"]
73
-
74
- @Interface.private_api()
75
- def graph_active_unset(self):
76
- """
77
- Unsets the default sentinel master should use
78
- """
79
- self.active_gph_id = None
80
- self.alias_delete("active:graph")
81
- return ["Default graph unset"]
82
-
83
- @Interface.private_api()
84
- def graph_active_get(self, detailed: bool = False):
85
- """
86
- Returns the default graph master is using
87
- """
88
- if self.active_gph_id:
89
- default = self._h.get_obj(self._m_id, self.active_gph_id)
90
- return default.serialize(detailed=detailed)
91
- else:
92
- return {"success": False, "response": "No default graph is selected!"}
93
-
94
- @Interface.private_api(cli_args=["gph"])
95
- def graph_delete(self, gph: Graph):
96
- """
97
- Permanently delete graph with given id
98
- """
99
- if self.active_gph_id == gph.jid:
100
- self.graph_active_unset()
101
- self.graph_ids.destroy_obj(gph)
102
- return [f"Graph {gph.id} successfully deleted"]
103
-
104
- @Interface.private_api(cli_args=["nd"])
105
- def graph_node_get(self, nd: Node, keys: list = []):
106
- """
107
- Returns value a given node
108
- """
109
- ret = {}
110
- nd_ctx = nd.serialize(detailed=True)["context"]
111
- for i in nd_ctx.keys():
112
- if not len(keys) or i in keys:
113
- ret[i] = nd_ctx[i]
114
- return ret
115
-
116
- @Interface.private_api(cli_args=["nd"])
117
- def graph_node_view(
118
- self,
119
- nd: Node = None,
120
- detailed: bool = False,
121
- show_edges: bool = False,
122
- node_type: str = "",
123
- edge_type: str = "",
124
- ):
125
- """
126
- Returns value a given node
127
- """
128
- ret = [nd.serialize(detailed=detailed)]
129
- for i in nd.attached_nodes():
130
- if not len(node_type) or i.name == node_type:
131
- edges = [
132
- en
133
- for en in nd.attached_edges(i)
134
- if not len(edge_type) or en.name == edge_type
135
- ]
136
- if len(edges):
137
- ret.append(i.serialize(detailed=detailed))
138
- if show_edges:
139
- for j in edges:
140
- ret.append(j.serialize(detailed=detailed))
141
- return ret
142
-
143
- @Interface.private_api(cli_args=["nd"])
144
- def graph_node_set(self, nd: Node, ctx: dict):
145
- """
146
- Assigns values to member variables of a given node using ctx object
147
- """
148
- nd.set_context(ctx=ctx)
149
- return nd.serialize()
150
-
151
- @Interface.cli_api(cli_args=["file"])
152
- def graph_walk(self, nd: Node = None):
153
- cmd = ""
154
- while cmd not in ["quit", "q", "exit"]:
155
- print(
156
- "location - " + ":".join([nd.kind, nd.name, nd.jid.strip("urn:uuid:")])
157
- )
158
- cmd = input("graph_walk_mode > ")
159
-
160
- def active_gph(self):
161
- return self._h.get_obj(self._m_id, self.active_gph_id)
162
-
163
- def destroy(self):
164
- """
165
- Destroys self from memory and persistent storage
166
- """
167
- for i in self.graph_ids.obj_list():
168
- i.destroy()
@@ -1,21 +0,0 @@
1
- """
2
- Health APIs
3
- """
4
-
5
- from jaseci.jsorc.jsorc import JsOrc
6
- from jaseci.extens.api.interface import Interface
7
-
8
-
9
- class HealthApi:
10
- """
11
- API for readiness probe
12
- """
13
-
14
- @Interface.public_api(allowed_methods=["get"])
15
- def health(self):
16
- """
17
- readiness probe
18
- """
19
- # to update
20
- # we might need to return some other information here
21
- return JsOrc.__running__
@@ -1,269 +0,0 @@
1
- """
2
- General master interface engine for client interfaces as mixin
3
- """
4
-
5
- from inspect import signature, getdoc
6
- from jaseci.utils.utils import logger, is_jsonable, is_true, exc_stack_as_str_list
7
- from jaseci.prim.element import Element
8
- from jaseci.prim.walker import Walker
9
- import json
10
-
11
-
12
- class Interface:
13
- """
14
- General master interface engine
15
- """
16
-
17
- _public_api = []
18
- _private_api = []
19
- _admin_api = []
20
- _cli_api = []
21
-
22
- def __init__(self):
23
- """
24
- self._pub_committer is set by api implementaiton if intent
25
- is to commit changes enacted by public call
26
- """
27
- self._pub_committer = None
28
-
29
- def assimilate_api(
30
- api_list,
31
- func,
32
- cmd_group=None,
33
- cli_args=None,
34
- url_args=None,
35
- allowed_methods=None,
36
- ):
37
- cmd_group = func.__name__.split("_") if cmd_group is None else cmd_group
38
- api_list.append(
39
- {
40
- "fname": func.__name__,
41
- "sig": signature(func),
42
- "doc": getdoc(func),
43
- "groups": cmd_group,
44
- "cli_args": cli_args if cli_args is not None else [],
45
- "url_args": url_args if url_args is not None else [],
46
- "allowed_methods": allowed_methods,
47
- }
48
- )
49
- return func
50
-
51
- def public_api(cmd_group=None, cli_args=None, url_args=None, allowed_methods=None):
52
- def decorator_func(func):
53
- return Interface.assimilate_api(
54
- Interface._public_api,
55
- func,
56
- cmd_group,
57
- cli_args,
58
- url_args,
59
- allowed_methods,
60
- )
61
-
62
- return decorator_func
63
-
64
- def private_api(cmd_group=None, cli_args=None, url_args=None, allowed_methods=None):
65
- def decorator_func(func):
66
- return Interface.assimilate_api(
67
- Interface._private_api,
68
- func,
69
- cmd_group,
70
- cli_args,
71
- url_args,
72
- allowed_methods,
73
- )
74
-
75
- return decorator_func
76
-
77
- def admin_api(cmd_group=None, cli_args=None, url_args=None, allowed_methods=None):
78
- def decorator_func(func):
79
- return Interface.assimilate_api(
80
- Interface._admin_api,
81
- func,
82
- cmd_group,
83
- cli_args,
84
- url_args,
85
- allowed_methods,
86
- )
87
-
88
- return decorator_func
89
-
90
- def cli_api(cmd_group=None, cli_args=None):
91
- def decorator_func(func):
92
- return Interface.assimilate_api(
93
- Interface._cli_api, func, cmd_group, cli_args
94
- )
95
-
96
- return decorator_func
97
-
98
- def all_apis(self, with_cli_only=False):
99
- ret = Interface._public_api + Interface._private_api + Interface._admin_api
100
- if with_cli_only:
101
- return ret + Interface._cli_api
102
- return ret
103
-
104
- assimilate_api = staticmethod(assimilate_api)
105
- public_api = staticmethod(public_api)
106
- private_api = staticmethod(private_api)
107
- admin_api = staticmethod(admin_api)
108
- cli_api = staticmethod(cli_api)
109
-
110
- def provide_internal_default(self, param):
111
- """
112
- Applies internal defaults for sentinel and graphs
113
- """
114
- if param == "snt" and self.active_snt_id:
115
- if self.active_snt_id == "global":
116
- glob_id = self._h.get_glob("GLOB_SENTINEL")
117
- if not glob_id:
118
- return self.interface_error("No global sentinel is available!")
119
- else:
120
- return glob_id
121
- return self.active_snt_id
122
- if param == "gph" or param == "nd":
123
- return (
124
- self.active_gph_id
125
- if self.active_gph_id
126
- else self.interface_error("No default graph node available!")
127
- )
128
- return None
129
-
130
- def interface_error(self, err, stack=None):
131
- """Standard error output to logger and api response"""
132
- logger.error(err)
133
- ret = {"response": err, "success": False, "errors": [err]}
134
- if stack:
135
- ret["stack_trace"] = stack
136
- return ret
137
-
138
- def general_interface_to_api(self, params, api_name):
139
- """
140
- A mapper utility to interface to master class
141
- Assumptions:
142
- params is a dictionary of parameter names and values in UUID
143
- api_name is the name of the api being mapped to
144
- """
145
- param_map = {}
146
- if (
147
- api_name.startswith("master_active")
148
- or api_name.startswith("master_become")
149
- or api_name.startswith("master_unbecome")
150
- ):
151
- _caller = self
152
- elif self.caller:
153
- _caller = self._h.get_obj(self._m_id, self.caller)
154
- else:
155
- _caller = self
156
- if not hasattr(_caller, api_name):
157
- return self.interface_error(f"{api_name} not a valid API")
158
- func_sig = signature(getattr(_caller, api_name))
159
- for i in func_sig.parameters.keys():
160
- if i == "self":
161
- continue
162
- p_name = i
163
- p_type = func_sig.parameters[i].annotation
164
- p_default = func_sig.parameters[i].default
165
- val = p_default if p_default is not func_sig.parameters[i].empty else None
166
- if p_name in params.keys():
167
- val = params[p_name]
168
- if val is None: # Used to patch defaults
169
- val = _caller.provide_internal_default(p_name)
170
- if val is not None and "errors" in val:
171
- return val
172
- if p_type == dict and isinstance(val, str):
173
- if not len(val):
174
- val = {}
175
- else:
176
- val = json.loads(val)
177
- if str(val) in _caller.alias_map.keys():
178
- val = _caller.alias_map[val]
179
- if issubclass(p_type, Element):
180
- if val is None:
181
- break
182
- val = _caller._h.get_obj(_caller._m_id, val)
183
- if isinstance(val, p_type):
184
- param_map[i] = self.sync_constraints(val, params)
185
- else:
186
- return self.interface_error(f"{type(val)} is not {p_type}")
187
- else: # TODO: Can do type checks here too
188
- param_map[i] = val
189
-
190
- if p_default and param_map[i] is None:
191
- return self.interface_error(f"Invalid API args - {params}")
192
- try:
193
- ret = getattr(_caller, api_name)(**param_map)
194
- except Exception as e:
195
- return self.interface_error(
196
- f"Internal Exception: {e}", stack=exc_stack_as_str_list()
197
- )
198
- if not is_jsonable(ret):
199
- return self.interface_error(f"Non-JSON API ret {type(ret)}: {ret}")
200
- return ret
201
-
202
- def public_interface_to_api(self, params, api_name):
203
- """
204
- A mapper utility to interface to public
205
- Assumptions:
206
- params is a dictionary of parameter names and values in UUID
207
- api_name is the name of the api being mapped to
208
- """
209
- param_map = {}
210
- if not hasattr(self, api_name):
211
- return self.interface_error(f"{api_name} not a valid API")
212
- func_sig = signature(getattr(self, api_name))
213
- for i in func_sig.parameters.keys():
214
- if i == "self":
215
- continue
216
- p_name = i
217
- p_type = func_sig.parameters[i].annotation
218
- p_default = func_sig.parameters[i].default
219
- val = p_default if p_default is not func_sig.parameters[i].empty else None
220
- if p_name in params.keys():
221
- val = params[p_name]
222
- if p_type == dict and isinstance(val, str):
223
- if not len(val):
224
- val = {}
225
- else:
226
- val = json.loads(val)
227
- if issubclass(p_type, Element):
228
- if val is None:
229
- return self.interface_error(
230
- f"No {p_type} value for {p_name} provided!"
231
- )
232
- val = self._h.get_obj("override", val, override=True)
233
- self.seek_committer(val)
234
- if isinstance(val, p_type):
235
- param_map[i] = self.sync_constraints(val, params)
236
- else:
237
- return self.interface_error(f"{type(val)} is not {p_type}")
238
- else: # TODO: Can do type checks here too
239
- param_map[i] = val
240
-
241
- if param_map[i] is None:
242
- return self.interface_error(f"Invalid API parameter set - {params}")
243
- try:
244
- ret = getattr(self, api_name)(**param_map)
245
- except Exception as e:
246
- return self.interface_error(
247
- f"Internal Exception: {e}", stack=exc_stack_as_str_list()
248
- )
249
- if not is_jsonable(ret):
250
- return self.interface_error(
251
- str(f"API returns non json object {type(ret)}: {ret}")
252
- )
253
- return ret
254
-
255
- # future constraints other than `async` should be add here
256
- def sync_constraints(self, obj, params):
257
- if isinstance(obj, Walker):
258
- obj.is_async = is_true(params.get("is_async", obj.is_async))
259
-
260
- return obj
261
-
262
- def seek_committer(self, obj):
263
- """Opportunistically assign a committer"""
264
- if not self._pub_committer and not (obj is None):
265
- self._pub_committer = obj._h.get_obj(obj._m_id, obj._m_id)
266
-
267
- def clear_committer(self):
268
- """Unset committer"""
269
- self._pub_committer = None
@@ -1,172 +0,0 @@
1
- """
2
- Jac tools api functions as a mixin
3
- """
4
-
5
- from copy import deepcopy
6
- import json
7
- import os
8
-
9
- from jaseci.extens.api.interface import Interface
10
- from jaseci.jsorc.jsorc import JsOrc
11
-
12
-
13
- class JacApi:
14
- """
15
- Jac tool APIs
16
- """
17
-
18
- @Interface.cli_api(cli_args=["file"])
19
- def jac_build(self, file: str, out: str = "", opt_level: int = 4):
20
- """
21
- Command line tooling for building executable jac ir
22
- """
23
- filename, dir = self.check_for_file(file)
24
- if not len(out):
25
- if file.endswith(".jac"):
26
- out = file.replace(".jac", ".jir")
27
- else:
28
- out = file + ".jir"
29
- faux = self.faux_master()
30
- with open(file, "r") as file:
31
- ret = faux.sentinel_register(
32
- code=file.read(),
33
- code_dir=dir,
34
- name=filename,
35
- auto_run="",
36
- opt_level=opt_level,
37
- )
38
- if "success" in ret and not ret["success"]:
39
- return ret
40
- with open(out, "w") as ofile:
41
- jir_out = json.dumps(
42
- faux.sentinel_get(mode="ir", snt=faux.active_snt())
43
- )
44
- ofile.write(jir_out)
45
- ret = f"Build of {out} complete!"
46
-
47
- return ret
48
-
49
- @Interface.cli_api(cli_args=["file"])
50
- def jac_disas(self, file: str):
51
- """
52
- Command line tooling for print IR for both .jac code files
53
- and .jir executables
54
- """
55
- filename, dir = self.check_for_file(file)
56
- is_jir = file.endswith(".jir")
57
- faux = self.faux_master()
58
- with open(file, "r") as file:
59
- if is_jir:
60
- faux.sentinel_register(name=filename)
61
- ret = faux.sentinel_set(
62
- snt=faux.active_snt(), code=file.read(), mode="ir"
63
- )
64
- faux.active_snt().print_ir()
65
- else:
66
- ret = faux.sentinel_register(
67
- code=file.read(), code_dir=dir, name=filename, auto_run=""
68
- )
69
- faux.active_snt().print_ir()
70
- if "success" in ret and not ret["success"]:
71
- return ret
72
-
73
- @Interface.cli_api(cli_args=["file"])
74
- def jac_test(
75
- self,
76
- file: str,
77
- single: str = "",
78
- profiling: bool = False,
79
- detailed: bool = False,
80
- ):
81
- """
82
- Command line tooling for running all test in both .jac code files
83
- and .jir executables
84
- """
85
- filename, dir = self.check_for_file(file)
86
- is_jir = file.endswith(".jir")
87
- faux = self.faux_master()
88
- with open(file, "r") as file:
89
- if is_jir:
90
- faux.sentinel_register(name=filename)
91
- faux.sentinel_set(snt=faux.active_snt(), code=file.read(), mode="ir")
92
- else:
93
- ret = faux.sentinel_register(
94
- code=file.read(), code_dir=dir, name=filename, auto_run=""
95
- )
96
- if "success" in ret and not ret["success"]:
97
- return ret
98
- return faux.sentinel_test(
99
- snt=faux.active_snt(), single=single, profiling=profiling, detailed=detailed
100
- )
101
-
102
- @Interface.cli_api(cli_args=["file"])
103
- def jac_run(
104
- self, file: str, walk: str = "init", ctx: dict = {}, profiling: bool = False
105
- ):
106
- """
107
- Command line tooling for running all test in both .jac code files
108
- and .jir executables
109
- """
110
- filename, dir = self.check_for_file(file)
111
- is_jir = file.endswith(".jir")
112
- faux = self.faux_master()
113
- with open(file, "r") as file:
114
- if is_jir:
115
- faux.sentinel_register(name=filename)
116
- faux.sentinel_set(snt=faux.active_snt(), code=file.read(), mode="ir")
117
- else:
118
- ret = faux.sentinel_register(
119
- code=file.read(), code_dir=dir, name=filename, auto_run=""
120
- )
121
- if "success" in ret and not ret["success"]:
122
- return ret
123
- return faux.walker_run(
124
- name=walk,
125
- snt=faux.active_snt(),
126
- nd=faux.active_gph(),
127
- ctx=ctx,
128
- profiling=profiling,
129
- )
130
-
131
- @Interface.cli_api(cli_args=["file"])
132
- def jac_dot(
133
- self, file: str, walk: str = "init", ctx: dict = {}, detailed: bool = False
134
- ):
135
- """
136
- Command line tooling for a walker then output graph in both .jac code
137
- files and .jir executables
138
- """
139
- filename, dir = self.check_for_file(file)
140
- is_jir = file.endswith(".jir")
141
- faux = self.faux_master()
142
- with open(file, "r") as file:
143
- if is_jir:
144
- faux.sentinel_register(name=filename)
145
- faux.sentinel_set(snt=faux.active_snt(), code=file.read(), mode="ir")
146
- else:
147
- ret = faux.sentinel_register(
148
- code=file.read(), name=filename, code_dir=dir, auto_run=""
149
- )
150
- if "success" in ret and not ret["success"]:
151
- return ret
152
- faux.walker_run(
153
- name=walk,
154
- snt=faux.active_snt(),
155
- nd=faux.active_gph(),
156
- ctx=ctx,
157
- profiling=False,
158
- )
159
- return faux.graph_get(nd=faux.active_gph(), mode="dot", detailed=detailed)
160
-
161
- def faux_master(self):
162
- faux = JsOrc.super_master()
163
- faux._h.mem["global"] = deepcopy(self._h.mem["global"])
164
- return faux
165
-
166
- def check_for_file(self, file):
167
- if not os.path.isfile(file):
168
- ret = "File does not exsist!"
169
- return ret, ret
170
- filename = os.path.basename(file)
171
- dir = os.path.dirname(os.path.realpath(file))
172
- return filename, dir