aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/infini/const.py3
-rw-r--r--src/infini/internal.py28
2 files changed, 17 insertions, 14 deletions
diff --git a/src/infini/const.py b/src/infini/const.py
deleted file mode 100644
index 2ec42488..00000000
--- a/src/infini/const.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from pathlib import Path
-
-SRC_HOME = Path.home() / ".ipm" / "src" \ No newline at end of file
diff --git a/src/infini/internal.py b/src/infini/internal.py
index 4f800297..460407a8 100644
--- a/src/infini/internal.py
+++ b/src/infini/internal.py
@@ -1,18 +1,24 @@
-from infini.typing import List, ModuleType
-from infini.const import SRC_HOME
+from infini.loader import Loader
+from infini.register import Register
+from infini.typing import List
+from pathlib import Path
-import importlib
import sys
+import inspect
-def require(name: str, paths: List | None = None) -> ModuleType:
+def require(name: str, paths: List | None = None) -> Register:
+ caller_frame = inspect.stack()[1]
+ caller_file = caller_frame[0].f_globals["__file__"]
+
+ default_paths = [Path(caller_file).resolve().parent]
paths = [
str(path)
- for path in (
- (list(paths) + [str(SRC_HOME / name)]) if paths else [str(SRC_HOME / name)]
- )
+ for path in ((list(paths) + default_paths) if paths else default_paths)
]
- sys.path.extend(paths)
- module = importlib.import_module(name)
- (sys.path.remove(path) for path in paths)
- return module
+ (sys.path.insert(0, path) for path in paths)
+
+ with Loader() as loader:
+ loader.load(name)
+ sys.path = sys.path[len(paths) - 1 :]
+ return loader.into_register()