Skip to content

Commit 32acc7a

Browse files
committed
Modify startup for Alis 2027.1 that now ships with Python (3.12)
1 parent a3757ad commit 32acc7a

3 files changed

Lines changed: 50 additions & 22 deletions

File tree

python/tk_framework_alias/server/api/__init__.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_module_path(module_name, alias_version):
5454
return module_path
5555

5656

57-
def get_alias_api_module():
57+
def get_alias_api_module(alias_bin_path=None):
5858
"""
5959
Import the right Alias Python API module according to the criteria:
6060
- the version of Alias
@@ -63,12 +63,33 @@ def get_alias_api_module():
6363
The Alias Python API supports Python >= 3
6464
"""
6565

66+
# import debugpy
67+
# try:
68+
# debugpy.listen(5678)
69+
# debugpy.wait_for_client()
70+
# except Exception as e:
71+
# print(e)
72+
6673
# Determine the module name based on if running in OpenAlias or OpenModel
6774
# If the executable is Alias, then it is OpenAlias, else OpenModel.
6875
is_open_model = os.path.basename(sys.executable) != "Alias.exe"
6976
module_name = OPEN_MODEL_API_NAME if is_open_model else OPEN_ALIAS_API_NAME
7077
alias_version = get_alias_version()
71-
module_path = get_module_path(module_name, alias_version)
78+
79+
print(f"init_api alias bin path: {alias_bin_path}")
80+
# First check if Alias ships the Python API module
81+
module_path = None
82+
if alias_bin_path:
83+
alias_api_pyd = f"{module_name}.pyd"
84+
alias_python_module_path = os.path.join(alias_bin_path, alias_api_pyd)
85+
print(f"init_api alias python module path: {alias_python_module_path}")
86+
if os.path.exists(alias_python_module_path):
87+
module_path = alias_python_module_path
88+
89+
if not module_path:
90+
# Fallback to the framework's Python API module
91+
module_path = get_module_path(module_name, alias_version)
92+
7293
if not module_path:
7394
return None
7495

@@ -122,6 +143,6 @@ def get_alias_api_module():
122143
)
123144
alias_dll_path = os.path.dirname(alias_bin_path)
124145
with os.add_dll_directory(alias_dll_path):
125-
alias_api = get_alias_api_module()
146+
alias_api = get_alias_api_module(alias_dll_path)
126147
else:
127148
alias_api = get_alias_api_module()

python/tk_framework_alias_utils/environment_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ def get_framework_supported_python_versions():
524524
(3, 9),
525525
(3, 10),
526526
(3, 11),
527+
(3, 12),
527528
(3, 13),
528529
]
529530

python/tk_framework_alias_utils/startup.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import shutil
1717
import zipfile
1818
import pprint
19+
import re
1920
import subprocess
2021
import zipfile
2122

@@ -830,7 +831,8 @@ def ensure_plugin_ready(
830831
logger = logging.getLogger(__file__)
831832
logger.setLevel(logging.DEBUG)
832833

833-
alias_python_exe = None
834+
alias_python_supported = False
835+
server_python_exe = None
834836

835837
if version_cmp(alias_version, "2024.0") >= 0:
836838
# Alias >= 2024.0
@@ -843,18 +845,23 @@ def ensure_plugin_ready(
843845

844846
if version_cmp(alias_version, "2027.1") >= 0:
845847
# Alias >= 2027.1 now supports Python and ships python interpreter.
846-
alias_python_exe = os.path.join(sys.executable, "Python", "python.exe")
847-
if not os.path.exists(alias_python_exe):
848-
alias_python_exe = None
848+
alias_python_supported = True
849+
alias_bin_path = os.path.dirname(alias_exec_path)
850+
alias_python_dir = os.path.join(alias_bin_path, "Python")
851+
if not os.path.exists(alias_python_dir):
849852
raise Exception(
850-
f"Failed to find Alias Python interpreter at {alias_python_exe}"
853+
f"Could not find Alias Python directory at {alias_python_dir}"
854+
)
855+
for filename in os.listdir(alias_python_dir):
856+
match = re.match(r"python(\d)(\d+)\.dll", filename)
857+
if match:
858+
py_major_version = int(match.group(1))
859+
py_minor_version = int(match.group(2))
860+
break
861+
else:
862+
raise Exception(
863+
f"Could not determine Alias Python version from {alias_python_dir}"
851864
)
852-
result = subprocess.run(
853-
[alias_python_exe, "--version"], capture_output=True, text=True
854-
)
855-
version_string = result.stdout.strip() # e.g. "Python 3.12.0"
856-
py_major_version = int(version_string.split(" ")[1].split(".")[0])
857-
py_minor_version = int(version_string.split(" ")[1].split(".")[1])
858865
elif version_cmp(alias_version, "2026.0") >= 0:
859866
# Alias >= 2026.0 has removed dependency on Qt/PySide for the FPT plugin
860867
py_major_version = 3
@@ -867,14 +874,11 @@ def ensure_plugin_ready(
867874
py_major_version = 3
868875
py_minor_version = 7
869876

870-
install_python_packages = os.environ.get(
871-
"SHOTGRID_ALIAS_INSTALL_PYTHON_PACKAGES"
872-
) in ("1", "true", "True")
877+
if not alias_python_supported:
878+
install_python_packages = os.environ.get(
879+
"SHOTGRID_ALIAS_INSTALL_PYTHON_PACKAGES"
880+
) in ("1", "true", "True")
873881

874-
if alias_python_exe:
875-
# Use the Alias Python interpreter
876-
server_python_exe = alias_python_exe
877-
else:
878882
# Use the framework's Python interpreter (installed for user)
879883
server_python_exe = ensure_python_installed(
880884
py_major_version,
@@ -895,7 +899,9 @@ def ensure_plugin_ready(
895899
# version.
896900
ensure_python_packages_installed(logger=logger)
897901

898-
if not alias_python_exe:
902+
if alias_python_supported:
903+
plugin_lst_path = None
904+
else:
899905
# For Alias < 2027.1, pre-python support we use C++ compiled plugin
900906
# Get the file path to the .lst file that contains the file path to the Alias Plugin to
901907
# load at startup with Alias.

0 commit comments

Comments
 (0)