Spaces:
Running
Running
File size: 1,975 Bytes
03a907a | 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | """
Alias the real dataset package so that `import src.dataset` works.
This module ensures that `import src.dataset` and
`from src.dataset.problem_X.buggy import ...` statements work correctly
by aliasing the real dataset package and all its nested submodules.
This is needed because:
- Test files import from `src.dataset.problem_X.buggy`
- But the actual files are in `dataset/problem_X/buggy.py`
- So we create sys.modules aliases to bridge the gap
"""
import sys
import importlib
import pkgutil
try:
import dataset as _real_dataset
except ImportError:
# dataset package not on sys.path — try to add the env root
import os
from pathlib import Path
_here = Path(__file__).parent # src/dataset/
# Walk up to find the directory that contains the `dataset/` folder
for _candidate in [_here.parent.parent, _here.parent.parent.parent]:
if (_candidate / "dataset").is_dir():
sys.path.insert(0, str(_candidate))
break
import dataset as _real_dataset
# Register top-level alias
sys.modules["src.dataset"] = _real_dataset
# Register every direct subpackage / submodule and their children
for _pkg in pkgutil.iter_modules(_real_dataset.__path__):
_full = f"dataset.{_pkg.name}"
_alias = f"src.dataset.{_pkg.name}"
try:
_mod = importlib.import_module(_full)
sys.modules.setdefault(_alias, _mod)
# Also register nested submodules (e.g. problem_X.buggy, problem_X.helpers)
if hasattr(_mod, "__path__"):
for _sub in pkgutil.iter_modules(_mod.__path__):
_sub_full = f"{_full}.{_sub.name}"
_sub_alias = f"{_alias}.{_sub.name}"
try:
_sub_mod = importlib.import_module(_sub_full)
sys.modules.setdefault(_sub_alias, _sub_mod)
except Exception:
pass
except Exception:
pass
|