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