Spaces:
Running
Running
Download tests/plugins_path_helper.py from Leon4gr45/brain: direct link, hf CLI and curl.
- Browser
- Download file 942 Bytes
-
https://huggingface.co/spaces/Leon4gr45/brain/resolve/main/tests/plugins_path_helper.py
- Command line
-
hf download hf://spaces/Leon4gr45/brain/tests/plugins_path_helper.py
-
curl -L -o plugins_path_helper.py https://huggingface.co/spaces/Leon4gr45/brain/resolve/main/tests/plugins_path_helper.py
942 Bytes
| """Load plugin modules without installing the plugin package.""" | |
| from __future__ import annotations | |
| import importlib.util | |
| import sys | |
| import unittest | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| PLUGIN = ROOT / "plugins" / "recsys-gnn" | |
| def _load(name: str, path: Path): | |
| if not path.is_file(): | |
| raise unittest.SkipTest(f"optional plugin artifact is not installed: {path}") | |
| # Ensure plugin root is on path so `from models.X` works inside modules. | |
| plugin_str = str(PLUGIN) | |
| if plugin_str not in sys.path: | |
| sys.path.insert(0, plugin_str) | |
| spec = importlib.util.spec_from_file_location(name, path) | |
| assert spec and spec.loader | |
| mod = importlib.util.module_from_spec(spec) | |
| sys.modules[name] = mod | |
| spec.loader.exec_module(mod) | |
| return mod | |
| def load_export_edges(): | |
| return _load( | |
| "recsys_gnn_export_edges", | |
| PLUGIN / "models" / "export_edges.py", | |
| ) | |