jaseci 1.4.0.9__py3-none-any.whl → 1.4.0.11__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 (87) hide show
  1. jaseci/VERSION +1 -1
  2. jaseci/__init__.py +3 -0
  3. jaseci/actions/standard/elastic.py +3 -2
  4. jaseci/actions/standard/mail.py +3 -2
  5. jaseci/actions/standard/std.py +3 -2
  6. jaseci/actions/standard/stripe.py +3 -2
  7. jaseci/actions/standard/task.py +3 -5
  8. jaseci/actions/standard/tests/test_mail_lib.py +8 -7
  9. jaseci/actions/tests/test_std.py +4 -5
  10. jaseci/actor/walker.py +6 -3
  11. jaseci/api/config_api.py +3 -2
  12. jaseci/api/jac_api.py +2 -2
  13. jaseci/api/jsorc_api.py +60 -121
  14. jaseci/api/prometheus_api.py +14 -20
  15. jaseci/api/queue_api.py +9 -5
  16. jaseci/api/tests/test_global_api.py +3 -3
  17. jaseci/api/tests/test_logger_api.py +3 -3
  18. jaseci/api/user_api.py +3 -3
  19. jaseci/api/webhook_api.py +6 -4
  20. jaseci/attr/action.py +10 -4
  21. jaseci/element/master.py +2 -0
  22. jaseci/element/super_master.py +2 -0
  23. jaseci/hook/memory.py +3 -1
  24. jaseci/hook/redis.py +5 -4
  25. jaseci/jac/interpreter/interp.py +16 -4
  26. jaseci/jac/tests/test_book.py +2 -2
  27. jaseci/jsctl/jsctl.py +48 -15
  28. jaseci/jsctl/tests/test_jsctl.py +5 -0
  29. jaseci/jsorc.py +733 -0
  30. jaseci/jsorc_settings.py +184 -0
  31. jaseci/manifests/database.yaml +107 -0
  32. jaseci/manifests/elastic.yaml +5923 -0
  33. jaseci/manifests/prometheus.yaml +1273 -0
  34. jaseci/{svc/jsorc-backup/jaseci-redis.yaml → manifests/redis.yaml} +20 -0
  35. jaseci/svc/__init__.py +0 -25
  36. jaseci/svc/{elastic/elastic.py → elastic_svc.py} +5 -16
  37. jaseci/svc/kube_svc.py +240 -0
  38. jaseci/svc/{mail/mail.py → mail_svc.py} +14 -17
  39. jaseci/svc/{prometheus/prometheus.py → prome_svc.py} +5 -16
  40. jaseci/svc/{redis/redis.py → redis_svc.py} +14 -26
  41. jaseci/svc/{stripe/stripe.py → stripe_svc.py} +4 -7
  42. jaseci/svc/{task/task.py → task_svc.py} +27 -24
  43. jaseci/svc/{task/common.py → tasks.py} +287 -293
  44. jaseci/tests/jac_test_progs.py +21 -0
  45. jaseci/tests/test_core.py +14 -15
  46. jaseci/tests/test_jac.py +59 -60
  47. jaseci/tests/test_node.py +6 -13
  48. jaseci/tests/test_progs.py +74 -52
  49. jaseci/tests/test_stripe.py +6 -10
  50. jaseci/utils/actions/actions_manager.py +254 -0
  51. jaseci/{svc/actions_optimizer → utils/actions}/actions_optimizer.py +9 -19
  52. jaseci/utils/json_handler.py +2 -3
  53. jaseci/utils/test_core.py +4 -5
  54. jaseci/utils/utils.py +12 -0
  55. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/METADATA +2 -1
  56. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/RECORD +63 -80
  57. jaseci/svc/common.py +0 -763
  58. jaseci/svc/config.py +0 -9
  59. jaseci/svc/elastic/__init__.py +0 -3
  60. jaseci/svc/elastic/config.py +0 -8
  61. jaseci/svc/elastic/manifest.py +0 -1
  62. jaseci/svc/jsorc-backup/jsorc.py +0 -182
  63. jaseci/svc/jsorc-backup/promon/__init__.py +0 -0
  64. jaseci/svc/jsorc-backup/promon/promon.py +0 -202
  65. jaseci/svc/mail/__init__.py +0 -4
  66. jaseci/svc/mail/config.py +0 -25
  67. jaseci/svc/meta.py +0 -164
  68. jaseci/svc/postgres/__init__.py +0 -0
  69. jaseci/svc/postgres/manifest.py +0 -106
  70. jaseci/svc/prometheus/__init__.py +0 -5
  71. jaseci/svc/prometheus/config.py +0 -11
  72. jaseci/svc/prometheus/manifest.py +0 -1102
  73. jaseci/svc/redis/__init__.py +0 -5
  74. jaseci/svc/redis/config.py +0 -10
  75. jaseci/svc/redis/manifest.py +0 -65
  76. jaseci/svc/state.py +0 -17
  77. jaseci/svc/stripe/__init__.py +0 -3
  78. jaseci/svc/stripe/config.py +0 -7
  79. jaseci/svc/task/__init__.py +0 -5
  80. jaseci/svc/task/config.py +0 -17
  81. /jaseci/{svc/actions_optimizer → manifests}/__init__.py +0 -0
  82. /jaseci/{svc/jsorc-backup → utils/actions}/__init__.py +0 -0
  83. /jaseci/{svc/actions_optimizer → utils/actions}/actions_state.py +0 -0
  84. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/LICENSE +0 -0
  85. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/WHEEL +0 -0
  86. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/entry_points.txt +0 -0
  87. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/top_level.txt +0 -0
