Update __init__.py

This commit is contained in:
2025-11-25 00:49:53 +08:00
parent 3bbaa70350
commit 47a95bc71c

View File

@@ -28,32 +28,55 @@ def _ensure_studiolibrary_loaded():
if _studiolibrary_module is not None:
return _studiolibrary_module
# Add all necessary paths
# Add all necessary paths in correct order
_inner_studiolibrary = os.path.join(_current_dir, 'studiolibrary')
for _subdir in ['studiolibrarymaya', 'mutils', 'studioqt', 'studiovendor']:
_subdir_path = os.path.join(_current_dir, _subdir)
if _subdir_path not in sys.path:
sys.path.insert(0, _subdir_path)
# Import from inner studiolibrary by temporarily manipulating sys.path
# Remove current directory to avoid circular import
_saved_path = sys.path[:]
if _current_dir in sys.path:
sys.path.remove(_current_dir)
# Add the parent directory so packages can be imported correctly
# e.g., "import studioqt" will find studiolibrary/studioqt/
if _current_dir not in sys.path:
sys.path.insert(0, _current_dir)
# Add inner studiolibrary to the front
# Also add inner studiolibrary for direct imports
if _inner_studiolibrary not in sys.path:
sys.path.insert(0, _inner_studiolibrary)
# Load main.py directly to get the main function
_main_module = None
_load_error = None
# Try Python 3.4+ first
try:
import studiolibrary
_studiolibrary_module = studiolibrary
finally:
# Restore sys.path
sys.path = _saved_path
# But keep the inner studiolibrary path
if _inner_studiolibrary not in sys.path:
sys.path.insert(0, _inner_studiolibrary)
import importlib.util
spec = importlib.util.spec_from_file_location(
"studiolibrary_main",
os.path.join(_inner_studiolibrary, "main.py")
)
_main_module = importlib.util.module_from_spec(spec)
sys.modules["studiolibrary_main"] = _main_module
spec.loader.exec_module(_main_module)
except Exception as e:
_load_error = e
# Try Python 2.7 fallback
try:
import imp
_main_module = imp.load_source(
"studiolibrary_main",
os.path.join(_inner_studiolibrary, "main.py")
)
except Exception as e2:
# If both fail, raise the original error
raise _load_error if _load_error else e2
# Create a simple module object with main function
class StudioLibraryModule:
def __init__(self):
self.main = _main_module.main
self.__version__ = "2.20.2"
def version(self):
return self.__version__
_studiolibrary_module = StudioLibraryModule()
return _studiolibrary_module