Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/run_plugin_pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ jobs:
run: |
jac clean
jac tool gen_parser
jac run jaclang_jaseci/tests/simple_graph.jac &
jac serve jaclang_jaseci/tests/simple_graph.jac --port 8001 &
sleep 3
pytest
58 changes: 58 additions & 0 deletions jaclang_jaseci/plugin/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Module for registering CLI plugins for jaseci."""

import os
import pickle

from jaclang import jac_import
from jaclang.cli.cmdreg import cmd_registry
from jaclang.plugin.default import hookimpl
from jaclang.runtimelib.context import ExecutionContext
from jaclang.runtimelib.machine import JacMachine, JacProgram


class JacCmd:
"""Jac CLI."""

@staticmethod
@hookimpl
def create_cmd() -> None:
"""Create Jac CLI cmds."""

@cmd_registry.register
def serve(filename: str, host: str = "0.0.0.0", port: int = 8000) -> None:
from jaclang_jaseci import FastAPI

"""Serve the jac application."""
base, mod = os.path.split(filename)
base = base if base else "./"
mod = mod[:-4]

jctx = ExecutionContext.create()

if filename.endswith(".jac"):
jac_import(
target=mod,
base_path=base,
cachable=True,
override_name="__main__",
)
elif filename.endswith(".jir"):
with open(filename, "rb") as f:
JacMachine(base).attach_program(
JacProgram(mod_bundle=pickle.load(f), bytecode=None)
)
jac_import(
target=mod,
base_path=base,
cachable=True,
override_name="__main__",
)
else:
jctx.close()
JacMachine.detach()
raise ValueError("Not a valid file!\nOnly supports `.jac` and `.jir`")

FastAPI.start(host=host, port=port)

jctx.close()
JacMachine.detach()
9 changes: 0 additions & 9 deletions jaclang_jaseci/tests/simple_graph.jac
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Example of simple walker walking nodes."""
import:py from jaclang_jaseci {FastAPI}
import:py from jaclang_jaseci.core.architype {BaseAnchor}
import:py from jaclang_jaseci.core.context {JaseciContext}
import:py from jaclang_jaseci.jaseci.models {User as BaseUser, NO_PASSWORD}
Expand Down Expand Up @@ -453,12 +452,4 @@ walker post_with_body_and_file {
class __specs__ {
has auth: bool = False;
}
}

with entry:__main__ {
FastAPI.start(
host="0.0.0.0",
port=8001
# emailer=SendGridEmailer
);
}
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
],
package_data={},
entry_points={
"jac": ["jac = jaclang_jaseci.plugin.jaseci:JacPlugin"],
"jac": [
"jac = jaclang_jaseci.plugin.jaseci:JacPlugin",
"serve = jaclang_jaseci.plugin.cli:JacCmd",
],
},
author="Jason Mars",
author_email="[email protected]",
Expand Down