Merge pull request #239 from ynput/enhancement/workfiles-utils-in-workfiles-api

Chore: Move workfile utils functions to workfile pipeline code
This commit is contained in:
Jakub Trllo 2024-03-26 17:23:04 +01:00 committed by GitHub
commit 22107e6035
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 137 additions and 105 deletions

View file

@ -1789,6 +1789,10 @@ def _prepare_last_workfile(data, workdir, addons_manager):
from ayon_core.addon import AddonsManager
from ayon_core.pipeline import HOST_WORKFILE_EXTENSIONS
from ayon_core.pipeline.workfile import (
should_use_last_workfile_on_launch,
should_open_workfiles_tool_on_launch,
)
if not addons_manager:
addons_manager = AddonsManager()
@ -1811,7 +1815,7 @@ def _prepare_last_workfile(data, workdir, addons_manager):
start_last_workfile = data.get("start_last_workfile")
if start_last_workfile is None:
start_last_workfile = should_start_last_workfile(
start_last_workfile = should_use_last_workfile_on_launch(
project_name, app.host_name, task_name, task_type
)
else:
@ -1819,7 +1823,7 @@ def _prepare_last_workfile(data, workdir, addons_manager):
data["start_last_workfile"] = start_last_workfile
workfile_startup = should_workfile_tool_start(
workfile_startup = should_open_workfiles_tool_on_launch(
project_name, app.host_name, task_name, task_type
)
data["workfile_startup"] = workfile_startup
@ -1889,106 +1893,6 @@ def _prepare_last_workfile(data, workdir, addons_manager):
data["last_workfile_path"] = last_workfile_path
def should_start_last_workfile(
project_name, host_name, task_name, task_type, default_output=False
):
"""Define if host should start last version workfile if possible.
Default output is `False`. Can be overridden with environment variable
`AYON_OPEN_LAST_WORKFILE`, valid values without case sensitivity are
`"0", "1", "true", "false", "yes", "no"`.
Args:
project_name (str): Project name.
host_name (str): Host name.
task_name (str): Task name.
task_type (str): Task type.
default_output (Optional[bool]): Default output if no profile is
found.
Returns:
bool: True if host should start workfile.
"""
project_settings = get_project_settings(project_name)
profiles = (
project_settings
["core"]
["tools"]
["Workfiles"]
["last_workfile_on_startup"]
)
if not profiles:
return default_output
filter_data = {
"tasks": task_name,
"task_types": task_type,
"hosts": host_name
}
matching_item = filter_profiles(profiles, filter_data)
output = None
if matching_item:
output = matching_item.get("enabled")
if output is None:
return default_output
return output
def should_workfile_tool_start(
project_name, host_name, task_name, task_type, default_output=False
):
"""Define if host should start workfile tool at host launch.
Default output is `False`. Can be overridden with environment variable
`AYON_WORKFILE_TOOL_ON_START`, valid values without case sensitivity are
`"0", "1", "true", "false", "yes", "no"`.
Args:
project_name (str): Project name.
host_name (str): Host name.
task_name (str): Task name.
task_type (str): Task type.
default_output (Optional[bool]): Default output if no profile is
found.
Returns:
bool: True if host should start workfile.
"""
project_settings = get_project_settings(project_name)
profiles = (
project_settings
["core"]
["tools"]
["Workfiles"]
["open_workfile_tool_on_startup"]
)
if not profiles:
return default_output
filter_data = {
"tasks": task_name,
"task_types": task_type,
"hosts": host_name
}
matching_item = filter_profiles(profiles, filter_data)
output = None
if matching_item:
output = matching_item.get("enabled")
if output is None:
return default_output
return output
def get_non_python_host_kwargs(kwargs, allow_console=True):
"""Explicit setting of kwargs for Popen for AE/PS/Harmony.

View file

@ -13,6 +13,11 @@ from .path_resolving import (
create_workdir_extra_folders,
)
from .utils import (
should_use_last_workfile_on_launch,
should_open_workfiles_tool_on_launch,
)
from .build_workfile import BuildWorkfile
@ -30,5 +35,8 @@ __all__ = (
"create_workdir_extra_folders",
"should_use_last_workfile_on_launch",
"should_open_workfiles_tool_on_launch",
"BuildWorkfile",
)

View file

@ -0,0 +1,121 @@
from ayon_core.lib import filter_profiles
from ayon_core.settings import get_project_settings
def should_use_last_workfile_on_launch(
project_name,
host_name,
task_name,
task_type,
default_output=False,
project_settings=None,
):
"""Define if host should start last version workfile if possible.
Default output is `False`. Can be overridden with environment variable
`AYON_OPEN_LAST_WORKFILE`, valid values without case sensitivity are
`"0", "1", "true", "false", "yes", "no"`.
Args:
project_name (str): Name of project.
host_name (str): Name of host which is launched. In avalon's
application context it's value stored in app definition under
key `"application_dir"`. Is not case sensitive.
task_name (str): Name of task which is used for launching the host.
Task name is not case sensitive.
task_type (str): Task type.
default_output (Optional[bool]): Default output value if no profile
is found.
project_settings (Optional[dict[str, Any]]): Project settings.
Returns:
bool: True if host should start workfile.
"""
if project_settings is None:
project_settings = get_project_settings(project_name)
profiles = (
project_settings
["core"]
["tools"]
["Workfiles"]
["last_workfile_on_startup"]
)
if not profiles:
return default_output
filter_data = {
"tasks": task_name,
"task_types": task_type,
"hosts": host_name
}
matching_item = filter_profiles(profiles, filter_data)
output = None
if matching_item:
output = matching_item.get("enabled")
if output is None:
return default_output
return output
def should_open_workfiles_tool_on_launch(
project_name,
host_name,
task_name,
task_type,
default_output=False,
project_settings=None,
):
"""Define if host should start workfile tool at host launch.
Default output is `False`. Can be overridden with environment variable
`AYON_WORKFILE_TOOL_ON_START`, valid values without case sensitivity are
`"0", "1", "true", "false", "yes", "no"`.
Args:
project_name (str): Name of project.
host_name (str): Name of host which is launched. In avalon's
application context it's value stored in app definition under
key `"application_dir"`. Is not case sensitive.
task_name (str): Name of task which is used for launching the host.
Task name is not case sensitive.
task_type (str): Task type.
default_output (Optional[bool]): Default output value if no profile
is found.
project_settings (Optional[dict[str, Any]]): Project settings.
Returns:
bool: True if host should start workfile.
"""
if project_settings is None:
project_settings = get_project_settings(project_name)
profiles = (
project_settings
["core"]
["tools"]
["Workfiles"]
["open_workfile_tool_on_startup"]
)
if not profiles:
return default_output
filter_data = {
"tasks": task_name,
"task_types": task_type,
"hosts": host_name
}
matching_item = filter_profiles(profiles, filter_data)
output = None
if matching_item:
output = matching_item.get("enabled")
if output is None:
return default_output
return output

View file

@ -6,6 +6,7 @@ from ayon_core.pipeline.actions import (
discover_launcher_actions,
LauncherAction,
)
from ayon_core.pipeline.workfile import should_use_last_workfile_on_launch
# class Action:
@ -301,8 +302,6 @@ class ActionsModel:
host_name,
not_open_workfile_actions
):
from ayon_core.lib.applications import should_start_last_workfile
if identifier in not_open_workfile_actions:
return not not_open_workfile_actions[identifier]
@ -315,7 +314,7 @@ class ActionsModel:
task_name = task_entity["name"]
task_type = task_entity["taskType"]
output = should_start_last_workfile(
output = should_use_last_workfile_on_launch(
project_name,
host_name,
task_name,