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

Commit

Permalink
Merge pull request #186 from Jaseci-Labs/example_plugin
Browse files Browse the repository at this point in the history
feat: example plugin for walkers
  • Loading branch information
marsninja authored Jan 31, 2024
2 parents a437b70 + 02abf41 commit 1e4379d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Empty file.
39 changes: 39 additions & 0 deletions examples/plugins/jaclang_walkerapi/jaclang_walkerapi/walkerapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from jaclang.plugin.default import hookimpl
from jaclang.plugin.spec import ArchBound, WalkerArchitype, DSFunc

from dataclasses import dataclass
from functools import wraps
from typing import Type, Callable


class JacFeature:
@staticmethod
@hookimpl
def make_walker(
on_entry: list[DSFunc], on_exit: list[DSFunc]
) -> Callable[[type], type]:
"""Create a walker architype."""

def decorator(cls: Type[ArchBound]) -> Type[ArchBound]:
"""Decorate class."""
cls = dataclass(eq=False)(cls)
for i in on_entry + on_exit:
i.resolve(cls)
arch_cls = WalkerArchitype
if not issubclass(cls, arch_cls):
cls = type(cls.__name__, (cls, arch_cls), {})
cls._jac_entry_funcs_ = on_entry
cls._jac_exit_funcs_ = on_exit
inner_init = cls.__init__

@wraps(inner_init)
def new_init(self: ArchBound, *args: object, **kwargs: object) -> None:
inner_init(self, *args, **kwargs)
arch_cls.__init__(self)

cls.__init__ = new_init
print("IM IN THE PLUGIN YO!")
return cls

print("IM IN THE PLUGIN YO!")
return decorator
23 changes: 23 additions & 0 deletions examples/plugins/jaclang_walkerapi/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Jaclang setup file."""
from __future__ import annotations

from setuptools import find_packages, setup # type: ignore


VERSION = "0.0.1"

setup(
name="jaclang-walkerapi",
version=VERSION,
packages=find_packages(include=["jaclang_walkerapi", "jaclang_walkerapi.*"]),
install_requires=[],
package_data={
"": ["*.ini"],
},
entry_points={
"jac": ["walkerapi = jaclang_walkerapi.walkerapi:JacFeature"],
},
author="Jason Mars",
author_email="[email protected]",
url="https://github.com/Jaseci-Labs/jaclang",
)

0 comments on commit 1e4379d

Please sign in to comment.