jaseci/api/queue_api.py CHANGED
@@ -2,6 +2,8 @@
2
2
  Queue api functions as a mixin
3
3
  """
4
4
  from jaseci.api.interface import Interface
5
+ from jaseci import JsOrc
6
+ from jaseci.svc.task_svc import TaskService
5
7
 
6
8
 
7
9
  class QueueApi:
@@ -16,23 +18,25 @@ class QueueApi:
16
18
  """
17
19
  Monitor Queues
18
20
  """
19
- if not self._h.task.is_running():
21
+ task = JsOrc.svc("task", TaskService)
22
+ if not task.is_running():
20
23
  return "Task hook is not yet initialized!"
21
24
 
22
25
  if not task_id:
23
- return self._h.task.inspect_tasks()
26
+ return task.inspect_tasks()
24
27
  else:
25
- return self._h.task.get_by_task_id(task_id)
28
+ return task.get_by_task_id(task_id)
26
29
 
27
30
  @Interface.private_api(allowed_methods=["get"])
28
31
  def walker_queue_wait(self, task_id: str, timeout: int = 30):
29
32
  """
30
33
  Wait Queues
31
34
  """
32
- if not self._h.task.is_running():
35
+ task = JsOrc.svc("task", TaskService)
36
+ if not task.is_running():
33
37
  return "Task hook is not yet initialized!"
34
38
 
35
39
  if not task_id:
36
40
  return "Task id is required!"
37
41
  else:
38
- return self._h.task.get_by_task_id(task_id, True, timeout)
42
+ return task.get_by_task_id(task_id, True, timeout)
@@ -1,4 +1,5 @@
1
1
  from jaseci.utils.test_core import CoreTest
2
+ from jaseci import JsOrc
2
3
  import jaseci.tests.jac_test_code as jtc
3
4
 
4
5
 
@@ -10,11 +11,10 @@ class GlobalApiTest(CoreTest):
10
11
  def setUp(self):
11
12
  super().setUp()
12
13
 
13
- self.smast2 = self.meta.build_super_master(h=self.smast._h)
14
+ self.smast2 = JsOrc.super_master(h=self.smast._h)
14
15
  self.smast.sentinel_register(name="test", code=jtc.basic)
15
16
 
16
- self.mast = self.meta.build_master()
17
- self.mast2 = self.meta.build_super_master(h=self.mast._h)
17
+ self.mast2 = JsOrc.master(h=self.mast._h)
18
18
  self.mast.sentinel_register(name="test", code=jtc.basic)
19
19
 
20
20
  def tearDown(self):
@@ -31,9 +31,9 @@ class LoggerApiTest(CoreTest):
31
31
  self.logger_off()
32
32
 
33
33
  ret = self.call(self.smast, ["logger_get", {}])
34
-
35
- self.assertEqual(len(ret), 1)
36
- self.assertTrue(ret[0]["log"].endswith("Hello world!"))
34
+ self.assertGreaterEqual(len(ret), 1)
35
+ self.assertLessEqual(len(ret), 5)
36
+ self.assertTrue(ret[-1]["log"].endswith("Hello world!"))
37
37
 
38
38
  def test_limited_sliding_buffer(self):
39
39
  buffer = LimitedSlidingBuffer(max_size=25)
jaseci/api/user_api.py CHANGED
@@ -2,7 +2,7 @@
2
2
  User API
3
3
  """
