Skip to content

Commit 3381947

Browse files
authored
Fix background publish for Alias 2026.1 (#18)
* Alias 2026.1 has a MSVC runtime DLL conflict with PySide 6.5 which prevents the alias_api module from loading * Add workaround to force loading the alias_api module first, before sgtk which loads PySide
1 parent f9c310f commit 3381947

3 files changed

Lines changed: 55 additions & 5 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exclude: "ui\/.*py$"
1414
# List of super useful formatters.
1515
repos:
1616
- repo: https://github.com/pre-commit/pre-commit-hooks
17-
rev: v3.2.0
17+
rev: v6.0.0
1818
hooks:
1919
# Ensures the code is syntaxically correct
2020
- id: check-ast
@@ -33,7 +33,7 @@ repos:
3333
- id: trailing-whitespace
3434
# Leave black at the bottom so all touchups are done before it is run.
3535
- repo: https://github.com/ambv/black
36-
rev: 22.3.0
36+
rev: 25.9.0
3737
hooks:
3838
- id: black
3939
language_version: python3

hooks/exec_info.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Source Code License included in this distribution package. See LICENSE.
77

88
import os
9+
import re
910
import sys
1011

1112
import sgtk
@@ -54,6 +55,23 @@ def get_subprocess_environment(self):
5455
env["PATH"] = "{};{}".format(alias_bin_folder, env.get("PATH", ""))
5556
# Ensure tk-alias engine is running in OpenModel (headless/batch mode)
5657
env["TK_ALIAS_OPEN_MODEL"] = "1"
58+
59+
# Set environment variables for the background publish process to import the Alias api module
60+
# NOTE: this is a workaround to MSVC runtime DLL conflicts between the Alias api and PySide
61+
alias_exec_path = os.environ.get("TK_ALIAS_EXECPATH")
62+
if not alias_exec_path:
63+
raise Exception(
64+
"Background publish for Alias requires TK_ALIAS_EXECPATH environment variable to be set"
65+
)
66+
env["BG_PUBLISH_ALIAS_DLL_PATH"] = os.path.dirname(alias_exec_path)
67+
# Get the api path for the python version that will run the background publish process
68+
api_path = os.path.dirname(current_engine.alias_py.__file__)
69+
bg_publish_python_version = (
70+
f"python{sys.version_info.major}.{sys.version_info.minor}"
71+
)
72+
api_path = re.sub(r"python\d+\.\d+", bg_publish_python_version, api_path)
73+
env["BG_PUBLISH_ALIAS_API_PATH"] = api_path
74+
5775
return env
5876

5977
# in case of VRED, we don't want to enable the automatic Flow Production Tracking integration in order to

scripts/run_publish_process.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import os
1111
import sys
1212

13-
import sgtk
1413
from tank_vendor import yaml
1514

1615

@@ -151,6 +150,41 @@ def main(
151150
:param monitor_file_path: Path to the file to use to monitor the publish process
152151
"""
153152

153+
# Initialize environment before importing sgtk
154+
if engine_name == "tk-alias":
155+
# Import the Alias api module first to ensure the correct MSVC runtime DLLs are loaded
156+
# NOTE: since this is not using the tk-alias engine api init, this api module will not have extensions available
157+
158+
# Add the api path for importing the module
159+
api_path = os.environ.get("BG_PUBLISH_ALIAS_API_PATH")
160+
if not api_path:
161+
raise Exception(
162+
"Background publish for Alias requires BG_PUBLISH_ALIAS_API_PATH environment variable to be set"
163+
)
164+
sys.path.insert(0, api_path)
165+
166+
# Add the Alias DLL path to load the Alias lib dependency for the api
167+
if hasattr(os, "add_dll_directory"):
168+
alias_dll_path = os.environ.get("BG_PUBLISH_ALIAS_DLL_PATH")
169+
if not alias_dll_path:
170+
raise Exception(
171+
"Background publish for Alias requires BG_PUBLISH_ALIAS_DLL_PATH environment variable to be set"
172+
)
173+
os.add_dll_directory(alias_dll_path)
174+
175+
# Import the Alias api module and initialize
176+
try:
177+
import alias_api_om as alias_api
178+
179+
alias_api.initialize_universe()
180+
except Exception as e:
181+
raise Exception(
182+
f"Failed to import and initialize Alias Python API for OpenModel: {e}"
183+
)
184+
185+
# Delay importing the sgtk module to allow importing any necessary modules before sgtk
186+
import sgtk
187+
154188
# initialize a log handler
155189
log_path = os.path.join(os.path.dirname(monitor_file_path), "bg_publish.log")
156190
log_handler = logging.FileHandler(log_path)
@@ -174,8 +208,6 @@ def main(
174208

175209
# import pymel to be sure everything has been sourced and imported
176210
import pymel.core as pm
177-
elif engine_name == "tk-alias":
178-
alias_api = current_engine.alias_py
179211
elif engine_name == "tk-vred":
180212
import vrController
181213
import vrFileIO

0 commit comments

Comments
 (0)