Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Publisher: Enhancement proposals #3897

Merged
merged 7 commits into from
Sep 26, 2022
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
2 changes: 2 additions & 0 deletions openpype/host/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .interfaces import (
IWorkfileHost,
ILoadHost,
IPublishHost,
INewPublisher,
)

Expand All @@ -16,6 +17,7 @@

"IWorkfileHost",
"ILoadHost",
"IPublishHost",
"INewPublisher",

"HostDirmap",
Expand Down
20 changes: 17 additions & 3 deletions openpype/host/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def has_unsaved_changes(self):
return self.workfile_has_unsaved_changes()


class INewPublisher:
class IPublishHost:
"""Functions related to new creation system in new publisher.

New publisher is not storing information only about each created instance
Expand All @@ -306,7 +306,7 @@ def get_missing_publish_methods(host):
workflow.
"""

if isinstance(host, INewPublisher):
if isinstance(host, IPublishHost):
return []

required = [
Expand All @@ -330,7 +330,7 @@ def validate_publish_methods(host):
MissingMethodsError: If there are missing methods on host
implementation.
"""
missing = INewPublisher.get_missing_publish_methods(host)
missing = IPublishHost.get_missing_publish_methods(host)
if missing:
raise MissingMethodsError(host, missing)

Expand Down Expand Up @@ -368,3 +368,17 @@ def update_context_data(self, data, changes):
"""

pass


class INewPublisher(IPublishHost):
"""Legacy interface replaced by 'IPublishHost'.

Deprecated:
'INewPublisher' is replaced by 'IPublishHost' please change your
imports.
There is no "reasonable" way hot mark these classes as deprecated
to show warning of wrong import. Deprecated since 3.14.* will be
removed in 3.15.*
"""

pass
4 changes: 2 additions & 2 deletions openpype/hosts/traypublisher/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
register_creator_plugin_path,
legacy_io,
)
from openpype.host import HostBase, INewPublisher
from openpype.host import HostBase, IPublishHost


ROOT_DIR = os.path.dirname(os.path.dirname(
Expand All @@ -19,7 +19,7 @@
CREATE_PATH = os.path.join(ROOT_DIR, "plugins", "create")


class TrayPublisherHost(HostBase, INewPublisher):
class TrayPublisherHost(HostBase, IPublishHost):
name = "traypublisher"

def install(self):
Expand Down
37 changes: 30 additions & 7 deletions openpype/pipeline/create/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from contextlib import contextmanager

from openpype.client import get_assets
from openpype.host import INewPublisher
from openpype.settings import (
get_system_settings,
get_project_settings
)
from openpype.host import IPublishHost
from openpype.pipeline import legacy_io
from openpype.pipeline.mongodb import (
AvalonMongoDB,
Expand All @@ -20,11 +24,6 @@
discover_creator_plugins,
)

from openpype.api import (
get_system_settings,
get_project_settings
)

UpdateData = collections.namedtuple("UpdateData", ["instance", "changes"])


Expand Down Expand Up @@ -402,8 +401,12 @@ def __init__(
self.creator = creator

# Instance members may have actions on them
# TODO implement members logic
self._members = []

# Data that can be used for lifetime of object
self._transient_data = {}

# Create a copy of passed data to avoid changing them on the fly
data = copy.deepcopy(data or {})
# Store original value of passed data
Expand Down Expand Up @@ -596,6 +599,26 @@ def data(self):

return self

@property
def transient_data(self):
"""Data stored for lifetime of instance object.

These data are not stored to scene and will be lost on object
deletion.

Can be used to store objects. In some host implementations is not
possible to reference to object in scene with some unique identifier
(e.g. node in Fusion.). In that case it is handy to store the object
here. Should be used that way only if instance data are stored on the
node itself.

Returns:
Dict[str, Any]: Dictionary object where you can store data related
to instance for lifetime of instance object.
"""

return self._transient_data

def changes(self):
"""Calculate and return changes."""

Expand Down Expand Up @@ -771,7 +794,7 @@ def get_host_misssing_methods(cls, host):
"""

missing = set(
INewPublisher.get_missing_publish_methods(host)
IPublishHost.get_missing_publish_methods(host)
)
return missing

Expand Down
7 changes: 7 additions & 0 deletions openpype/pipeline/create/creator_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ def __init__(
# - we may use UI inside processing this attribute should be checked
self.headless = headless

self.apply_settings(project_settings, system_settings)

def apply_settings(self, project_settings, system_settings):
"""Method called on initialization of plugin to apply settings."""

pass

@property
def identifier(self):
"""Identifier of creator (must be unique).
Expand Down
9 changes: 7 additions & 2 deletions openpype/plugins/publish/collect_from_create_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def process(self, context):
for created_instance in create_context.instances:
instance_data = created_instance.data_to_store()
if instance_data["active"]:
self.create_instance(context, instance_data)
self.create_instance(
context, instance_data, created_instance.transient_data
)

# Update global data to context
context.data.update(create_context.context_data_to_store())
Expand All @@ -37,7 +39,7 @@ def process(self, context):
legacy_io.Session[key] = value
os.environ[key] = value

def create_instance(self, context, in_data):
def create_instance(self, context, in_data, transient_data):
subset = in_data["subset"]
# If instance data already contain families then use it
instance_families = in_data.get("families") or []
Expand All @@ -56,5 +58,8 @@ def create_instance(self, context, in_data):
for key, value in in_data.items():
if key not in instance.data:
instance.data[key] = value

instance.data["transientData"] = transient_data

self.log.info("collected instance: {}".format(instance.data))
self.log.info("parsing data: {}".format(in_data))