4
4
  from jaseci.api.interface import Interface
5
- from jaseci.svc.meta import MetaService
5
+ from jaseci import JsOrc
6
6
 
7
7
 
8
8
  class UserApi:
@@ -107,14 +107,14 @@ class UserApi:
107
107
  Abstraction for user creation for elegant overriding
108
108
  """
109
109
 
110
- return MetaService().build_master(h=self._h, name=name)
110
+ return JsOrc.master(h=self._h, name=name)
111
111
 
112
112
  def superuser_creator(self, name, password: str = "", other_fields: dict = {}):
113
113
  """
114
114
  Abstraction for super user creation for elegant overriding
115
115
  """
116
116
 
117
- return MetaService().build_super_master(h=self._h, name=name)
117
+ return JsOrc.super_master(h=self._h, name=name)
118
118
 
119
119
  def user_global_init(
120
120
  self,
jaseci/api/webhook_api.py CHANGED
@@ -3,8 +3,10 @@ Webhook API
3
3
  """
4
4
  from jaseci.api.interface import Interface
5
5
  from fastapi import HTTPException
6
- from json import loads
7
- from jaseci.svc import MetaService
6
+ from jaseci import JsOrc
7
+ from jaseci.svc.stripe_svc import StripeService
8
+
9
+ import stripe as _stripe
8
10
 
9
11
 
10
12
  class WebhookApi:
@@ -18,8 +20,8 @@ class WebhookApi:
18
20
  req_body = _req_ctx["body"]
19
21
 
20
22
  if provider == "stripe":
21
- stripe_service = MetaService().get_service("stripe")
22
- stripe = stripe_service.poke()
23
+ stripe_service = JsOrc.svc("stripe", StripeService)
24
+ stripe = stripe_service.poke(_stripe)
23
25
 
24
26
  # to be updated
25
27
  stripe_service.get_event(_raw_req_ctx, _req_ctx["headers"])
jaseci/attr/action.py CHANGED
@@ -9,6 +9,9 @@ from jaseci.jac.jac_set import JacSet
9
9
  import inspect
10
10
  import time
11
11
 
12
+ from jaseci import JsOrc
13
+ from jaseci.utils.actions.actions_manager import ActionManager
14
+
12
15
  # ACTION_PACKAGE = 'jaseci.actions.'
13
16
 
14
17
 
@@ -55,7 +58,10 @@ class Action(Item):
55
58
  self.do_auto_conversions(args, param_list)
56
59
  args = args[0] + args[4]
57
60
  hook = scope.parent._h
58
- hook.meta.app.pre_action_call_hook() if hook.meta.run_svcs else None
61
+
62
+ action_manager = JsOrc.get("action_manager", ActionManager)
63
+ action_manager.pre_action_call_hook()
64
+
59
65
  ts = time.time()
60
66
  if "meta" in args:
61
67
  result = func(
@@ -85,7 +91,7 @@ class Action(Item):
85
91
  )
86
92
  raise
