Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Move workfile utils functions to workfile pipeline code #239

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 6 additions & 102 deletions client/ayon_core/lib/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -1811,15 +1815,15 @@ 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:
log.info("Opening of last workfile was disabled by user")

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
Expand Down Expand Up @@ -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.

Expand Down
8 changes: 8 additions & 0 deletions client/ayon_core/pipeline/workfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
create_workdir_extra_folders,
)

from .utils import (
should_use_last_workfile_on_launch,
should_open_workfiles_tool_on_launch,
)

from .build_workfile import BuildWorkfile


Expand All @@ -30,5 +35,8 @@

"create_workdir_extra_folders",

"should_use_last_workfile_on_launch",
"should_open_workfiles_tool_on_launch",

"BuildWorkfile",
)
121 changes: 121 additions & 0 deletions client/ayon_core/pipeline/workfile/utils.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions client/ayon_core/tools/launcher/models/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
discover_launcher_actions,
LauncherAction,
)
from ayon_core.pipeline.workfile import should_use_last_workfile_on_launch


# class Action:
Expand Down Expand Up @@ -301,8 +302,6 @@ def _should_start_last_workfile(
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]

Expand All @@ -315,7 +314,7 @@ def _should_start_last_workfile(
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,
Expand Down
Loading