mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
modules have ability to modify environments before launch
This commit is contained in:
parent
13b4b18d16
commit
c3e13a9e19
2 changed files with 47 additions and 5 deletions
|
|
@ -1282,7 +1282,13 @@ class EnvironmentPrepData(dict):
|
|||
|
||||
|
||||
def get_app_environments_for_context(
|
||||
project_name, asset_name, task_name, app_name, env_group=None, env=None
|
||||
project_name,
|
||||
asset_name,
|
||||
task_name,
|
||||
app_name,
|
||||
env_group=None,
|
||||
env=None,
|
||||
modules_manager=None
|
||||
):
|
||||
"""Prepare environment variables by context.
|
||||
Args:
|
||||
|
|
@ -1293,10 +1299,12 @@ def get_app_environments_for_context(
|
|||
by ApplicationManager.
|
||||
env (dict): Initial environment variables. `os.environ` is used when
|
||||
not passed.
|
||||
modules_manager (ModulesManager): Initialized modules manager.
|
||||
|
||||
Returns:
|
||||
dict: Environments for passed context and application.
|
||||
"""
|
||||
|
||||
from openpype.pipeline import AvalonMongoDB
|
||||
|
||||
# Avalon database connection
|
||||
|
|
@ -1311,6 +1319,11 @@ def get_app_environments_for_context(
|
|||
"name": asset_name
|
||||
})
|
||||
|
||||
if modules_manager is None:
|
||||
from openpype.modules import ModulesManager
|
||||
|
||||
modules_manager = ModulesManager()
|
||||
|
||||
# Prepare app object which can be obtained only from ApplciationManager
|
||||
app_manager = ApplicationManager()
|
||||
app = app_manager.applications[app_name]
|
||||
|
|
@ -1334,7 +1347,7 @@ def get_app_environments_for_context(
|
|||
"env": env
|
||||
})
|
||||
|
||||
prepare_app_environments(data, env_group)
|
||||
prepare_app_environments(data, env_group, modules_manager)
|
||||
prepare_context_environments(data, env_group)
|
||||
|
||||
# Discard avalon connection
|
||||
|
|
@ -1355,9 +1368,12 @@ def _merge_env(env, current_env):
|
|||
return result
|
||||
|
||||
|
||||
def _add_python_version_paths(app, env, logger):
|
||||
def _add_python_version_paths(app, env, logger, modules_manager):
|
||||
"""Add vendor packages specific for a Python version."""
|
||||
|
||||
for module in modules_manager.get_enabled_modules():
|
||||
module.modify_application_launch_arguments(app, env)
|
||||
|
||||
# Skip adding if host name is not set
|
||||
if not app.host_name:
|
||||
return
|
||||
|
|
@ -1390,7 +1406,9 @@ def _add_python_version_paths(app, env, logger):
|
|||
env["PYTHONPATH"] = os.pathsep.join(python_paths)
|
||||
|
||||
|
||||
def prepare_app_environments(data, env_group=None, implementation_envs=True):
|
||||
def prepare_app_environments(
|
||||
data, env_group=None, implementation_envs=True, modules_manager=None
|
||||
):
|
||||
"""Modify launch environments based on launched app and context.
|
||||
|
||||
Args:
|
||||
|
|
@ -1403,7 +1421,12 @@ def prepare_app_environments(data, env_group=None, implementation_envs=True):
|
|||
log = data["log"]
|
||||
source_env = data["env"].copy()
|
||||
|
||||
_add_python_version_paths(app, source_env, log)
|
||||
if modules_manager is None:
|
||||
from openpype.modules import ModulesManager
|
||||
|
||||
modules_manager = ModulesManager()
|
||||
|
||||
_add_python_version_paths(app, source_env, log, modules_manager)
|
||||
|
||||
# Use environments from local settings
|
||||
filtered_local_envs = {}
|
||||
|
|
|
|||
|
|
@ -370,6 +370,7 @@ def _load_modules():
|
|||
|
||||
class _OpenPypeInterfaceMeta(ABCMeta):
|
||||
"""OpenPypeInterface meta class to print proper string."""
|
||||
|
||||
def __str__(self):
|
||||
return "<'OpenPypeInterface.{}'>".format(self.__name__)
|
||||
|
||||
|
|
@ -388,6 +389,7 @@ class OpenPypeInterface:
|
|||
OpenPype modules which means they have to have implemented methods defined
|
||||
in the interface. By default interface does not have any abstract parts.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -432,10 +434,12 @@ class OpenPypeModule:
|
|||
It is not recommended to override __init__ that's why specific method
|
||||
was implemented.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
def connect_with_modules(self, enabled_modules):
|
||||
"""Connect with other enabled modules."""
|
||||
|
||||
pass
|
||||
|
||||
def get_global_environments(self):
|
||||
|
|
@ -443,8 +447,22 @@ class OpenPypeModule:
|
|||
|
||||
Environment variables that can be get only from system settings.
|
||||
"""
|
||||
|
||||
return {}
|
||||
|
||||
def modify_application_launch_arguments(self, app, env):
|
||||
"""Give option to modify launch environments before application launch.
|
||||
|
||||
Implementation is optional. To change environments modify passed
|
||||
dictionary of environments.
|
||||
|
||||
Args:
|
||||
app (Application): Application that is launcher.
|
||||
env (dict): Current environemnt variables.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
def cli(self, module_click_group):
|
||||
"""Add commands to click group.
|
||||
|
||||
|
|
@ -465,6 +483,7 @@ class OpenPypeModule:
|
|||
def mycommand():
|
||||
print("my_command")
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue