mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
add python version specific vendors outside of launch hook
This commit is contained in:
parent
0bfb3c3dfc
commit
70c317005c
2 changed files with 35 additions and 35 deletions
|
|
@ -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)
|
||||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue