From 122d80709c2f8db3ffbf0b7270ecd60b03d4bcc1 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Dec 2020 11:42:19 +0100 Subject: [PATCH] added prealunch hook that will add python 2 ftrack api modules to PYTHONPATH --- .../ftrack/launch_hooks/pre_python2_vendor.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 pype/modules/ftrack/launch_hooks/pre_python2_vendor.py diff --git a/pype/modules/ftrack/launch_hooks/pre_python2_vendor.py b/pype/modules/ftrack/launch_hooks/pre_python2_vendor.py new file mode 100644 index 0000000000..8e55e29763 --- /dev/null +++ b/pype/modules/ftrack/launch_hooks/pre_python2_vendor.py @@ -0,0 +1,27 @@ +import os +from pype.lib import PreLaunchHook +from pype.modules.ftrack import FTRACK_MODULE_DIR + + +class PrePyhton2Support(PreLaunchHook): + """Add python ftrack api module for Python 2 to PYTHONPATH. + + Path to vendor modules is added to the beggining of PYTHONPATH. + """ + # There will be needed more granular filtering in future + app_groups = ["maya", "nuke", "nukex", "hiero", "nukestudio"] + + def execute(self): + # Prepare dir path + python2_vendor = os.path.join(FTRACK_MODULE_DIR, "python2_vendor") + # Load PYTHONPATH from current launch context + python_path = self.launch_context.env.get("PYTHONPATH") + + # Just override if PYTHONPATH is not set yet + if not python_path: + python_path = python2_vendor + else: + python_path = os.pathsep.join([python2_vendor, python_path]) + + # Set new PYTHONPATH to launch context environments + self.launch_context.env["PYTHONPATH"] = python_path