rl_code_fix_env / src /dataset /__init__.py
Viraj0112's picture
Upload folder using huggingface_hub
03a907a verified
"""
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