Add dynamic import handling for 'zdtt' package in terminal.py

- Implemented a mechanism to ensure the 'zdtt' package is importable from both repository and installed locations.
- Added a fallback search for the package in various candidate directories if the initial import fails, enhancing compatibility and usability.
This commit is contained in:
2025-11-16 10:51:32 -05:00
parent 884288a2c4
commit 7f06853544

View File

@@ -23,6 +23,27 @@ import urllib.request
import urllib.error
import time as time_module
# Ensure local 'zdtt' package is importable both from repo and installed locations
try:
# Probe a quick import to determine availability
import zdtt # type: ignore
except Exception:
script_dir = os.path.dirname(os.path.abspath(__file__))
candidates = [
script_dir,
os.path.abspath(os.path.join(script_dir, '..')),
os.path.join(script_dir, 'zdtt'),
'/home/zane/ZDTT',
]
for path_candidate in candidates:
if path_candidate and os.path.isdir(path_candidate) and path_candidate not in sys.path:
sys.path.insert(0, path_candidate)
# Best-effort: ignore failure here; regular imports will raise if still missing
try:
import zdtt # type: ignore
except Exception:
pass
from zdtt.plugins import (
PROTECTED_COMMANDS as PLUGIN_PROTECTED_COMMANDS,
validate_plugin_ast as plugins_validate_ast,