File size: 1,536 Bytes
0f6657d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
"""Unified OpenEnv package bundling the CLI and core runtime."""

from __future__ import annotations

from importlib import import_module, metadata

__all__ = [
    "core",
    "cli",
    "AutoEnv",
    "AutoAction",
    "GenericEnvClient",
    "GenericAction",
    "SyncEnvClient",
]


def _load_package_version() -> str:
    """Resolve the installed distribution version for the OpenEnv package."""
    for distribution_name in ("openenv-core", "openenv"):
        try:
            return metadata.version(distribution_name)
        except metadata.PackageNotFoundError:
            continue
    return "0.0.0"


__version__ = _load_package_version()


_LAZY_MODULES = {
    "core": ".core",
    "cli": ".cli",
}

_LAZY_ATTRS = {
    "AutoEnv": (".auto", "AutoEnv"),
    "AutoAction": (".auto", "AutoAction"),
    "GenericEnvClient": (".core", "GenericEnvClient"),
    "GenericAction": (".core", "GenericAction"),
    "SyncEnvClient": (".core", "SyncEnvClient"),
}


def __getattr__(name: str):
    if name in _LAZY_MODULES:
        module = import_module(_LAZY_MODULES[name], __name__)
        globals()[name] = module
        return module

    if name in _LAZY_ATTRS:
        module_path, attr_name = _LAZY_ATTRS[name]
        module = import_module(module_path, __name__)
        value = getattr(module, attr_name)
        globals()[name] = value
        return value

    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


def __dir__() -> list[str]:
    return sorted(set(globals().keys()) | set(__all__))