fix: register aitbc_cli.core in sys.modules before loading core/main.py
Some checks failed
CLI Tests / test-cli (push) Has been cancelled
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled

- Register aitbc_cli.core module pointing to core/ directory before loading
- Register aitbc_cli.core.main in sys.modules before exec_module
- Fixes No module named 'aitbc_cli.core' error when core/main.py imports
- Allows core/main.py to import from aitbc_cli.commands.* correctly
This commit is contained in:
aitbc
2026-05-26 11:39:18 +02:00
parent cff0dc1393
commit 98390554b2

View File

@@ -26,16 +26,30 @@ def __getattr__(name: str):
if name not in __all__:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
# Load core/main.py directly via spec_from_file_location to avoid package resolution issues
# Set up sys.modules for proper package resolution
# core/ is a sibling of aitbc_cli/, but imports reference it as aitbc_cli.core
# We need to register these in sys.modules before loading core/main.py
import importlib.util
from pathlib import Path
cli_path = Path(__file__).parent.parent / "core" / "main.py"
spec = importlib.util.spec_from_file_location("aitbc_cli_core_main", cli_path)
cli_dir = Path(__file__).parent
core_dir = cli_dir.parent / "core"
# Register aitbc_cli.core as a module pointing to the core/ directory
if "aitbc_cli.core" not in sys.modules:
core_spec = importlib.util.spec_from_file_location("aitbc_cli.core", core_dir / "__init__.py")
if core_spec and core_spec.loader:
core_module = importlib.util.module_from_spec(core_spec)
sys.modules["aitbc_cli.core"] = core_module
# Load core/main.py and register it as aitbc_cli.core.main
cli_path = core_dir / "main.py"
spec = importlib.util.spec_from_file_location("aitbc_cli.core.main", cli_path)
if spec is None or spec.loader is None:
raise ImportError(f"Unable to load modular CLI entrypoint from {cli_path}")
module = importlib.util.module_from_spec(spec)
sys.modules["aitbc_cli.core.main"] = module
spec.loader.exec_module(module)
value = module.cli if name == "cli" else module.main