jaclang 0.3.1__py3-none-any.whl → 0.3.3__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 jaclang might be problematic. Click here for more details.

jaclang/cli/__init__.py CHANGED
@@ -1,5 +1,6 @@
1
1
  """CLI for jaclang."""
2
- from jaclang import jac_import as jac_import
2
+ from jaclang import jac_import
3
+
3
4
 
4
5
  cli = jac_import("cli")
5
6
  cmds = jac_import("cmds")
jaclang/core/__init__.py CHANGED
@@ -1,8 +1,8 @@
1
1
  """Core primitives for Jaseci."""
2
2
  from jaclang import jac_import
3
3
 
4
- prim = jac_import("corelib")
5
- if not prim:
6
- raise ImportError("Could not import primitives, internal compile error")
4
+ corelib = jac_import("corelib")
5
+ if not corelib:
6
+ raise ImportError("Could not import primitives, internal jaseci error")
7
7
 
8
- JacPlugin = prim.JacPlugin
8
+ JacPlugin = corelib.JacPlugin
@@ -1,15 +1,11 @@
1
1
  """Jac's Key Elemental Abstractions"""
2
2
  from __future__ import annotations
3
3
  from enum import Enum as __jac_Enum__, auto as __jac_auto__
4
- from jaclang import jac_import as __jac_import__
5
4
  from jaclang.jac.plugin.feature import JacFeature as _JacFeature
6
5
  from datetime import datetime
7
6
  from uuid import UUID, uuid4
8
7
  from jaclang.jac.constant import EdgeDir
9
8
  from jaclang.jac.plugin import Architype, AbsRootHook, hookimpl
10
- __jac_import__(target='corelib_impl', base_path=__file__)
11
- from corelib_impl import *
12
- import corelib_impl
13
9
 
14
10
  class AccessMode(__jac_Enum__):
15
11
  READ_ONLY = __jac_auto__()
@@ -74,6 +70,7 @@ exec_ctx = ExecutionContext()
74
70
 
75
71
  @_JacFeature.make_architype('obj')
76
72
  class ElementInterface:
73
+ ob: object
77
74
  (jid): UUID = uuid4()
78
75
  (timestamp): datetime = datetime.now()
79
76
  (persist): bool = False
@@ -167,7 +164,7 @@ class NodeInterface(DataSpatialInterface):
167
164
  return ret_nodes
168
165
 
169
166
  def __call__(self, walk: Walker) -> None:
170
- if not isinstance(walk, Walker):
167
+ if not isinstance(walk._jac_, WalkerInterface):
171
168
  raise TypeError('Argument must be a Walker instance')
172
169
  walk(self)
173
170
 
@@ -227,63 +224,282 @@ class WalkerInterface(DataSpatialInterface):
227
224
  self.disengaged = True
228
225
 
229
226
  def __call__(self, nd: Node) -> None:
230
- self._jac_.path = []
231
- self._jac_.next = [nd]
227
+ self.path = []
228
+ self.next = [nd]
232
229
  walker_type = self.__class__.__name__
233
- while len(self._jac_.next):
234
- nd = self._jac_.next.pop(0)
230
+ while len(self.next):
231
+ nd = self.next.pop(0)
235
232
  node_type = nd.__class__.__name__
236
- for i in nd._jac_ds_.ds_entry_funcs:
233
+ for i in nd.ds_entry_funcs:
237
234
  if i['func'].__qualname__.split('.')[0] == node_type and type(self) in i['types']:
238
235
  i['func'](nd, self)
239
- if self._jac_.disengaged:
236
+ if self.disengaged:
240
237
  return
241
- for i in self._jac_ds_.ds_entry_funcs:
238
+ for i in self.ds_entry_funcs:
242
239
  if i['func'].__qualname__.split('.')[0] == walker_type and (type(nd) in i['types'] or nd in i['types']):
243
240
  i['func'](self, nd)
244
- if self._jac_.disengaged:
241
+ if self.disengaged:
245
242
  return
246
- for i in self._jac_ds_.ds_exit_funcs:
243
+ for i in self.ds_exit_funcs:
247
244
  if i['func'].__qualname__.split('.')[0] == walker_type and (type(nd) in i['types'] or nd in i['types']):
