diff --git a/openpype/hooks/pre_python_2_prelaunch.py b/openpype/hooks/pre_python_2_prelaunch.py deleted file mode 100644 index 84272d2e5d..0000000000 --- a/openpype/hooks/pre_python_2_prelaunch.py +++ /dev/null @@ -1,35 +0,0 @@ -import os -from openpype.lib import PreLaunchHook - - -class PrePython2Vendor(PreLaunchHook): - """Prepend python 2 dependencies for py2 hosts.""" - order = 10 - - def execute(self): - if not self.application.use_python_2: - return - - # Prepare vendor dir path - self.log.info("adding global python 2 vendor") - pype_root = os.getenv("OPENPYPE_REPOS_ROOT") - python_2_vendor = os.path.join( - pype_root, - "openpype", - "vendor", - "python", - "python_2" - ) - - # Add Python 2 modules - python_paths = [ - python_2_vendor - ] - - # 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) diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index e72585c75a..fcb5226606 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -1118,6 +1118,39 @@ class ApplicationLaunchContext: # Return process which is already terminated return process + def _add_python_version_paths(self): + """Add vendor packages specific for a Python version.""" + + # Skip adding if host name is not set + if not self.application.host_name: + return + + # Add Python 2/3 modules + openpype_root = os.getenv("OPENPYPE_REPOS_ROOT") + python_vendor_dir = os.path.join( + openpype_root, + "openpype", + "vendor", + "python" + ) + python_paths = [] + if self.application.use_python_2: + python_paths.append( + os.path.join(python_vendor_dir, "python_2") + ) + else: + python_paths.append( + os.path.join(python_vendor_dir, "python_3") + ) + + # Load PYTHONPATH from current launch context + python_path = self.env.get("PYTHONPATH") + if python_path: + python_paths.append(python_path) + + # Set new PYTHONPATH to launch context environments + self.env["PYTHONPATH"] = os.pathsep.join(python_paths) + def launch(self): """Collect data for new process and then create it. @@ -1130,6 +1163,8 @@ class ApplicationLaunchContext: self.log.warning("Application was already launched.") return + self._add_python_version_paths() + # Discover launch hooks self.discover_launch_hooks()