Skip to content

Commit

Permalink
Merge pull request #759 from ynput/feature/AY-2480_tokens-unify-the-l…
Browse files Browse the repository at this point in the history
…ogic-of-anatomy-and-subset-profiles

Product name: Support task short name
  • Loading branch information
iLLiCiTiT authored Jul 9, 2024
2 parents 142d875 + a15b613 commit 6cc5132
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 9 deletions.
30 changes: 29 additions & 1 deletion client/ayon_core/pipeline/create/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ayon_api

from ayon_core.settings import get_project_settings
from ayon_core.lib import is_func_signature_supported
from ayon_core.lib.attribute_definitions import (
UnknownDef,
serialize_attr_defs,
Expand Down Expand Up @@ -1404,6 +1405,7 @@ def __init__(
self._current_workfile_path = None
self._current_project_settings = None

self._current_project_entity = _NOT_SET
self._current_folder_entity = _NOT_SET
self._current_task_entity = _NOT_SET
self._current_task_type = _NOT_SET
Expand Down Expand Up @@ -1592,6 +1594,22 @@ def get_current_task_type(self):
self._current_task_type = task_type
return self._current_task_type

def get_current_project_entity(self):
"""Project entity for current context project.
Returns:
Union[dict[str, Any], None]: Folder entity.
"""
if self._current_project_entity is not _NOT_SET:
return copy.deepcopy(self._current_project_entity)
project_entity = None
project_name = self.get_current_project_name()
if project_name:
project_entity = ayon_api.get_project(project_name)
self._current_project_entity = project_entity
return copy.deepcopy(self._current_project_entity)

def get_current_folder_entity(self):
"""Folder entity for current context folder.
Expand Down Expand Up @@ -1788,6 +1806,7 @@ def reset_current_context(self):
self._current_task_name = task_name
self._current_workfile_path = workfile_path

self._current_project_entity = _NOT_SET
self._current_folder_entity = _NOT_SET
self._current_task_entity = _NOT_SET
self._current_task_type = _NOT_SET
Expand Down Expand Up @@ -2083,13 +2102,22 @@ def create(
# TODO validate types
_pre_create_data.update(pre_create_data)

product_name = creator.get_product_name(
project_entity = self.get_current_project_entity()
args = (
project_name,
folder_entity,
task_entity,
variant,
self.host_name,
)
kwargs = {"project_entity": project_entity}
# Backwards compatibility for 'project_entity' argument
# - 'get_product_name' signature changed 24/07/08
if not is_func_signature_supported(
creator.get_product_name, *args, **kwargs
):
kwargs.pop("project_entity")
product_name = creator.get_product_name(*args, **kwargs)

instance_data = {
"folderPath": folder_entity["path"],
Expand Down
10 changes: 6 additions & 4 deletions client/ayon_core/pipeline/create/creator_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ def apply_settings(self, project_settings):
))
setattr(self, key, value)


@property
def identifier(self):
"""Identifier of creator (must be unique).
Expand Down Expand Up @@ -493,7 +492,8 @@ def get_product_name(
task_entity,
variant,
host_name=None,
instance=None
instance=None,
project_entity=None,
):
"""Return product name for passed context.
Expand All @@ -510,8 +510,9 @@ def get_product_name(
instance (Optional[CreatedInstance]): Object of 'CreatedInstance'
for which is product name updated. Passed only on product name
update.
"""
project_entity (Optional[dict[str, Any]]): Project entity.
"""
if host_name is None:
host_name = self.create_context.host_name

Expand All @@ -537,7 +538,8 @@ def get_product_name(
self.product_type,
variant,
dynamic_data=dynamic_data,
project_settings=self.project_settings
project_settings=self.project_settings,
project_entity=project_entity,
)

def get_instance_attr_defs(self):
Expand Down
21 changes: 20 additions & 1 deletion client/ayon_core/pipeline/create/product_name.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ayon_api

from ayon_core.settings import get_project_settings
from ayon_core.lib import filter_profiles, prepare_template_data

Expand Down Expand Up @@ -88,6 +90,7 @@ def get_product_name(
dynamic_data=None,
project_settings=None,
product_type_filter=None,
project_entity=None,
):
"""Calculate product name based on passed context and AYON settings.
Expand Down Expand Up @@ -120,12 +123,18 @@ def get_product_name(
product_type_filter (Optional[str]): Use different product type for
product template filtering. Value of `product_type` is used when
not passed.
project_entity (Optional[Dict[str, Any]]): Project entity used when
task short name is required by template.
Returns:
str: Product name.
Raises:
TaskNotSetError: If template requires task which is not provided.
TemplateFillError: If filled template contains placeholder key which
is not collected.
"""
"""
if not product_type:
return ""

Expand All @@ -150,6 +159,16 @@ def get_product_name(
if "{task}" in template.lower():
task_value = task_name

elif "{task[short]}" in template.lower():
if project_entity is None:
project_entity = ayon_api.get_project(project_name)
task_types_by_name = {
task["name"]: task for task in
project_entity["taskTypes"]
}
task_short = task_types_by_name.get(task_type, {}).get("shortName")
task_value["short"] = task_short

fill_pairs = {
"variant": variant,
"family": product_type,
Expand Down
6 changes: 6 additions & 0 deletions client/ayon_core/tools/publisher/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ def get_task_item_by_name(
) -> Union[TaskItem, None]:
pass

@abstractmethod
def get_project_entity(
self, project_name: str
) -> Union[Dict[str, Any], None]:
pass

@abstractmethod
def get_folder_entity(
self, project_name: str, folder_id: str
Expand Down
3 changes: 3 additions & 0 deletions client/ayon_core/tools/publisher/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def get_instances_by_id(self, instance_ids=None):
def get_convertor_items(self):
return self._create_model.get_convertor_items()

def get_project_entity(self, project_name):
return self._projects_model.get_project_entity(project_name)

def get_folder_type_items(self, project_name, sender=None):
return self._projects_model.get_folder_type_items(
project_name, sender
Expand Down
19 changes: 16 additions & 3 deletions client/ayon_core/tools/publisher/models/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
from ayon_core.lib.profiles_filtering import filter_profiles
from ayon_core.lib.attribute_definitions import UIDef
from ayon_core.lib import is_func_signature_supported
from ayon_core.pipeline.create import (
BaseCreator,
AutoCreator,
Expand All @@ -26,6 +27,7 @@
AbstractPublisherBackend,
CardMessageTypes,
)

CREATE_EVENT_SOURCE = "publisher.create.model"


Expand Down Expand Up @@ -356,13 +358,24 @@ def get_product_name(
project_name, task_item.task_id
)

return creator.get_product_name(
project_entity = self._controller.get_project_entity(project_name)
args = (
project_name,
folder_entity,
task_entity,
variant,
instance=instance
variant
)
kwargs = {
"instance": instance,
"project_entity": project_entity,
}
# Backwards compatibility for 'project_entity' argument
# - 'get_product_name' signature changed 24/07/08
if not is_func_signature_supported(
creator.get_product_name, *args, **kwargs
):
kwargs.pop("project_entity")
return creator.get_product_name(*args, **kwargs)

def create(
self,
Expand Down

0 comments on commit 6cc5132

Please sign in to comment.