Skip to content

Commit

Permalink
Merge pull request #1110 from ynput/enhancement/allow-transient-data-…
Browse files Browse the repository at this point in the history
…on-instnace-init

Create: Allow to pass in transient data on instance creation
  • Loading branch information
iLLiCiTiT authored Jan 29, 2025
2 parents 283465b + 5684c94 commit 34fbf68
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions client/ayon_core/pipeline/create/structures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import collections
from uuid import uuid4
import typing
from typing import Optional, Dict, List, Any

from ayon_core.lib.attribute_definitions import (
Expand All @@ -17,6 +18,9 @@
from .exceptions import ImmutableKeyError
from .changes import TrackChangesItem

if typing.TYPE_CHECKING:
from .creator_plugins import BaseCreator


class ConvertorItem:
"""Item representing convertor plugin.
Expand Down Expand Up @@ -444,10 +448,11 @@ class CreatedInstance:

def __init__(
self,
product_type,
product_name,
data,
creator,
product_type: str,
product_name: str,
data: Dict[str, Any],
creator: "BaseCreator",
transient_data: Optional[Dict[str, Any]] = None,
):
self._creator = creator
creator_identifier = creator.identifier
Expand All @@ -462,7 +467,9 @@ def __init__(
self._members = []

# Data that can be used for lifetime of object
self._transient_data = {}
if transient_data is None:
transient_data = {}
self._transient_data = transient_data

# Create a copy of passed data to avoid changing them on the fly
data = copy.deepcopy(data or {})
Expand Down Expand Up @@ -787,16 +794,26 @@ def set_create_attr_defs(self, attr_defs, value=None):
self._create_context.instance_create_attr_defs_changed(self.id)

@classmethod
def from_existing(cls, instance_data, creator):
def from_existing(
cls,
instance_data: Dict[str, Any],
creator: "BaseCreator",
transient_data: Optional[Dict[str, Any]] = None,
) -> "CreatedInstance":
"""Convert instance data from workfile to CreatedInstance.
Args:
instance_data (Dict[str, Any]): Data in a structure ready for
'CreatedInstance' object.
creator (BaseCreator): Creator plugin which is creating the
instance of for which the instance belong.
"""
instance of for which the instance belongs.
transient_data (Optional[dict[str, Any]]): Instance transient
data.
Returns:
CreatedInstance: Instance object.
"""
instance_data = copy.deepcopy(instance_data)

product_type = instance_data.get("productType")
Expand All @@ -809,7 +826,11 @@ def from_existing(cls, instance_data, creator):
product_name = instance_data.get("subset")

return cls(
product_type, product_name, instance_data, creator
product_type,
product_name,
instance_data,
creator,
transient_data=transient_data,
)

def attribute_value_changed(self, key, changes):
Expand Down

0 comments on commit 34fbf68

Please sign in to comment.