mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
🎨 introduce name and id for representation
This commit is contained in:
parent
03dcc370e9
commit
2b572ae773
3 changed files with 26 additions and 7 deletions
|
|
@ -41,4 +41,4 @@ class TemplatePath(TraitBase):
|
|||
description: ClassVar[str] = "Template Path Trait Model"
|
||||
id: ClassVar[str] = "ayon.meta.TemplatePath.v1"
|
||||
template: str = Field(..., title="Template Path")
|
||||
data: dict[str] = Field(..., title="Formatting Data")
|
||||
data: dict = Field(..., title="Formatting Data")
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import inspect
|
||||
import sys
|
||||
import uuid
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import OrderedDict
|
||||
from functools import lru_cache
|
||||
|
|
@ -58,10 +59,16 @@ class Representation:
|
|||
It holds methods to add, remove, get, and check for the existence of a
|
||||
trait in the representation. It also provides a method to get all the
|
||||
|
||||
Arguments:
|
||||
name (str): Representation name. Must be unique within instance.
|
||||
representation_id (str): Representation ID.
|
||||
|
||||
"""
|
||||
_data: dict
|
||||
_module_blacklist: ClassVar[list[str]] = [
|
||||
"_", "builtins", "pydantic"]
|
||||
name: str
|
||||
representation_id: str
|
||||
|
||||
@lru_cache(maxsize=64) # noqa: B019
|
||||
def _get_trait_class(self, trait_id: str) -> Union[Type[TraitBase], None]:
|
||||
|
|
@ -343,8 +350,20 @@ class Representation:
|
|||
"""Return the length of the data."""
|
||||
return len(self._data)
|
||||
|
||||
def __init__(self, traits: Optional[list[TraitBase]]=None):
|
||||
"""Initialize the data."""
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
representation_id: Optional[str]=None,
|
||||
traits: Optional[list[TraitBase]]=None):
|
||||
"""Initialize the data.
|
||||
|
||||
Args:
|
||||
name (str): Representation name. Must be unique within instance.
|
||||
representation_id (str, optional): Representation ID.
|
||||
traits (list[TraitBase], optional): List of traits.
|
||||
"""
|
||||
self.name = name
|
||||
self.representation_id = representation_id or uuid.uuid4().hex
|
||||
self._data = {}
|
||||
if traits:
|
||||
for trait in traits:
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class InvalidTrait:
|
|||
@pytest.fixture()
|
||||
def representation() -> Representation:
|
||||
"""Return a traits data instance."""
|
||||
return Representation(traits=[
|
||||
return Representation(name="test", traits=[
|
||||
FileLocation(**REPRESENTATION_DATA[FileLocation.id]),
|
||||
Image(),
|
||||
PixelBased(**REPRESENTATION_DATA[PixelBased.id]),
|
||||
|
|
@ -111,7 +111,7 @@ def test_representation_traits(representation: Representation) -> None:
|
|||
repre_dict
|
||||
|
||||
assert representation.has_traits() is True
|
||||
empty_representation = Representation(traits=[])
|
||||
empty_representation = Representation(name="test", traits=[])
|
||||
assert empty_representation.has_traits() is False
|
||||
|
||||
assert representation.contains_trait(trait=FileLocation) is True
|
||||
|
|
@ -205,7 +205,7 @@ def test_bundles() -> None:
|
|||
MimeType(mime_type="image/tiff"),
|
||||
]
|
||||
bundle = Bundle(items=[diffuse_texture, bump_texture])
|
||||
representation = Representation(traits=[bundle])
|
||||
representation = Representation(name="test_bundle", traits=[bundle])
|
||||
|
||||
if representation.contains_trait(trait=Bundle):
|
||||
assert representation.get_trait(trait=Bundle).items == [
|
||||
|
|
@ -213,7 +213,7 @@ def test_bundles() -> None:
|
|||
]
|
||||
|
||||
for item in representation.get_trait(trait=Bundle).items:
|
||||
sub_representation = Representation(traits=item)
|
||||
sub_representation = Representation(name="test", traits=item)
|
||||
assert sub_representation.contains_trait(trait=Image)
|
||||
assert sub_representation.get_trait(trait=MimeType).mime_type in [
|
||||
"image/jpeg", "image/tiff"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue