This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from Jaseci-Labs/example_plugin
feat: example plugin for walkers
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
39 changes: 39 additions & 0 deletions
39
examples/plugins/jaclang_walkerapi/jaclang_walkerapi/walkerapi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |