more usage of product type in create api

This commit is contained in:
Jakub Trllo 2024-02-21 17:31:33 +01:00
parent 3b2dc131f9
commit 88786d8160
3 changed files with 29 additions and 29 deletions

View file

@ -14,7 +14,7 @@ Except creating and removing instances are all changes not automatically propaga
## CreatedInstance
Product of creation is "instance" which holds basic data defying it. Core data are `creator_identifier`, `productType` and `productName`. Other data can be keys used to fill subset name or metadata modifying publishing process of the instance (more described later). All instances have `id` which holds constant `ayon.create.instance` or `pyblish.avalon.instance` (for backwards compatibility) and `instance_id` which is identifier of the instance.
Product of creation is "instance" which holds basic data defying it. Core data are `creator_identifier`, `productType` and `productName`. Other data can be keys used to fill product name or metadata modifying publishing process of the instance (more described later). All instances have `id` which holds constant `ayon.create.instance` or `pyblish.avalon.instance` (for backwards compatibility) and `instance_id` which is identifier of the instance.
Product type tells how should be instance processed and product name what name will published item have.
- There are cases when product name is not fully filled during creation and may change during publishing. That is in most of cases caused because instance is related to other instance or instance data do not represent final product.

View file

@ -866,7 +866,7 @@ class CreatedInstance:
creator.
Args:
family (str): Name of family that will be created.
product_type (str): Product type that will be created.
product_name (str): Name of product that will be created.
data (Dict[str, Any]): Data used for filling product name or override
data from already existing instance.
@ -885,7 +885,7 @@ class CreatedInstance:
__immutable_keys = (
"id",
"instance_id",
"family",
"product_type",
"creator_identifier",
"creator_attributes",
"publish_attributes"
@ -1436,7 +1436,7 @@ class CreateContext:
self.publish_plugins_mismatch_targets = []
self.publish_plugins = []
self.plugins_with_defs = []
self._attr_plugins_by_family = {}
self._attr_plugins_by_product_type = {}
# Helpers for validating context of collected instances
# - they can be validation for multiple instances at one time
@ -1745,7 +1745,7 @@ class CreateContext:
)
# Reset publish plugins
self._attr_plugins_by_family = {}
self._attr_plugins_by_product_type = {}
discover_result = DiscoverResult(pyblish.api.Plugin)
plugins_with_defs = []
@ -1917,8 +1917,8 @@ class CreateContext:
self._instances_by_id[instance.id] = instance
# Prepare publish plugin attributes and set it on instance
attr_plugins = self._get_publish_plugins_with_attr_for_family(
instance.family
attr_plugins = self._get_publish_plugins_with_attr_for_product_type(
instance.product_type
)
instance.set_publish_plugins(attr_plugins)
@ -2431,29 +2431,29 @@ class CreateContext:
if failed_info:
raise CreatorsRemoveFailed(failed_info)
def _get_publish_plugins_with_attr_for_family(self, family):
"""Publish plugin attributes for passed family.
def _get_publish_plugins_with_attr_for_product_type(self, product_type):
"""Publish plugin attributes for passed product type.
Attribute definitions for specific family are cached.
Attribute definitions for specific product type are cached.
Args:
family(str): Instance family for which should be attribute
definitions returned.
product_type(str): Instance product type for which should be
attribute definitions returned.
"""
if family not in self._attr_plugins_by_family:
if product_type not in self._attr_plugins_by_product_type:
import pyblish.logic
filtered_plugins = pyblish.logic.plugins_by_families(
self.plugins_with_defs, [family]
self.plugins_with_defs, [product_type]
)
plugins = []
for plugin in filtered_plugins:
if plugin.__instanceEnabled__:
plugins.append(plugin)
self._attr_plugins_by_family[family] = plugins
self._attr_plugins_by_product_type[product_type] = plugins
return self._attr_plugins_by_family[family]
return self._attr_plugins_by_product_type[product_type]
def _get_publish_plugins_with_attr_for_context(self):
"""Publish plugins attributes for Context plugins.

View file

@ -9,35 +9,35 @@ from .constants import DEFAULT_SUBSET_TEMPLATE
class TaskNotSetError(KeyError):
def __init__(self, msg=None):
if not msg:
msg = "Creator's subset name template requires task name."
msg = "Creator's product name template requires task name."
super(TaskNotSetError, self).__init__(msg)
class TemplateFillError(Exception):
def __init__(self, msg=None):
if not msg:
msg = "Creator's subset name template is missing key value."
msg = "Creator's product name template is missing key value."
super(TemplateFillError, self).__init__(msg)
def get_product_name_template(
project_name,
family,
product_type,
task_name,
task_type,
host_name,
default_template=None,
project_settings=None
):
"""Get subset name template based on passed context.
"""Get product name template based on passed context.
Args:
project_name (str): Project on which the context lives.
family (str): Family (subset type) for which the subset name is
product_type (str): Product type for which the subset name is
calculated.
host_name (str): Name of host in which the subset name is calculated.
task_name (str): Name of task in which context the subset is created.
task_type (str): Type of task in which context the subset is created.
host_name (str): Name of host in which the product name is calculated.
task_name (str): Name of task in which context the product is created.
task_type (str): Type of task in which context the product is created.
default_template (Union[str, None]): Default template which is used if
settings won't find any matching possitibility. Constant
'DEFAULT_SUBSET_TEMPLATE' is used if not defined.
@ -50,7 +50,7 @@ def get_product_name_template(
tools_settings = project_settings["core"]["tools"]
profiles = tools_settings["creator"]["product_name_profiles"]
filtering_criteria = {
"product_types": family,
"product_types": product_type,
"hosts": host_name,
"tasks": task_name,
"task_types": task_type
@ -94,7 +94,7 @@ def get_product_name(
"""Calculate product name based on passed context and AYON settings.
Subst name templates are defined in `project_settings/global/tools/creator
/product_name_profiles` where are profiles with host name, family,
/product_name_profiles` where are profiles with host name, product type,
task name and task type filters. If context does not match any profile
then `DEFAULT_SUBSET_TEMPLATE` is used as default template.
@ -120,12 +120,12 @@ def get_product_name(
a creator which creates instance.
project_settings (Optional[Union[Dict[str, Any]]]): Prepared settings
for project. Settings are queried if not passed.
family_filter (Optional[str]): Use different family for subset template
family_filter (Optional[str]): Use different family for product template
filtering. Value of 'family' is used when not passed.
Raises:
TemplateFillError: If filled template contains placeholder key which is not
collected.
TemplateFillError: If filled template contains placeholder key which
is not collected.
"""
if not product_type: