"""Backend package facade: native Periscope + inherited PinScope. ``periscope/src/backend`` and ``periscope/dependency/backend`` are merged via pkgutil path extension. Do not put application modules in this directory. """ from __future__ import annotations import sys from pathlib import Path from pkgutil import extend_path _REPO = Path(__file__).resolve().parents[1] _SRC = _REPO / "periscope" / "src" _DEP = _REPO / "periscope" / "dependency" # Last insert is searched first: native src overlays inherited dependency. for _p in (_DEP, _SRC): _s = str(_p) if not _p.is_dir(): continue if _s in sys.path: sys.path.remove(_s) sys.path.insert(0, _s) def _prefer_native_backend(paths: list[str]) -> list[str]: src, other, dep = [], [], [] for p in paths: norm = p.replace("\\", "/") if "/periscope/src/" in norm: src.append(p) elif "/periscope/dependency/" in norm: dep.append(p) else: other.append(p) return src + other + dep __path__ = _prefer_native_backend(list(extend_path(__path__, __name__)))