Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4288413
[PERSISTENCE-PR-SERIES]: Initial Commit
amadolid Aug 6, 2024
dbd0878
[PERSISTENCE-PR-SERIES]: Architype Refactor
amadolid Aug 6, 2024
7cd6c67
[PERSISTENCE-PR-SERIES]: Rename _jac_ and target_obj
amadolid Aug 6, 2024
99c1701
[PERSISTENCE-PR-SERIES]: Context Refactor
amadolid Aug 6, 2024
8b70518
[PERSISTENCE-PR-SERIES]: Memory Refactor
amadolid Aug 6, 2024
562cf6d
[PERSISTENCE-PR-SERIES]: Plugin Refactor
amadolid Aug 6, 2024
a05f47e
[PERSISTENCE-PR-SERIES]: Align cli, constructs and jac_streamlit
amadolid Aug 6, 2024
50bcb3c
[PERSISTENCE-PR-SERIES]: Unit Tests
amadolid Aug 6, 2024
9ff2555
[PERSISTENCE-PR-SERIES]: Auto await if necessary
amadolid Aug 6, 2024
79c1b6f
[UPDATES]: Address PR Comments
amadolid Aug 7, 2024
d1d810f
[ACCESS-VALIDATION]: Improved hierarchy of access level
amadolid Aug 7, 2024
f6ab241
[UNIT-TEST]: Access Validation
amadolid Aug 7, 2024
c540479
[ALIGNMENT]: Sync approach to jaclang-jaseci (Context and Memory)
amadolid Aug 8, 2024
b014909
[BUGFIX]: Missing EdgeAnchor.is_undirected & Rename NO_ACESSS
amadolid Aug 9, 2024
4760372
[AUTOMATION]: Delete nodes that doesn't have any connection
amadolid Aug 12, 2024
db724ac
[DISCONNECT]: Use EdgeDir class instead of string
amadolid Aug 12, 2024
2d68e4b
[REFACTOR]: Remove orjson and dacite
amadolid Aug 12, 2024
bdcc5f8
[REFACTOR]: Make Root and GenericEdge to be dataclass for consistency
amadolid Aug 12, 2024
03533ee
[REFACTOR]: Prioritize pluggy context
amadolid Aug 13, 2024
58ab554
[REFACTOR]: Remove ref_id prefixing
amadolid Aug 13, 2024
9fbeaa7
[MINOR]: Return current root instead of super_root on get_object root
amadolid Aug 14, 2024
2d7b101
[SERIALIZER]: Adjust pickling handler
amadolid Aug 14, 2024
03dbf72
[CLEANUP]: Migrate some tools to jaclang-jaseci
amadolid Aug 14, 2024
d75fc1d
[MINOR]: Use shallow cloning instead of copy/deepcopy
amadolid Aug 14, 2024
a72b6c4
[UNIT-TEST]: Use JacFeature instead of ExecutionContext directly
amadolid Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions examples/plugins/jaclang_walkerapi/jaclang_walkerapi/walkerapi.py

This file was deleted.

24 changes: 0 additions & 24 deletions examples/plugins/jaclang_walkerapi/setup.py

This file was deleted.

1 change: 1 addition & 0 deletions jaclang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
JacFeatureDefaults,
)
from jaclang.plugin.feature import JacFeature, pm # noqa: E402
from jaclang.runtimelib import architype # noqa

jac_import = JacFeature.jac_import

Expand Down
121 changes: 57 additions & 64 deletions jaclang/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import ast as ast3
import importlib
import inspect
import marshal
import os
import pickle
import shutil
import types
from typing import Optional
from uuid import UUID

import jaclang.compiler.absyntree as ast
from jaclang import jac_import
Expand All @@ -22,7 +20,7 @@
from jaclang.plugin.builtin import dotgen
from jaclang.plugin.feature import JacCmd as Cmd
from jaclang.plugin.feature import JacFeature as Jac
from jaclang.runtimelib.constructs import Architype
from jaclang.runtimelib.constructs import Anchor, NodeAnchor, WalkerArchitype
from jaclang.runtimelib.machine import JacProgram
from jaclang.utils.helpers import debugger as db
from jaclang.utils.lang_tools import AstTool
Expand Down Expand Up @@ -68,12 +66,7 @@ def format_file(filename: str) -> None:

