ftrack module modify application launch environments in module instead of in prelaunch hook

This commit is contained in:
Jakub Trllo 2022-05-20 18:10:40 +02:00
parent c3e13a9e19
commit 6fc240734c
3 changed files with 36 additions and 45 deletions

View file

@ -450,14 +450,14 @@ class OpenPypeModule:
return {} return {}
def modify_application_launch_arguments(self, app, env): def modify_application_launch_arguments(self, application, env):
"""Give option to modify launch environments before application launch. """Give option to modify launch environments before application launch.
Implementation is optional. To change environments modify passed Implementation is optional. To change environments modify passed
dictionary of environments. dictionary of environments.
Args: Args:
app (Application): Application that is launcher. application (Application): Application that is launched.
env (dict): Current environemnt variables. env (dict): Current environemnt variables.
""" """

View file

@ -88,6 +88,40 @@ class FtrackModule(
"""Implementation of `ILaunchHookPaths`.""" """Implementation of `ILaunchHookPaths`."""
return os.path.join(FTRACK_MODULE_DIR, "launch_hooks") return os.path.join(FTRACK_MODULE_DIR, "launch_hooks")
def modify_application_launch_arguments(self, application, env):
if not application.use_python_2:
return
self.log.info("Adding Ftrack Python 2 packages to PYTHONPATH.")
# Prepare vendor dir path
python_2_vendor = os.path.join(FTRACK_MODULE_DIR, "python2_vendor")
# Add Python 2 modules
python_paths = [
# `python-ftrack-api`
os.path.join(python_2_vendor, "ftrack-python-api", "source"),
# `arrow`
os.path.join(python_2_vendor, "arrow"),
# `builtins` from `python-future`
# - `python-future` is strict Python 2 module that cause crashes
# of Python 3 scripts executed through OpenPype
# (burnin script etc.)
os.path.join(python_2_vendor, "builtins"),
# `backports.functools_lru_cache`
os.path.join(
python_2_vendor, "backports.functools_lru_cache"
)
]
# Load PYTHONPATH from current launch context
python_path = env.get("PYTHONPATH")
if python_path:
python_paths.append(python_path)
# Set new PYTHONPATH to launch context environments
env["PYTHONPATH"] = os.pathsep.join(python_paths)
def connect_with_modules(self, enabled_modules): def connect_with_modules(self, enabled_modules):
for module in enabled_modules: for module in enabled_modules:
if not hasattr(module, "get_ftrack_event_handler_paths"): if not hasattr(module, "get_ftrack_event_handler_paths"):

View file

@ -1,43 +0,0 @@
import os
from openpype.lib import PreLaunchHook
from openpype_modules.ftrack import FTRACK_MODULE_DIR
class PrePython2Support(PreLaunchHook):
"""Add python ftrack api module for Python 2 to PYTHONPATH.
Path to vendor modules is added to the beggining of PYTHONPATH.
"""
def execute(self):
if not self.application.use_python_2:
return
self.log.info("Adding Ftrack Python 2 packages to PYTHONPATH.")
# Prepare vendor dir path
python_2_vendor = os.path.join(FTRACK_MODULE_DIR, "python2_vendor")
# Add Python 2 modules
python_paths = [
# `python-ftrack-api`
os.path.join(python_2_vendor, "ftrack-python-api", "source"),
# `arrow`
os.path.join(python_2_vendor, "arrow"),
# `builtins` from `python-future`
# - `python-future` is strict Python 2 module that cause crashes
# of Python 3 scripts executed through OpenPype (burnin script etc.)
os.path.join(python_2_vendor, "builtins"),
# `backports.functools_lru_cache`
os.path.join(
python_2_vendor, "backports.functools_lru_cache"
)
]
# Load PYTHONPATH from current launch context
python_path = self.launch_context.env.get("PYTHONPATH")
if python_path:
python_paths.append(python_path)
# Set new PYTHONPATH to launch context environments
self.launch_context.env["PYTHONPATH"] = os.pathsep.join(python_paths)