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

feat: example plugin for walkers #186

Merged
merged 1 commit into from
Jan 31, 2024
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
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",
)
Loading