248
245
  i['func'](self, nd)
249
- if self._jac_.disengaged:
246
+ if self.disengaged:
250
247
  return
251
- for i in nd._jac_ds_.ds_exit_funcs:
248
+ for i in nd.ds_exit_funcs:
252
249
  if i['func'].__qualname__.split('.')[0] == node_type and type(self) in i['types']:
253
250
  i['func'](nd, self)
254
- if self._jac_.disengaged:
251
+ if self.disengaged:
255
252
  return
256
- self._jac_.path.append(nd)
257
- self._jac_.ignores = []
253
+ self.path.append(nd)
254
+ self.ignores = []
258
255
 
259
256
  @_JacFeature.make_architype('obj')
260
257
  class Root(AbsRootHook):
261
- _jac_: NodeInterface
262
258
  RootType: type
259
+ (_jac_): NodeInterface | None = None
260
+
261
+ def __post_init__(self) -> None:
262
+ self._jac_ = NodeInterface(self)
263
263
 
264
264
  @_JacFeature.make_architype('obj')
265
265
  class Master:
266
- (_jac_): ElementInterface = ElementInterface()
267
- (root_node): Root = Root(NodeInterface(), Root)
266
+ (_jac_): ElementInterface | None = None
267
+ (root_node): Root = Root(Root)
268
+
269
+ def __post_init__(self) -> None:
270
+ self._jac_ = ElementInterface(self)
268
271
 
269
272
  @_JacFeature.make_architype('obj')
270
273
  class JacPlugin:
271
274
 
272
275
  @staticmethod
276
+ @hookimpl
273
277
  def bind_architype(arch: AT, arch_type: str) -> bool:
274
278
  match arch_type:
275
279
  case 'obj':
276
- arch._jac_ = ObjectInterface()
280
+ arch._jac_ = ObjectInterface(arch)
277
281
  case 'node':
278
- arch._jac_ = NodeInterface()
282
+ arch._jac_ = NodeInterface(arch)
279
283
  case 'edge':
280
- arch._jac_ = EdgeInterface()
284
+ arch._jac_ = EdgeInterface(arch)
281
285
  case 'walker':
282
- arch._jac_ = WalkerInterface()
286
+ arch._jac_ = WalkerInterface(arch)
283
287
  case _:
284
288
  raise TypeError('Invalid archetype type')
285
289
  return True
286
290
 
287
291
  @staticmethod
292
+ @hookimpl
288
293
  def get_root() -> Architype:
