Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
[MINOR]: Address PR Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amadolid committed Jul 18, 2024
1 parent bf54383 commit e988be6
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 1,579 deletions.
2 changes: 0 additions & 2 deletions jaclang/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,6 @@ def start_cli() -> None:
args_dict = vars(args)
args_dict.pop("command")
args_dict.pop("version", None)
if command.func.__name__ != "run":
args_dict.pop("session")
ret = command.call(**args_dict)
if ret:
print(ret)
Expand Down
21 changes: 11 additions & 10 deletions jaclang/core/architype.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

from jaclang.compiler.constant import EdgeDir
from jaclang.core.utils import collect_node_connections
from jaclang.vendor.orjson import dumps

from orjson import dumps

GENERIC_ID_REGEX = compile(
r"^(g|n|e|w):([^:]*):([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$",
Expand Down Expand Up @@ -196,7 +197,7 @@ def sync(self, node: Optional["NodeAnchor"] = None) -> Optional[Architype]:

from .context import ExecutionContext

jsrc = ExecutionContext.get().datasource
jsrc = ExecutionContext.get_or_create().datasource
anchor = jsrc.find_one(self.id)

if anchor and (node or self).has_read_access(anchor):
Expand All @@ -208,7 +209,7 @@ def allocate(self) -> None:
"""Allocate hashes and memory."""
from .context import ExecutionContext

jctx = ExecutionContext.get()
jctx = ExecutionContext.get_or_create()
self.root = jctx.root.id
jctx.datasource.set(self, True)

Expand All @@ -228,7 +229,7 @@ def access_level(self, to: Anchor) -> int:
"""Access validation."""
from .context import ExecutionContext

jctx = ExecutionContext.get()
jctx = ExecutionContext.get_or_create()
jroot = jctx.root
to.current_access_level = -1

Expand Down Expand Up @@ -347,7 +348,7 @@ def ref(cls, ref_id: str) -> Optional[NodeAnchor]:
def _save(self) -> None:
from .context import ExecutionContext

jsrc = ExecutionContext.get().datasource
jsrc = ExecutionContext.get_or_create().datasource

for edge in self.edges:
edge.save()
Expand All @@ -359,7 +360,7 @@ def destroy(self) -> None:
if self.architype and self.current_access_level > 1:
from .context import ExecutionContext

jsrc = ExecutionContext.get().datasource
jsrc = ExecutionContext.get_or_create().datasource
for edge in self.edges:
edge.destroy()

Expand Down Expand Up @@ -507,7 +508,7 @@ def ref(cls, ref_id: str) -> Optional[EdgeAnchor]:
def _save(self) -> None:
from .context import ExecutionContext

jsrc = ExecutionContext.get().datasource
jsrc = ExecutionContext.get_or_create().datasource

if source := self.source:
source.save()
Expand All @@ -522,7 +523,7 @@ def destroy(self) -> None:
if self.architype and self.current_access_level == 1:
from .context import ExecutionContext

jsrc = ExecutionContext.get().datasource
jsrc = ExecutionContext.get_or_create().datasource

source = self.source
target = self.target
Expand Down Expand Up @@ -601,14 +602,14 @@ def ref(cls, ref_id: str) -> Optional[WalkerAnchor]:
def _save(self) -> None:
from .context import ExecutionContext

ExecutionContext.get().datasource.set(self)
ExecutionContext.get_or_create().datasource.set(self)

def destroy(self) -> None:
"""Delete Anchor."""
if self.architype and self.current_access_level > 1:
from .context import ExecutionContext

ExecutionContext.get().datasource.remove(self)
ExecutionContext.get_or_create().datasource.remove(self)

def sync(self, node: Optional["NodeAnchor"] = None) -> Optional[WalkerArchitype]:
"""Retrieve the Architype from db and return."""
Expand Down
2 changes: 1 addition & 1 deletion jaclang/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def validate_access(self) -> bool:
return self.root.has_read_access(self.entry)

@staticmethod
def get(options: Optional[dict[str, Any]] = None) -> ExecutionContext:
def get_or_create(options: Optional[dict[str, Any]] = None) -> ExecutionContext:
"""Get or create execution context."""
if not isinstance(ctx := EXECUTION_CONTEXT.get(None), ExecutionContext):
EXECUTION_CONTEXT.set(ctx := ExecutionContext(**options or {}))
Expand Down
2 changes: 1 addition & 1 deletion jaclang/plugin/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class JacFeatureDefaults:
@hookimpl
def context(options: Optional[dict[str, Any]]) -> ExecutionContext:
"""Get the execution context."""
return ExecutionContext.get(options)
return ExecutionContext.get_or_create(options)

@staticmethod
@hookimpl
Expand Down
1 change: 0 additions & 1 deletion jaclang/vendor/orjson-3.10.6.dist-info/INSTALLER

This file was deleted.

Loading

0 comments on commit e988be6

Please sign in to comment.