SXXXXXXX_PyUCC/external/_setup_paths.py

34 lines
1015 B
Python

"""
Setup Python paths for external submodules.
This module ensures that external submodules are added to sys.path
before any other imports. It should be imported at the very beginning
of __main__.py and any test files.
"""
import sys
import os
def setup_external_paths():
"""Add external submodules to Python path if they exist."""
# Get the project root (parent of target_simulator/)
current_file = os.path.abspath(__file__)
target_simulator_dir = os.path.dirname(current_file)
project_root = os.path.dirname(target_simulator_dir)
# Add external submodules
external_base = os.path.join(project_root, "external")
external_modules = [
os.path.join(external_base, "python-resource-monitor"),
os.path.join(external_base, "python-tkinter-logger"),
]
for module_path in external_modules:
if os.path.isdir(module_path) and module_path not in sys.path:
sys.path.insert(0, module_path)
# Auto-execute when imported
setup_external_paths()