add python version specific vendors outside of launch hook

This commit is contained in:
Jakub Trllo 2022-03-24 09:42:18 +01:00
parent 0bfb3c3dfc
commit 70c317005c
2 changed files with 35 additions and 35 deletions

View file

@ -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)

View file

@ -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()