import sys
import importlib
import inspect
DEFAULTS = {
"np":"numpy",
"pd":"pandas",
"plt":"matplotlib.pyplot",
"sns":"seaborn",
"requests":"requests",
"sklearn":"sklearn",
"scipy":"scipy",
"bs4":"bs4",
"PIL":"PIL",
"tqdm":"tqdm",
"dateutil":"dateutil",
"flask":"flask",
"django":"django"
}
def _caller_globals():
    f = inspect.currentframe()
    if not f:
        return globals()
    caller = f.f_back
    while caller and caller.f_code.co_filename == __file__:
        caller = caller.f_back
    if caller:
        return caller.f_globals
    return globals()
def _import_name(module_path):
    try:
        m = importlib.import_module(module_path)
        return m
    except Exception:
        return None
def enable(packages=None):
    pkg_map = DEFAULTS.copy()
    if packages:
        if isinstance(packages, dict):
            pkg_map.update(packages)
        elif isinstance(packages, (list, tuple)):
            for name in packages:
                if isinstance(name, str):
                    pkg_map[name] = name
    g = _caller_globals()
    injected = {}
    for alias, module_path in pkg_map.items():
        mod = _import_name(module_path)
        if mod is None:
            continue
        injected[alias] = mod
        g[alias] = mod
    return injected
def configure_and_enable(packages=None):
    return enable(packages)