87
93
  t = time.time() - ts
88
- hook.meta.app.post_action_call_hook(
89
- self.value, t
90
- ) if hook.meta.run_svcs else None
94
+
95
+ action_manager.post_action_call_hook(self.value, t)
96
+
91
97
  return result
jaseci/element/master.py CHANGED
@@ -17,8 +17,10 @@ from jaseci.api.jac_api import JacApi
17
17
  from jaseci.api.user_api import UserApi
18
18
  from jaseci.api.queue_api import QueueApi
19
19
  from jaseci.api.webhook_api import WebhookApi
20
+ from jaseci import JsOrc
20
21
 
21
22
 
23
+ @JsOrc.context(name="master")
22
24
  class Master(
23
25
  Element,
24
26
  Interface,
@@ -11,8 +11,10 @@ from jaseci.api.global_api import GlobalApi
11
11
  from jaseci.api.super_api import SuperApi
12
12
  from jaseci.api.actions_api import ActionsApi
13
13
  from jaseci.api.prometheus_api import PrometheusApi
14
+ from jaseci import JsOrc
14
15
 
15
16
 
17
+ @JsOrc.context(name="super_master")
16
18
  class SuperMaster(
17
19
  Master,
18
20
  LoggerApi,
jaseci/hook/memory.py CHANGED
@@ -1,8 +1,10 @@
1
1
  from json import dumps, loads
2
2
  import sys
3
3
  from jaseci.utils.utils import find_class_and_import
4
+ from jaseci import JsOrc
4
5
 
5
6
 
7
+ @JsOrc.repository(name="hook")
6
8
  class MemoryHook:
7
9
  """
8
10
  Set of virtual functions to be used as hooks to allow access to
@@ -219,7 +221,7 @@ class MemoryHook:
219
221
  ###################################################
220
222
 
221
223
  def find_class_and_import(self, j_type, mod):
222
- cls = self.meta.get_context(j_type)
224
+ cls = JsOrc.ctx_cls(j_type)
223
225
 
224
226
  if not cls:
225
227
  cls = find_class_and_import(j_type, mod)
jaseci/hook/redis.py CHANGED
@@ -5,9 +5,10 @@ core engine.
5
5
  import json
6
6
 
7
7
  import jaseci as core_mod
8
- from jaseci.svc import ProxyService
9
8
  from jaseci.utils.json_handler import JaseciJsonDecoder
10
9
  from .memory import MemoryHook
10
+ from jaseci import JsOrc
11
+ from jaseci.svc.redis_svc import RedisService
11
12
 
12
13
 
13
14
  #################################################
@@ -15,10 +16,10 @@ from .memory import MemoryHook
15
16
  #################################################
16
17
 
17
18
 
19
+ @JsOrc.repository(name="hook", priority=1)
18
20
  class RedisHook(MemoryHook):
19
- def __init__(self):
20
- # proxy redis, to be overriden by build_apps
21
- self.redis = ProxyService()
21
+ def __init__(self, redis: RedisService = None):
22
+ self.redis = JsOrc.svc("redis", RedisService)
22
23
  self.red_touch_count = 0
23
24
 
24
25
  super().__init__()
@@ -4,6 +4,8 @@ Interpreter for jac code in AST form
4
4
  This interpreter should be inhereted from the class that manages state
5
5
  referenced through self.
6
6
  """
7
+ from jaseci import JsOrc
8
+ from jaseci.svc.task_svc import TaskService
7
9
  from jaseci.utils.utils import is_jsonable, parse_str_token, uuid_re
8
10
  from jaseci.element.element import Element
9
11
  from jaseci.graph.node import Node
@@ -20,6 +22,7 @@ from jaseci.jac.machine.jac_value import jac_elem_unwrap as jeu
20
22
  from jaseci.jac.machine.jac_value import jac_wrap_value as jwv
21
23
  from copy import copy, deepcopy
22
24
  from base64 import b64decode
25
+ from itertools import pairwise
23
26
 
24
27
  from jaseci.jac.jsci_vm.op_codes import JsCmp
25
28
 
@@ -794,12 +797,14 @@ class Interp(VirtualMachine):
794
797
  elif kid[0].name == "KW_SYNC":
795
798
  self.run_atom(kid[1])
796
799
  val = self.pop()
797
- task_func = self._h.task
798
- if not task_func.is_running():
799
- raise Exception("Task hook is not yet initialized!")
800
800
  self.push(
801
801
  JacValue(
802
- self, value=task_func.get_by_task_id(val.value["result"], True)
802
+ self,
803
+ value=(
804
+ JsOrc.svc("task")
805
+ .poke(TaskService)
806
+ .get_by_task_id(val.value["result"], True)
807
+ ),
803
808
  )
804
809
  )
805
810
  else:
@@ -1154,6 +1159,13 @@ class Interp(VirtualMachine):
1154
1159
  result = JacValue(
1155
1160
  self, value=atom_res.value.index(min(atom_res.value))
1156
1161
  )
1162
+ elif op == "pairwise":
1163
+ result = JacValue(
1164
+ self, value=[list(s) for s in pairwise(atom_res.value)]
1165
+ )
1166
+ elif op == "unique":
1167
+ result = JacValue(self, value=list(set(atom_res.value)))
1168
+
1157
1169
  elif len(kid) < 2 and op == "pop":
1158
1170
  result = JacValue(self, value=atom_res.value.pop())
1159
1171
  self.candidate_writethrough()
@@ -5,7 +5,7 @@ from unittest import TestCase
5
5
  import jaseci.jac.tests.book_code as jtc
6
6
  from jaseci.actor.sentinel import Sentinel
7
7
  from jaseci.graph.graph import Graph
8
- from jaseci.svc import MetaService
8
+ from jaseci import JsOrc
9
9
  from jaseci.utils.utils import TestCaseHelper
10
10
 
11
11
 
@@ -14,7 +14,7 @@ class JacBookTests(TestCaseHelper, TestCase):
14
14
 
15
15
  def setUp(self):
16
16
  super().setUp()
17
- self.sent = Sentinel(m_id=0, h=MetaService().build_hook())
17
+ self.sent = Sentinel(m_id=0, h=JsOrc.hook())
18
18
  self.gph = Graph(m_id=0, h=self.sent._h)
19
19
  self.old_stdout = sys.stdout
20
20
  self.new_stdout = io.StringIO()
jaseci/jsctl/jsctl.py CHANGED
@@ -6,17 +6,17 @@ import functools
6
6
  import json
7
7
  import os
8
8
  import pickle
9
-
9
+ import webbrowser
10
10
  import click
11
11
  import requests
12
12
  from click_shell import shell
13
13
  from click.testing import CliRunner
14
14
  from jaseci import __version__
15
15
  from jaseci.element.super_master import SuperMaster
16
- from jaseci.svc import MetaService
17
16
  from jaseci.utils.utils import copy_func
18
17
  from .book_tools import Book, modifiedBook
19
- from jaseci.utils.utils import logger, perf_test_start, perf_test_stop
18
+ from jaseci.utils.utils import logger, perf_test_start, perf_test_stop, find_first_api
19
+ from jaseci import JsOrc
20
20
 
21
21
  session = None
22
22
 
@@ -25,7 +25,7 @@ def reset_state():
25
25
  global session
26
26
  session = {
27
27
  "filename": "js.session",
28
- "user": [MetaService(run_svcs=False).build_super_master(name="admin")],
28
+ "user": [JsOrc.super_master(name="admin")],
29
29
  "mem-only": session["mem-only"] if session is not None else False,
30
30
  "connection": {"url": None, "token": None, "headers": None},
31
31
  }
@@ -83,17 +83,19 @@ def remote_api_call(payload, api_name):
83
83
  Constructs and issues call to remote server
84
84
  NOTE: Untested
85
85
  """
86
- for i in SuperMaster.all_apis(None):
87
- if api_name == "_".join(i["groups"]):
88
- if i in SuperMaster._private_api:
89
- path = "/js/" + api_name
90
- elif i in SuperMaster._admin_api:
91
- path = "/js_admin/" + api_name
92
- elif i in SuperMaster._public_api:
93
- path = "/js_public/" + api_name
94
- break
95
- ret = requests.post(
96
- session["connection"]["url"] + path,
86
+ path, api = find_first_api(
87
+ api_name,
88
+ js_public=SuperMaster._public_api,
89
+ js=SuperMaster._private_api,
90
+ js_admin=SuperMaster._admin_api,
91
+ )
92
+
93
+ method = requests.post
94
+ if api["allowed_methods"] != None and "post" not in api["allowed_methods"]:
95
+ method = requests.get
96
+
97
+ ret = method(
98
+ session["connection"]["url"] + f"/{path}/{api_name}",
97
99
  json=payload,
98
100
  headers=session["connection"]["headers"],
99
101
  )
@@ -270,6 +272,36 @@ def login(url, username, password):
270
272
  pickle.dump(session, f)
271
273
 
272
274
 
275
+ @click.command(help="Launch Jaseci Studio")
276
+ def studio():
277
+ token = session["connection"]["token"]
278
+
279
+ if not token:
280
+ click.echo(
281
+ click.style(
282
+ "It doesn't look like you're logged in to a Jaseci instance. Please log in to a Jaseci instance to use this command.\n",
283
+ fg="red",
284
+ )
285
+ )
286
+ else:
287
+ url = session["connection"]["url"] + "/studio/"
288
+
289
+ if token == "PUBLIC":
290
+ click.echo(
291
+ click.style(
292
+ "You are logged in as a public user. Please log in to a Jaseci instance to use this command.\n",
293
+ fg="red",
294
+ )
295
+ )
296
+
297
+ webbrowser.open(url)
298
+ else:
299
+ click.echo(click.style("Launching Jaseci Studio...", fg="green"))
300
+ click.echo(click.style("URL: ", fg="green", bold=True) + url)
301
+ click.echo(click.style(f"Token: {token}", fg="green"))
302
+ webbrowser.open(url + "?token=" + token)
303
+
304
+
273
305
  @click.command(help="Command for unauthenticated log into live Jaseci server")
274
306
  @click.argument("url", type=str, required=True)
275
307
  def publogin(url):
@@ -408,6 +440,7 @@ jsctl.add_command(ls)
408
440
  jsctl.add_command(clear)
409
441
  jsctl.add_command(reset)
410
442
  jsctl.add_command(script)
443
+ jsctl.add_command(studio)
411
444
  jsctl.add_command(booktool)
412
445
  cmd_tree_builder(extract_api_tree())
413
446
  cmd_tree_builder(extract_api_tree()["jac"], group_func=jac)
@@ -5,6 +5,9 @@ from click.testing import CliRunner
5
5
  import json
6
6
  import os
7
7
 
8
+ from jaseci import JsOrc
9
+ from jaseci.svc.redis_svc import RedisService
10
+
8
11
 
9
12
  class JsctlTest(TestCaseHelper, TestCase):
10
13
  """Unit tests for Jac language"""
@@ -15,6 +18,7 @@ class JsctlTest(TestCaseHelper, TestCase):
15
18
 
16
19
  def setUp(self):
17
20
  super().setUp()
21
+ JsOrc.svc("redis", RedisService).clear()
18
22
 
19
23
  def call(self, cmd: str):
20
24
  res = CliRunner(mix_stderr=False).invoke(jsctl.jsctl, ["-m"] + cmd.split())
@@ -154,6 +158,7 @@ class JsctlTest(TestCaseHelper, TestCase):
154
158
  r = self.call("config get APPLE -do_check False")
155
159
  self.assertEqual(r.strip(), "Grape2")
156
160
  r = self.call_cast("config list")
161
+
157
162
  self.assertEqual(len(r), 1)
158
163
 
159
164
  def test_jsctl_default_snt_setting(self):