289
- return exec_ctx.get_root()
294
+ return exec_ctx.get_root()
295
+
296
+ def o_Memory_c_get_obj(self, caller_id: UUID, item_id: UUID, override: bool=False) -> Element:
297
+ ret = self.index.get(item_id)
298
+ if override or ret.__is_readable(ret is not None and caller_id):
299
+ return ret
300
+
301
+ def o_Memory_c_has_obj(self, item_id: UUID) -> bool:
302
+ return item_id in self.index
303
+
304
+ def o_Memory_c_save_obj(self, caller_id: UUID, item: Element) -> None:
305
+ if item.is_writable(caller_id):
306
+ self.index[item.id] = item
307
+ if item._persist:
308
+ self.save_obj_list.add(item)
309
+ self.mem[item.id] = item
310
+ if item._persist:
311
+ self.save_obj_list.add(item)
312
+
313
+ def o_Memory_c_del_obj(self, caller_id: UUID, item: Element) -> None:
314
+ if item.is_writable(caller_id):
315
+ self.index.pop(item.id)
316
+ if item._persist:
317
+ self.save_obj_list.remove(item)
318
+
319
+ def o_Memory_c_get_object_distribution(self) -> dict:
320
+ dist = {}
321
+ for i in self.index.keys():
322
+ t = type(self.index[i])
323
+ if t in dist:
324
+ dist[t] += 1
325
+ else:
326
+ dist[t] = 1
327
+ return dist
328
+
329
+ def o_Memory_c_get_mem_size(self) -> float:
330
+ return sys.getsizeof(self.index) / 1024.0
331
+
332
+ def o_ExecutionContext_c_get_root(self) -> None:
333
+ if type(self.master) == UUID:
334
+ self.master = Master()
335
+ return self.master.root_node
336
+
337
+ def o_ExecutionContext_c_reset(self) -> None:
338
+ self.__init__()
339
+
340
+ class e_AccessMode(__jac_Enum__):
341
+ READ_ONLY = __jac_auto__()
342
+ READ_WRITE = __jac_auto__()
343
+ PRIVATE = __jac_auto__()
344
+
345
+ def o_ElementInterface_c_make_public_ro(self) -> None:
346
+ self.__jinfo.access_mode = AccessMode.READ_ONLY
347
+
348
+ def o_ElementInterface_c_make_public_rw(self) -> None:
349
+ self.__jinfo.access_mode = AccessMode.READ_WRITE
350
+
351
+ def o_ElementInterface_c_make_private(self) -> None:
352
+ self.__jinfo.access_mode = AccessMode.PRIVATE
353
+
354
+ def o_ElementInterface_c_is_public_ro(self) -> bool:
355
+ return self.__jinfo.access_mode == AccessMode.READ_ONLY
356
+
357
+ def o_ElementInterface_c_is_public_rw(self) -> bool:
358
+ return self.__jinfo.access_mode == AccessMode.READ_WRITE
359
+
360
+ def o_ElementInterface_c_is_private(self) -> bool:
361
+ return self.__jinfo.access_mode == AccessMode.PRIVATE
362
+
363
+ def o_ElementInterface_c_is_readable(self, caller_id: UUID) -> bool:
364
+ return caller_id == self.owner_id or (self.is_public_read() or (caller_id in self.ro_access or caller_id in self.rw_access))
365
+
366
+ def o_ElementInterface_c_is_writable(self, caller_id: UUID) -> bool:
367
+ return caller_id == self.owner_id or (self.is_public_write() or caller_id in self.rw_access)
368
+
369
+ def o_ElementInterface_c_give_access(self, caller_id: UUID, read_write: bool=False) -> None:
370
+ if read_write:
371
+ self.rw_access.add(caller_id)
372
+ else:
373
+ add.ro_access.self(caller_id)
374
+
375
+ def o_ElementInterface_c_revoke_access(self, caller_id: UUID) -> None:
376
+ self.ro_access.discard(caller_id)
377
+ self.rw_access.discard(caller_id)
378
+
379
+ def o_DataSpatialInterface_c_on_entry(cls: type, triggers: list) -> None:
380
+
381
+ def decorator(func: callable) -> callable:
382
+ cls.ds_entry_funcs.append({'types': triggers, 'func': func})
383
+
384
+ def wrapper(*args: list, **kwargs: dict) -> callable:
385
+ return func(*args, **kwargs)
386
+ return wrapper
387
+ return decorator
388
+
389
+ def o_DataSpatialInterface_c_on_exit(cls: type, triggers: list) -> None:
390
+
391
+ def decorator(func: callable) -> callable:
392
+ cls.ds_exit_funcs.append({'types': triggers, 'func': func})
393
+
394
+ def wrapper(*args: list, **kwargs: dict) -> callable:
395
+ return func(*args, **kwargs)
396
+ return wrapper
397
+ return decorator
398
+
399
+ def o_NodeInterface_c_connect_node(self, nd: Node, edg: Edge) -> Node:
400
+ edg.attach(self.py_obj, nd)
401
+ return self
402
+
403
+ def o_NodeInterface_c_edges_to_nodes(self, dir: EdgeDir) -> list[Node]:
404
+ ret_nodes = []
405
+ if dir in [EdgeDir.OUT, EdgeDir.ANY]:
406
+ for i in self.edges[EdgeDir.OUT]:
407
+ ret_nodes.append(i.target)
408
+ elif dir in [EdgeDir.IN, EdgeDir.ANY]:
409
+ for i in self.edges[EdgeDir.IN]:
410
+ ret_nodes.append(i.source)
411
+ return ret_nodes
412
+
413
+ def o_EdgeInterface_c_apply_dir(self, dir: EdgeDir) -> Edge:
414
+ self.dir = dir
415
+ return self
416
+
417
+ def o_EdgeInterface_c_attach(self, src: Node, trg: Node) -> Edge:
418
+ if self.dir == EdgeDir.IN:
419
+ self.source = trg
420
+ self.target = src
421
+ src._jac_.edges[EdgeDir.IN].append(self)
422
+ trg._jac_.edges[EdgeDir.OUT].append(self)
423
+ else:
424
+ self.source = src
425
+ self.target = trg
426
+ src._jac_.edges[EdgeDir.OUT].append(self)
427
+ trg._jac_.edges[EdgeDir.IN].append(self)
428
+ return self
429
+
430
+ def o_WalkerInterface_c_visit_node(self, nds: list[Node] | (list[Edge] | (Node | Edge))) -> None:
431
+ if isinstance(nds, list):
432
+ for i in nds:
433
+ if i not in self.ignores:
434
+ self.next.append(i)
435
+ elif nds not in self.ignores:
436
+ self.next.append(nds)
437
+ return len(nds) if isinstance(nds, list) else 1
438
+
439
+ def o_WalkerInterface_c_ignore_node(self, nds: list[Node] | (list[Edge] | (Node | Edge))) -> None:
440
+ if isinstance(nds, list):
441
+ for i in nds:
442
+ self.ignores.append(i)
443
+ else:
444
+ self.ignores.append(nds)
445
+
446
+ def o_WalkerInterface_c_disengage_now(self) -> None:
447
+ self.next = []
448
+ self.disengaged = True
449
+
450
+ def o_NodeInterface_c___call__(self, walk: object) -> None:
451
+ if not isinstance(walk._jac_, WalkerInterface):
452
+ raise TypeError('Argument must be a Walker instance')
453
+ walk(self)
454
+
455
+ def o_EdgeInterface_c___call__(self, walk: Walker) -> None:
456
+ if not isinstance(walk, Walker):
457
+ raise TypeError('Argument must be a Walker instance')
458
+ walk(self._jac_.target)
459
+
460
+ def o_WalkerInterface_c___call__(self, nd: Node) -> None:
461
+ self.path = []
462
+ self.next = [nd]
463
+ walker_type = self.__class__.__name__
464
+ while len(self.next):
465
+ nd = self.next.pop(0)
466
+ node_type = nd.__class__.__name__
467
+ for i in nd.ds_entry_funcs:
468
+ if i['func'].__qualname__.split('.')[0] == node_type and type(self) in i['types']:
469
+ i['func'](nd, self)
470
+ if self.disengaged:
471
+ return
472
+ for i in self.ds_entry_funcs:
473
+ if i['func'].__qualname__.split('.')[0] == walker_type and (type(nd) in i['types'] or nd in i['types']):
474
+ i['func'](self, nd)
475
+ if self.disengaged:
476
+ return
477
+ for i in self.ds_exit_funcs:
478
+ if i['func'].__qualname__.split('.')[0] == walker_type and (type(nd) in i['types'] or nd in i['types']):
479
+ i['func'](self, nd)
480
+ if self.disengaged:
481
+ return
482
+ for i in nd.ds_exit_funcs:
483
+ if i['func'].__qualname__.split('.')[0] == node_type and type(self) in i['types']:
484
+ i['func'](nd, self)
485
+ if self.disengaged:
486
+ return
487
+ self.path.append(nd)
488
+ self.ignores = []
489
+
490
+ def o_JacPlugin_c_bind_architype(arch: AT, arch_type: str) -> bool:
491
+ match arch_type:
492
+ case 'obj':
493
+ arch._jac_ = ObjectInterface(arch)
494
+ case 'node':
495
+ arch._jac_ = NodeInterface(arch)
496
+ case 'edge':
497
+ arch._jac_ = EdgeInterface(arch)
498
+ case 'walker':
499
+ arch._jac_ = WalkerInterface(arch)
500
+ case _:
501
+ raise TypeError('Invalid archetype type')
502
+ return True
503
+
504
+ def o_JacPlugin_c_get_root() -> None:
505
+ return exec_ctx.get_root()