import os
import sys
__version__ = "0.1.0"
BACKEND = os.environ.get("CONSORTIUM_BACKEND", "rust")
_this_dir = os.path.dirname(os.path.abspath(__file__))
def _find_oracle_lib():
candidates = []
env_dir = os.environ.get("LIB_CLUSTERSHELL")
if env_dir:
candidates.append(env_dir)
_repo_root = os.path.normpath(os.path.join(_this_dir, "..", "..", ".."))
candidates.append(
os.path.join(os.path.dirname(_repo_root), "consortium-tests", "lib")
)
candidates.append(os.path.join(_repo_root, "lib"))
for cand in candidates:
if os.path.isdir(cand):
return os.path.normpath(cand)
return None
if BACKEND == "python":
_lib_dir = _find_oracle_lib()
if _lib_dir is not None:
_parent = os.path.dirname(_this_dir)
if _parent in sys.path:
sys.path.remove(_parent)
if _lib_dir not in sys.path:
sys.path.insert(0, _lib_dir)
for key in list(sys.modules.keys()):
if key == "ClusterShell" or key.startswith("ClusterShell."):
del sys.modules[key]
import importlib
_orig = importlib.import_module("ClusterShell")
globals().update(_orig.__dict__)
else:
raise RuntimeError(
"CONSORTIUM_BACKEND=python but cannot find the original ClusterShell "
"lib/ (looked in $LIB_CLUSTERSHELL, ../consortium-tests/lib, and the "
"in-repo lib/). Set LIB_CLUSTERSHELL env var to the lib/ directory "
"containing the original."
)
else:
_lib_dir = _find_oracle_lib()
if _lib_dir is not None:
_lib_pkg = os.path.join(_lib_dir, "ClusterShell")
if os.path.isdir(_lib_pkg) and _lib_pkg not in __path__:
__path__.append(_lib_pkg)