From 7f068535448bcd8f5042fd797b5133191907a16c Mon Sep 17 00:00:00 2001 From: Zane V Date: Sun, 16 Nov 2025 10:51:32 -0500 Subject: [PATCH] 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. --- terminal.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/terminal.py b/terminal.py index 6a94d71..158557e 100644 --- a/terminal.py +++ b/terminal.py @@ -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,