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

Commit

Permalink
pluginable import
Browse files Browse the repository at this point in the history
  • Loading branch information
Sivasuthan9 committed Jan 29, 2024
1 parent bb9c91d commit 239be11
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
7 changes: 4 additions & 3 deletions jaclang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import sys

sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "vendor"))

from jaclang.compiler.importer import jac_import # noqa: E402
from jaclang.plugin.feature import JacFeature # noqa: E402
from jaclang.vendor import lark # noqa: E402
from jaclang.vendor import mypy # noqa: E402
from jaclang.vendor import pluggy # noqa: E402

JacFeature.pm.load_setuptools_entrypoints("jac")


__all__ = [
"jac_import",
"lark",
"mypy",
"pluggy",
]

JacFeature.pm.load_setuptools_entrypoints("jac")
jac_import = JacFeature.jac_import
2 changes: 1 addition & 1 deletion jaclang/compiler/importer.py → jaclang/core/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from jaclang.utils.log import logging


def jac_import(
def j_import(
target: str,
base_path: Optional[str] = None,
cachable: bool = True,
Expand Down
22 changes: 20 additions & 2 deletions jaclang/plugin/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from __future__ import annotations

import os
import types
from dataclasses import dataclass, field
from functools import wraps
from typing import Any, Callable, Optional, Type

from jaclang import jac_import
from jaclang.core.importer import j_import
from jaclang.plugin.spec import (
ArchBound,
Architype,
Expand Down Expand Up @@ -96,11 +97,28 @@ def run_test(filename: str) -> None:
base = base if base else "./"
mod_name = mod_name[:-4]
JacTestCheck.reset()
jac_import(target=mod_name, base_path=base)
j_import(target=mod_name, base_path=base)
JacTestCheck.run_test()
else:
print("Not a .jac file.")

@staticmethod
@hookimpl
def jac_import(
target: str,
base_path: Optional[str] = None,
cachable: bool = True,
override_name: Optional[str] = None,
) -> Optional[types.ModuleType]:
"""Core Import Process."""
mdle = j_import(
target=target,
base_path=base_path,
cachable=cachable,
override_name=override_name,
)
return mdle

@staticmethod
@hookimpl
def elvis(op1: Optional[T], op2: T) -> T:
Expand Down
16 changes: 16 additions & 0 deletions jaclang/plugin/feature.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Jac Language Features."""
from __future__ import annotations

import types
from typing import Any, Callable, Optional, Type

from jaclang.plugin.default import JacFeatureDefaults
Expand Down Expand Up @@ -50,6 +51,21 @@ def run_test(filename: str) -> None:
"""Run the test suite in the specified .jac file."""
return JacFeature.pm.hook.run_test(filename=filename)

@staticmethod
def jac_import(
target: str,
base_path: Optional[str] = None,
cachable: bool = True,
override_name: Optional[str] = None,
) -> Optional[types.ModuleType]:
"""Core Import Process."""
return JacFeature.pm.hook.jac_import(
target=target,
base_path=base_path,
cachable=cachable,
override_name=override_name,
)

@staticmethod
def elvis(op1: Optional[T], op2: T) -> T:
"""Jac's elvis operator feature."""
Expand Down
13 changes: 12 additions & 1 deletion jaclang/plugin/spec.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Jac Language Features."""
from __future__ import annotations


import types
from typing import Any, Callable, Optional, Type, TypeVar

from jaclang.core.construct import (
Expand Down Expand Up @@ -73,6 +73,17 @@ def run_test(filename: str) -> None:
"""
raise NotImplementedError

@staticmethod
@hookspec(firstresult=True)
def jac_import(
target: str,
base_path: Optional[str] = None,
cachable: bool = True,
override_name: Optional[str] = None,
) -> Optional[types.ModuleType]:
"""Core Import Process."""
raise NotImplementedError

@staticmethod
@hookspec(firstresult=True)
def elvis(op1: Optional[T], op2: T) -> T:
Expand Down

0 comments on commit 239be11

Please sign in to comment.