diff --git a/openpype/hosts/aftereffects/__init__.py b/openpype/hosts/aftereffects/__init__.py index e69de29bb2d..deae48d1229 100644 --- a/openpype/hosts/aftereffects/__init__.py +++ b/openpype/hosts/aftereffects/__init__.py @@ -0,0 +1,9 @@ +def add_implementation_envs(env, _app): + """Modify environments to contain all required for implementation.""" + defaults = { + "OPENPYPE_LOG_NO_COLORS": "True", + "WEBSOCKET_URL": "ws://localhost:8097/ws/" + } + for key, value in defaults.items(): + if not env.get(key): + env[key] = value diff --git a/openpype/hosts/blender/__init__.py b/openpype/hosts/blender/__init__.py index e69de29bb2d..4d932334497 100644 --- a/openpype/hosts/blender/__init__.py +++ b/openpype/hosts/blender/__init__.py @@ -0,0 +1,41 @@ +import os + + +def add_implementation_envs(env, _app): + """Modify environments to contain all required for implementation.""" + # Prepare path to implementation script + implementation_user_script_path = os.path.join( + os.environ["OPENPYPE_REPOS_ROOT"], + "repos", + "avalon-core", + "setup", + "blender" + ) + + # Add blender implementation script path to PYTHONPATH + python_path = env.get("PYTHONPATH") or "" + python_path_parts = [ + path + for path in python_path.split(os.pathsep) + if path + ] + python_path_parts.insert(0, implementation_user_script_path) + env["PYTHONPATH"] = os.pathsep.join(python_path_parts) + + # Modify Blender user scripts path + blender_user_scripts = env.get("BLENDER_USER_SCRIPTS") or "" + previous_user_scripts = [] + for path in blender_user_scripts.split(os.pathsep): + if path and os.path.exists(path): + path = os.path.normpath(path) + if path != implementation_user_script_path: + previous_user_scripts.append(path) + + env["OPENPYPE_BLENDER_USER_SCRIPTS"] = os.pathsep.join( + previous_user_scripts + ) + env["BLENDER_USER_SCRIPTS"] = implementation_user_script_path + + # Define Qt binding if not defined + if not env.get("QT_PREFERRED_BINDING"): + env["QT_PREFERRED_BINDING"] = "PySide2" diff --git a/openpype/hosts/harmony/__init__.py b/openpype/hosts/harmony/__init__.py index e69de29bb2d..8560fbaf4b6 100644 --- a/openpype/hosts/harmony/__init__.py +++ b/openpype/hosts/harmony/__init__.py @@ -0,0 +1,10 @@ +import os + + +def add_implementation_envs(env, _app): + """Modify environments to contain all required for implementation.""" + openharmony_path = os.path.join( + os.environ["OPENPYPE_REPOS_ROOT"], "pype", "vendor", "OpenHarmony" + ) + # TODO check if is already set? What to do if is already set? + env["LIB_OPENHARMONY_PATH"] = openharmony_path diff --git a/openpype/hosts/hiero/__init__.py b/openpype/hosts/hiero/__init__.py index e69de29bb2d..1781f808e2d 100644 --- a/openpype/hosts/hiero/__init__.py +++ b/openpype/hosts/hiero/__init__.py @@ -0,0 +1,40 @@ +import os +import platform + + +def add_implementation_envs(env, _app): + # Add requirements to HIERO_PLUGIN_PATH + pype_root = os.environ["OPENPYPE_REPOS_ROOT"] + new_hiero_paths = [ + os.path.join(pype_root, "openpype", "hosts", "hiero", "startup") + ] + old_hiero_path = env.get("HIERO_PLUGIN_PATH") or "" + for path in old_hiero_path.split(os.pathsep): + if not path or not os.path.exists(path): + continue + + norm_path = os.path.normpath(path) + if norm_path not in new_hiero_paths: + new_hiero_paths.append(norm_path) + + env["HIERO_PLUGIN_PATH"] = os.pathsep.join(new_hiero_paths) + + # Try to add QuickTime to PATH + quick_time_path = "C:/Program Files (x86)/QuickTime/QTSystem" + if platform.system() == "windows" and os.path.exists(quick_time_path): + path_value = env.get("PATH") or "" + path_paths = [ + path + for path in path_value.split(os.pathsep) + if path + ] + path_paths.append(quick_time_path) + env["PATH"] = os.pathsep.join(path_paths) + + # Set default values if are not already set via settings + defaults = { + "LOGLEVEL": "DEBUG" + } + for key, value in defaults.items(): + if not env.get(key): + env[key] = value diff --git a/openpype/hosts/houdini/__init__.py b/openpype/hosts/houdini/__init__.py index e69de29bb2d..8c12d13c813 100644 --- a/openpype/hosts/houdini/__init__.py +++ b/openpype/hosts/houdini/__init__.py @@ -0,0 +1,38 @@ +import os + + +def add_implementation_envs(env, _app): + # Add requirements to HOUDINI_PATH and HOUDINI_MENU_PATH + pype_root = os.environ["OPENPYPE_REPOS_ROOT"] + + startup_path = os.path.join( + pype_root, "openpype", "hosts", "houdini", "startup" + ) + new_houdini_path = [startup_path] + new_houdini_menu_path = [startup_path] + + old_houdini_path = env.get("HOUDINI_PATH") or "" + old_houdini_menu_path = env.get("HOUDINI_MENU_PATH") or "" + + for path in old_houdini_path.split(os.pathsep): + if not path or not os.path.exists(path): + continue + + norm_path = os.path.normpath(path) + if norm_path not in new_houdini_path: + new_houdini_path.append(norm_path) + + for path in old_houdini_menu_path.split(os.pathsep): + if not path or not os.path.exists(path): + continue + + norm_path = os.path.normpath(path) + if norm_path not in new_houdini_menu_path: + new_houdini_menu_path.append(norm_path) + + # Add ampersand for unknown reason (Maybe is needed in Houdini?) + new_houdini_path.append("&") + new_houdini_menu_path.append("&") + + env["HOUDINI_PATH"] = os.pathsep.join(new_houdini_path) + env["HOUDINI_MENU_PATH"] = os.pathsep.join(new_houdini_menu_path) diff --git a/openpype/hosts/maya/__init__.py b/openpype/hosts/maya/__init__.py index e69de29bb2d..549f100007a 100644 --- a/openpype/hosts/maya/__init__.py +++ b/openpype/hosts/maya/__init__.py @@ -0,0 +1,29 @@ +import os + + +def add_implementation_envs(env, _app): + # Add requirements to PYTHONPATH + pype_root = os.environ["OPENPYPE_REPOS_ROOT"] + new_python_paths = [ + os.path.join(pype_root, "openpype", "hosts", "maya", "startup"), + os.path.join(pype_root, "repos", "avalon-core", "setup", "maya"), + os.path.join(pype_root, "tools", "mayalookassigner") + ] + old_python_path = env.get("PYTHONPATH") or "" + for path in old_python_path.split(os.pathsep): + if not path or not os.path.exists(path): + continue + + norm_path = os.path.normpath(path) + if norm_path not in new_python_paths: + new_python_paths.append(norm_path) + + env["PYTHONPATH"] = os.pathsep.join(new_python_paths) + + # Set default values if are not already set via settings + defaults = { + "OPENPYPE_LOG_NO_COLORS": "Yes" + } + for key, value in defaults.items(): + if not env.get(key): + env[key] = value diff --git a/openpype/hosts/nuke/__init__.py b/openpype/hosts/nuke/__init__.py index e69de29bb2d..f1e81617e07 100644 --- a/openpype/hosts/nuke/__init__.py +++ b/openpype/hosts/nuke/__init__.py @@ -0,0 +1,43 @@ +import os +import platform + + +def add_implementation_envs(env, _app): + # Add requirements to NUKE_PATH + pype_root = os.environ["OPENPYPE_REPOS_ROOT"] + new_nuke_paths = [ + os.path.join(pype_root, "openpype", "hosts", "nuke", "startup"), + os.path.join( + pype_root, "repos", "avalon-core", "setup", "nuke", "nuke_path" + ) + ] + old_nuke_path = env.get("NUKE_PATH") or "" + for path in old_nuke_path.split(os.pathsep): + if not path or not os.path.exists(path): + continue + + norm_path = os.path.normpath(path) + if norm_path not in new_nuke_paths: + new_nuke_paths.append(norm_path) + + env["NUKE_PATH"] = os.pathsep.join(new_nuke_paths) + + # Try to add QuickTime to PATH + quick_time_path = "C:/Program Files (x86)/QuickTime/QTSystem" + if platform.system() == "windows" and os.path.exists(quick_time_path): + path_value = env.get("PATH") or "" + path_paths = [ + path + for path in path_value.split(os.pathsep) + if path + ] + path_paths.append(quick_time_path) + env["PATH"] = os.pathsep.join(path_paths) + + # Set default values if are not already set via settings + defaults = { + "LOGLEVEL": "DEBUG" + } + for key, value in defaults.items(): + if not env.get(key): + env[key] = value diff --git a/openpype/hosts/photoshop/__init__.py b/openpype/hosts/photoshop/__init__.py index e69de29bb2d..a91e0a65ff7 100644 --- a/openpype/hosts/photoshop/__init__.py +++ b/openpype/hosts/photoshop/__init__.py @@ -0,0 +1,9 @@ +def add_implementation_envs(env, _app): + """Modify environments to contain all required for implementation.""" + defaults = { + "OPENPYPE_LOG_NO_COLORS": "True", + "WEBSOCKET_URL": "ws://localhost:8099/ws/" + } + for key, value in defaults.items(): + if not env.get(key): + env[key] = value diff --git a/openpype/hosts/tvpaint/__init__.py b/openpype/hosts/tvpaint/__init__.py index e69de29bb2d..0e793fcf9f3 100644 --- a/openpype/hosts/tvpaint/__init__.py +++ b/openpype/hosts/tvpaint/__init__.py @@ -0,0 +1,8 @@ +def add_implementation_envs(env, _app): + """Modify environments to contain all required for implementation.""" + defaults = { + "OPENPYPE_LOG_NO_COLORS": "True" + } + for key, value in defaults.items(): + if not env.get(key): + env[key] = value diff --git a/openpype/hosts/unreal/__init__.py b/openpype/hosts/unreal/__init__.py index e69de29bb2d..1280442916a 100644 --- a/openpype/hosts/unreal/__init__.py +++ b/openpype/hosts/unreal/__init__.py @@ -0,0 +1,18 @@ +import os + + +def add_implementation_envs(env, _app): + """Modify environments to contain all required for implementation.""" + # Set AVALON_UNREAL_PLUGIN required for Unreal implementation + unreal_plugin_path = os.path.join( + os.environ["OPENPYPE_REPOS_ROOT"], "repos", "avalon-unreal-integration" + ) + env["AVALON_UNREAL_PLUGIN"] = unreal_plugin_path + + # Set default environments if are not set via settings + defaults = { + "OPENPYPE_LOG_NO_COLORS": "True" + } + for key, value in defaults.items(): + if not env.get(key): + env[key] = value diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index c5c192f51bf..a44c43102f9 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -3,7 +3,6 @@ import copy import json import platform -import getpass import collections import inspect import subprocess @@ -362,7 +361,6 @@ def launch(self, app_name, **data): context = ApplicationLaunchContext( app, executable, **data ) - # TODO pass context through launch hooks return context.launch() @@ -626,7 +624,7 @@ def __init__(self, application, executable, **data): # Logger logger_name = "{}-{}".format(self.__class__.__name__, self.app_name) - self.log = PypeLogger().get_logger(logger_name) + self.log = PypeLogger.get_logger(logger_name) self.executable = executable @@ -1033,7 +1031,7 @@ def _merge_env(env, current_env): return result -def prepare_host_environments(data): +def prepare_host_environments(data, implementation_envs=True): """Modify launch environments based on launched app and context. Args: @@ -1089,7 +1087,24 @@ def prepare_host_environments(data): # Merge dictionaries env_values = _merge_env(tool_env, env_values) - final_env = _merge_env(acre.compute(env_values), data["env"]) + loaded_env = _merge_env(acre.compute(env_values), data["env"]) + + final_env = None + # Add host specific environments + if app.host_name and implementation_envs: + module = __import__("openpype.hosts", fromlist=[app.host_name]) + host_module = getattr(module, app.host_name, None) + add_implementation_envs = None + if host_module: + add_implementation_envs = getattr( + host_module, "add_implementation_envs", None + ) + if add_implementation_envs: + # Function may only modify passed dict without returning value + final_env = add_implementation_envs(loaded_env, app) + + if final_env is None: + final_env = loaded_env # Update env data["env"].update(final_env) diff --git a/openpype/settings/defaults/system_settings/applications.json b/openpype/settings/defaults/system_settings/applications.json index 63d6da46337..020924db67a 100644 --- a/openpype/settings/defaults/system_settings/applications.json +++ b/openpype/settings/defaults/system_settings/applications.json @@ -5,18 +5,11 @@ "icon": "{}/app_icons/maya.png", "host_name": "maya", "environment": { - "PYTHONPATH": [ - "{OPENPYPE_REPOS_ROOT}/openpype/hosts/maya/startup", - "{OPENPYPE_REPOS_ROOT}/repos/avalon-core/setup/maya", - "{OPENPYPE_REPOS_ROOT}/repos/maya-look-assigner", - "{PYTHONPATH}" - ], "MAYA_DISABLE_CLIC_IPM": "Yes", "MAYA_DISABLE_CIP": "Yes", "MAYA_DISABLE_CER": "Yes", "PYMEL_SKIP_MEL_INIT": "Yes", - "LC_ALL": "C", - "OPENPYPE_LOG_NO_COLORS": "Yes" + "LC_ALL": "C" }, "variants": { "2022": { @@ -110,15 +103,7 @@ "icon": "{}/app_icons/nuke.png", "host_name": "nuke", "environment": { - "NUKE_PATH": [ - "{OPENPYPE_REPOS_ROOT}/repos/avalon-core/setup/nuke/nuke_path", - "{OPENPYPE_REPOS_ROOT}/openpype/hosts/nuke/startup", - "{OPENPYPE_STUDIO_PLUGINS}/nuke" - ], - "PATH": { - "windows": "C:/Program Files (x86)/QuickTime/QTSystem/;{PATH}" - }, - "LOGLEVEL": "DEBUG" + "NUKE_PATH": "{OPENPYPE_STUDIO_PLUGINS}/nuke" }, "variants": { "13-0": { @@ -224,15 +209,7 @@ "icon": "{}/app_icons/nuke.png", "host_name": "nuke", "environment": { - "NUKE_PATH": [ - "{OPENPYPE_REPOS_ROOT}/repos/avalon-core/setup/nuke/nuke_path", - "{OPENPYPE_REPOS_ROOT}/openpype/hosts/nuke/startup", - "{OPENPYPE_STUDIO_PLUGINS}/nuke" - ], - "PATH": { - "windows": "C:/Program Files (x86)/QuickTime/QTSystem/;{PATH}" - }, - "LOGLEVEL": "DEBUG" + "NUKE_PATH": "{OPENPYPE_STUDIO_PLUGINS}/nuke" }, "variants": { "13-0": { @@ -368,15 +345,8 @@ "icon": "{}/app_icons/nuke.png", "host_name": "hiero", "environment": { - "HIERO_PLUGIN_PATH": [ - "{OPENPYPE_REPOS_ROOT}/openpype/hosts/hiero/startup" - ], - "PATH": { - "windows": "C:/Program Files (x86)/QuickTime/QTSystem/;{PATH}" - }, "WORKFILES_STARTUP": "0", - "TAG_ASSETBUILD_STARTUP": "0", - "LOGLEVEL": "DEBUG" + "TAG_ASSETBUILD_STARTUP": "0" }, "variants": { "13-0": { @@ -510,15 +480,8 @@ "icon": "{}/app_icons/hiero.png", "host_name": "hiero", "environment": { - "HIERO_PLUGIN_PATH": [ - "{OPENPYPE_REPOS_ROOT}/openpype/hosts/hiero/startup" - ], - "PATH": { - "windows": "C:/Program Files (x86)/QuickTime/QTSystem/;{PATH}" - }, "WORKFILES_STARTUP": "0", - "TAG_ASSETBUILD_STARTUP": "0", - "LOGLEVEL": "DEBUG" + "TAG_ASSETBUILD_STARTUP": "0" }, "variants": { "13-0": { @@ -783,18 +746,7 @@ "label": "Houdini", "icon": "{}/app_icons/houdini.png", "host_name": "houdini", - "environment": { - "HOUDINI_PATH": { - "darwin": "{OPENPYPE_REPOS_ROOT}/openpype/hosts/houdini/startup:&", - "linux": "{OPENPYPE_REPOS_ROOT}/openpype/hosts/houdini/startup:&", - "windows": "{OPENPYPE_REPOS_ROOT}/openpype/hosts/houdini/startup;&" - }, - "HOUDINI_MENU_PATH": { - "darwin": "{OPENPYPE_REPOS_ROOT}/openpype/hosts/houdini/startup:&", - "linux": "{OPENPYPE_REPOS_ROOT}/openpype/hosts/houdini/startup:&", - "windows": "{OPENPYPE_REPOS_ROOT}/openpype/hosts/houdini/startup;&" - } - }, + "environment": {}, "variants": { "18-5": { "use_python_2": true, @@ -852,14 +804,7 @@ "label": "Blender", "icon": "{}/app_icons/blender.png", "host_name": "blender", - "environment": { - "BLENDER_USER_SCRIPTS": "{OPENPYPE_REPOS_ROOT}/repos/avalon-core/setup/blender", - "PYTHONPATH": [ - "{OPENPYPE_REPOS_ROOT}/repos/avalon-core/setup/blender", - "{PYTHONPATH}" - ], - "QT_PREFERRED_BINDING": "PySide2" - }, + "environment": {}, "variants": { "2-83": { "use_python_2": false, @@ -940,8 +885,7 @@ "icon": "{}/app_icons/harmony.png", "host_name": "harmony", "environment": { - "AVALON_HARMONY_WORKFILES_ON_LAUNCH": "1", - "LIB_OPENHARMONY_PATH": "{OPENPYPE_REPOS_ROOT}/pype/vendor/OpenHarmony" + "AVALON_HARMONY_WORKFILES_ON_LAUNCH": "1" }, "variants": { "20": { @@ -985,9 +929,7 @@ "label": "TVPaint", "icon": "{}/app_icons/tvpaint.png", "host_name": "tvpaint", - "environment": { - "OPENPYPE_LOG_NO_COLORS": "True" - }, + "environment": {}, "variants": { "animation_11-64bits": { "use_python_2": false, @@ -1034,8 +976,6 @@ "host_name": "photoshop", "environment": { "AVALON_PHOTOSHOP_WORKFILES_ON_LAUNCH": "1", - "OPENPYPE_LOG_NO_COLORS": "Yes", - "WEBSOCKET_URL": "ws://localhost:8099/ws/", "WORKFILES_SAVE_AS": "Yes" }, "variants": { @@ -1084,8 +1024,6 @@ "host_name": "aftereffects", "environment": { "AVALON_AFTEREFFECTS_WORKFILES_ON_LAUNCH": "1", - "OPENPYPE_LOG_NO_COLORS": "Yes", - "WEBSOCKET_URL": "ws://localhost:8097/ws/", "WORKFILES_SAVE_AS": "Yes" }, "variants": { @@ -1159,10 +1097,7 @@ "label": "Unreal Editor", "icon": "{}/app_icons/ue4.png'", "host_name": "unreal", - "environment": { - "AVALON_UNREAL_PLUGIN": "{OPENPYPE_REPOS_ROOT}/repos/avalon-unreal-integration", - "OPENPYPE_LOG_NO_COLORS": "True" - }, + "environment": {}, "variants": { "4-26": { "use_python_2": false,