@cmd_registry.register
def run(
filename: str,
session: str = "",
main: bool = True,
cache: bool = True,
walker: str = "",
node: str = "",
filename: str, session: str = "", main: bool = True, cache: bool = True
) -> None:
"""Run the specified .jac file."""
# if no session specified, check if it was defined when starting the command shell
Expand All @@ -90,78 +83,49 @@ def run(
base, mod = os.path.split(filename)
base = base if base else "./"
mod = mod[:-4]
Jac.context().init_memory(base_path=base, session=session)

ctx = Jac.new_context(base_path=base, session=session)

if filename.endswith(".jac"):
ret_module = jac_import(
jac_import(
target=mod,
base_path=base,
cachable=cache,
override_name="__main__" if main else None,
)
if ret_module is None:
loaded_mod = None
else:
(loaded_mod,) = ret_module
elif filename.endswith(".jir"):
with open(filename, "rb") as f:
ir = pickle.load(f)
jac_program = JacProgram(mod_bundle=ir, bytecode=None)
Jac.context().jac_machine.attach_program(jac_program)
ret_module = jac_import(
ctx.jac_machine.attach_program(JacProgram(mod_bundle=ir, bytecode=None))
jac_import(
target=mod,
base_path=base,
cachable=cache,
override_name="__main__" if main else None,
)
if ret_module is None:
loaded_mod = None
else:
(loaded_mod,) = ret_module
else:
print("Not a .jac file.")
return

if not node or node == "root":
entrypoint: Architype = Jac.get_root()
else:
obj = Jac.context().get_obj(UUID(node))
if obj is None:
print(f"Entrypoint {node} not found.")
return
entrypoint = obj

# TODO: handle no override name
if walker:
walker_module = dict(inspect.getmembers(loaded_mod)).get(walker)
if walker_module:
Jac.spawn_call(entrypoint, walker_module())
else:
print(f"Walker {walker} not found.")

Jac.reset_context()
ctx.close()


@cmd_registry.register
def get_object(id: str, session: str = "") -> dict:
def get_object(id: str, session: str = "") -> dict[str, object]:
"""Get the object with the specified id."""
if session == "":
session = cmd_registry.args.session if "session" in cmd_registry.args else ""

Jac.context().init_memory(session=session)
ctx = Jac.new_context(session=session)

response = {}
if id == "root":
id_uuid = UUID(int=0)
else:
id_uuid = UUID(id)
response = ctx.root.__getstate__()
elif (anchor := Anchor.ref(id)) and (architype := anchor.sync()):
response = architype.__jac__.__getstate__()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have this logic as a plugin method? like, how it is currently implemented in main.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, not sure which part you're pointing.

Will change the the == "root" to return current root instead of super root

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the logic of getting the full object given an object id. I feel like this pattern gets used in a lot of places and it is something that a plugin might want to override.

So basically line 122 to 125.


obj = Jac.context().get_obj(id_uuid)
if obj is None:
print(f"Object with id {id} not found.")
Jac.reset_context()
return {}
else:
Jac.reset_context()
return obj.__getstate__()
ctx.close()
return response


@cmd_registry.register
Expand Down Expand Up @@ -211,13 +175,27 @@ def lsp() -> None:


@cmd_registry.register
def enter(filename: str, entrypoint: str, args: list) -> None:
"""Run the specified entrypoint function in the given .jac file.
def enter(
filename: str,
session: str = "",
entrypoint: str = "",
root: str = "",
node: str = "",
args: Optional[list] = None,
) -> None:
"""
Run the specified entrypoint function in the given .jac file.

:param filename: The path to the .jac file.
:param entrypoint: The name of the entrypoint function.
:param root: root executor.
:param node: starting node if entrypoint is walker.
:param args: Arguments to pass to the entrypoint function.
"""
ctx = Jac.new_context(
session=session, root=NodeAnchor.ref(root), entry=NodeAnchor.ref(node)
)

if filename.endswith(".jac"):
base, mod_name = os.path.split(filename)
base = base if base else "./"
Expand All @@ -227,10 +205,19 @@ def enter(filename: str, entrypoint: str, args: list) -> None:
print("Errors occurred while importing the module.")
return
else:
getattr(mod, entrypoint)(*args)
result = getattr(mod, entrypoint)(*args or [])
if (
isinstance(result, WalkerArchitype)
and ctx.validate_access()
and (architype := ctx.entry.architype)
):
Jac.spawn_call(architype, result)

else:
print("Not a .jac file.")

ctx.close()


@cmd_registry.register
def test(
Expand All @@ -252,6 +239,8 @@ def test(

jac test => jac test -d .
"""
ctx = Jac.new_context()

failcount = Jac.run_test(
filepath=filepath,
filter=filter,
Expand All @@ -260,6 +249,9 @@ def test(
directory=directory,
verbose=verbose,
)

ctx.close()

if failcount:
raise SystemExit(f"Tests failed: {failcount}")

Expand Down Expand Up @@ -361,7 +353,9 @@ def dot(
base, mod = os.path.split(filename)
base = base if base else "./"
mod = mod[:-4]
Jac.context().init_memory(base_path=base, session=session)

ctx = Jac.new_context(base_path=base, session=session)

if filename.endswith(".jac"):
jac_import(
target=mod,
Expand All @@ -380,21 +374,20 @@ def dot(
edge_limit=edge_limit,
node_limit=node_limit,
)

file_name = saveto if saveto else f"{mod}.dot"
with open(file_name, "w") as file:
file.write(graph)
print(f">>> Graph content saved to {os.path.join(os.getcwd(), file_name)}")
except Exception as e:
print(f"Error while generating graph: {e}")
import traceback

traceback.print_exc()
Jac.reset_context()
return
file_name = saveto if saveto else f"{mod}.dot"
with open(file_name, "w") as file:
file.write(graph)
print(f">>> Graph content saved to {os.path.join(os.getcwd(), file_name)}")
else:
print("Not a .jac file.")

Jac.reset_context()
ctx.close()


@cmd_registry.register
Expand Down
21 changes: 13 additions & 8 deletions jaclang/compiler/constant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""Constants across the project."""

from enum import Enum, IntEnum, IntFlag, StrEnum
from typing import ParamSpec, TypeVar


T = TypeVar("T")
P = ParamSpec("P")


class SymbolType(Enum):
Expand Down Expand Up @@ -94,18 +99,18 @@ class Constants(StrEnum):
HERE = "_jac_here_"
JAC_FEATURE = "_Jac"
ROOT = f"{JAC_FEATURE}.get_root()"
EDGES_TO_NODE = "_jac_.edges_to_nodes"
EDGE_REF = "_jac_.edge_ref"
CONNECT_NODE = "_jac_.connect_node"
DISCONNECT_NODE = "_jac_.disconnect_node"
WALKER_VISIT = "_jac_.visit_node"
WALKER_IGNORE = "_jac_.ignore_node"
DISENGAGE = "_jac_.disengage_now"
EDGES_TO_NODE = "__jac__.edges_to_nodes"
EDGE_REF = "__jac__.edge_ref"
CONNECT_NODE = "__jac__.connect_node"
DISCONNECT_NODE = "__jac__.disconnect_node"
WALKER_VISIT = "__jac__.visit_node"
WALKER_IGNORE = "__jac__.ignore_node"
DISENGAGE = "__jac__.disengage_now"
OBJECT_CLASS = "_jac_Object_"
NODE_CLASS = "_jac_Node_"
EDGE_CLASS = "_jac_Edge_"
WALKER_CLASS = "_jac_Walker_"
WITH_DIR = "_jac_.apply_dir"
WITH_DIR = "__jac__.apply_dir"
EDGE_DIR = "_jac_Edge_Dir"
ON_ENTRY = "_jac_ds_.on_entry"
ON_EXIT = "_jac_ds_.on_exit"
Expand Down
Loading