File size: 942 Bytes
ac68ae4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""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",
    )