mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
Merge pull request #3594 from pypeclub/feature/OP-2840_Missing-context-on-publish-instances
General: Add context to pyblish context
This commit is contained in:
commit
31b4a9dc05
12 changed files with 101 additions and 54 deletions
|
|
@ -5,7 +5,6 @@ from maya import cmds
|
|||
|
||||
from openpype.pipeline import legacy_io, PublishXmlValidationError
|
||||
from openpype.settings import get_project_settings
|
||||
import openpype.api
|
||||
|
||||
import pyblish.api
|
||||
|
||||
|
|
@ -34,7 +33,9 @@ class MayaSubmitRemotePublishDeadline(pyblish.api.InstancePlugin):
|
|||
targets = ["local"]
|
||||
|
||||
def process(self, instance):
|
||||
settings = get_project_settings(os.getenv("AVALON_PROJECT"))
|
||||
project_name = instance.context.data["projectName"]
|
||||
# TODO settings can be received from 'context.data["project_settings"]'
|
||||
settings = get_project_settings(project_name)
|
||||
# use setting for publish job on farm, no reason to have it separately
|
||||
deadline_publish_job_sett = (settings["deadline"]
|
||||
["publish"]
|
||||
|
|
@ -53,9 +54,6 @@ class MayaSubmitRemotePublishDeadline(pyblish.api.InstancePlugin):
|
|||
scene = instance.context.data["currentFile"]
|
||||
scenename = os.path.basename(scene)
|
||||
|
||||
# Get project code
|
||||
project_name = legacy_io.Session["AVALON_PROJECT"]
|
||||
|
||||
job_name = "{scene} [PUBLISH]".format(scene=scenename)
|
||||
batch_name = "{code} - {scene}".format(code=project_name,
|
||||
scene=scenename)
|
||||
|
|
@ -107,8 +105,8 @@ class MayaSubmitRemotePublishDeadline(pyblish.api.InstancePlugin):
|
|||
environment = dict({key: os.environ[key] for key in keys
|
||||
if key in os.environ}, **legacy_io.Session)
|
||||
|
||||
# TODO replace legacy_io with context.data ?
|
||||
environment["AVALON_PROJECT"] = legacy_io.Session["AVALON_PROJECT"]
|
||||
# TODO replace legacy_io with context.data
|
||||
environment["AVALON_PROJECT"] = project_name
|
||||
environment["AVALON_ASSET"] = legacy_io.Session["AVALON_ASSET"]
|
||||
environment["AVALON_TASK"] = legacy_io.Session["AVALON_TASK"]
|
||||
environment["AVALON_APP_NAME"] = os.environ.get("AVALON_APP_NAME")
|
||||
|
|
|
|||
|
|
@ -1,29 +1,32 @@
|
|||
"""Collect Anatomy object.
|
||||
|
||||
Requires:
|
||||
os.environ -> AVALON_PROJECT
|
||||
context -> projectName
|
||||
|
||||
Provides:
|
||||
context -> anatomy (openpype.pipeline.anatomy.Anatomy)
|
||||
"""
|
||||
import os
|
||||
|
||||
import pyblish.api
|
||||
from openpype.pipeline import Anatomy
|
||||
from openpype.pipeline import Anatomy, KnownPublishError
|
||||
|
||||
|
||||
class CollectAnatomyObject(pyblish.api.ContextPlugin):
|
||||
"""Collect Anatomy object into Context"""
|
||||
"""Collect Anatomy object into Context.
|
||||
|
||||
Order offset could be changed to '-0.45'.
|
||||
"""
|
||||
|
||||
order = pyblish.api.CollectorOrder - 0.4
|
||||
label = "Collect Anatomy Object"
|
||||
|
||||
def process(self, context):
|
||||
project_name = os.environ.get("AVALON_PROJECT")
|
||||
project_name = context.data.get("projectName")
|
||||
if project_name is None:
|
||||
raise AssertionError(
|
||||
"Environment `AVALON_PROJECT` is not set."
|
||||
raise KnownPublishError((
|
||||
"Project name is not set in 'projectName'."
|
||||
"Could not initialize project's Anatomy."
|
||||
)
|
||||
))
|
||||
|
||||
context.data["anatomy"] = Anatomy(project_name)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,35 +1,38 @@
|
|||
"""Collect Anatomy and global anatomy data.
|
||||
|
||||
Requires:
|
||||
session -> AVALON_PROJECT, AVALON_ASSET
|
||||
session -> AVALON_ASSET
|
||||
context -> projectName
|
||||
|
||||
Provides:
|
||||
context -> projectEntity - project entity from database
|
||||
context -> assetEntity - asset entity from database
|
||||
context -> projectEntity - Project document from database.
|
||||
context -> assetEntity - Asset document from database only if 'asset' is
|
||||
set in context.
|
||||
"""
|
||||
|
||||
import pyblish.api
|
||||
|
||||
from openpype.client import get_project, get_asset_by_name
|
||||
from openpype.pipeline import legacy_io
|
||||
from openpype.pipeline import legacy_io, KnownPublishError
|
||||
|
||||
|
||||
class CollectAvalonEntities(pyblish.api.ContextPlugin):
|
||||
"""Collect Anatomy into Context"""
|
||||
"""Collect Anatomy into Context."""
|
||||
|
||||
order = pyblish.api.CollectorOrder - 0.1
|
||||
label = "Collect Avalon Entities"
|
||||
|
||||
def process(self, context):
|
||||
legacy_io.install()
|
||||
project_name = legacy_io.Session["AVALON_PROJECT"]
|
||||
project_name = context.data["projectName"]
|
||||
asset_name = legacy_io.Session["AVALON_ASSET"]
|
||||
task_name = legacy_io.Session["AVALON_TASK"]
|
||||
|
||||
project_entity = get_project(project_name)
|
||||
assert project_entity, (
|
||||
"Project '{0}' was not found."
|
||||
).format(project_name)
|
||||
if not project_entity:
|
||||
raise KnownPublishError(
|
||||
"Project '{0}' was not found.".format(project_name)
|
||||
)
|
||||
self.log.debug("Collected Project \"{}\"".format(project_entity))
|
||||
|
||||
context.data["projectEntity"] = project_entity
|
||||
|
|
|
|||
47
openpype/plugins/publish/collect_current_context.py
Normal file
47
openpype/plugins/publish/collect_current_context.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
"""
|
||||
Provides:
|
||||
context -> projectName (str)
|
||||
context -> asset (str)
|
||||
context -> task (str)
|
||||
"""
|
||||
|
||||
import pyblish.api
|
||||
from openpype.pipeline import legacy_io
|
||||
|
||||
|
||||
class CollectCurrentContext(pyblish.api.ContextPlugin):
|
||||
"""Collect project context into publish context data.
|
||||
|
||||
Plugin does not override any value if is already set.
|
||||
"""
|
||||
|
||||
order = pyblish.api.CollectorOrder - 0.5
|
||||
label = "Collect Current context"
|
||||
|
||||
def process(self, context):
|
||||
# Make sure 'legacy_io' is intalled
|
||||
legacy_io.install()
|
||||
|
||||
# Check if values are already set
|
||||
project_name = context.data.get("projectName")
|
||||
asset_name = context.data.get("asset")
|
||||
task_name = context.data.get("task")
|
||||
if not project_name:
|
||||
project_name = legacy_io.current_project()
|
||||
context.data["projectName"] = project_name
|
||||
|
||||
if not asset_name:
|
||||
asset_name = legacy_io.Session.get("AVALON_ASSET")
|
||||
context.data["asset"] = asset_name
|
||||
|
||||
if not task_name:
|
||||
task_name = legacy_io.Session.get("AVALON_TASK")
|
||||
context.data["task"] = task_name
|
||||
|
||||
# QUESTION should we be explicit with keys? (the same on instances)
|
||||
# - 'asset' -> 'assetName'
|
||||
# - 'task' -> 'taskName'
|
||||
|
||||
self.log.info((
|
||||
"Collected project context\nProject: {}\nAsset: {}\nTask: {}"
|
||||
).format(project_name, asset_name, task_name))
|
||||
|
|
@ -9,7 +9,7 @@ from openpype.lib.dateutils import get_datetime_data
|
|||
|
||||
|
||||
class CollectDateTimeData(pyblish.api.ContextPlugin):
|
||||
order = pyblish.api.CollectorOrder
|
||||
order = pyblish.api.CollectorOrder - 0.5
|
||||
label = "Collect DateTime data"
|
||||
|
||||
def process(self, context):
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ class CollectFromCreateContext(pyblish.api.ContextPlugin):
|
|||
if not create_context:
|
||||
return
|
||||
|
||||
project_name = create_context.project_name
|
||||
if project_name:
|
||||
context.data["projectName"] = project_name
|
||||
for created_instance in create_context.instances:
|
||||
instance_data = created_instance.data_to_store()
|
||||
if instance_data["active"]:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import pyblish.api
|
||||
|
||||
from openpype.pipeline import legacy_io
|
||||
|
||||
|
||||
class CollectHierarchy(pyblish.api.ContextPlugin):
|
||||
"""Collecting hierarchy from `parents`.
|
||||
|
|
@ -20,7 +18,7 @@ class CollectHierarchy(pyblish.api.ContextPlugin):
|
|||
|
||||
def process(self, context):
|
||||
temp_context = {}
|
||||
project_name = legacy_io.Session["AVALON_PROJECT"]
|
||||
project_name = context.data["projectName"]
|
||||
final_context = {}
|
||||
final_context[project_name] = {}
|
||||
final_context[project_name]['entity_type'] = 'Project'
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import pyblish.api
|
|||
|
||||
class CollectMachineName(pyblish.api.ContextPlugin):
|
||||
label = "Local Machine Name"
|
||||
order = pyblish.api.CollectorOrder
|
||||
order = pyblish.api.CollectorOrder - 0.5
|
||||
hosts = ["*"]
|
||||
|
||||
def process(self, context):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""Loads publishing context from json and continues in publish process.
|
||||
|
||||
Requires:
|
||||
anatomy -> context["anatomy"] *(pyblish.api.CollectorOrder - 0.11)
|
||||
anatomy -> context["anatomy"] *(pyblish.api.CollectorOrder - 0.4)
|
||||
|
||||
Provides:
|
||||
context, instances -> All data from previous publishing process.
|
||||
|
|
@ -12,7 +12,7 @@ import json
|
|||
|
||||
import pyblish.api
|
||||
|
||||
from openpype.pipeline import legacy_io
|
||||
from openpype.pipeline import legacy_io, KnownPublishError
|
||||
|
||||
|
||||
class CollectRenderedFiles(pyblish.api.ContextPlugin):
|
||||
|
|
@ -20,7 +20,12 @@ class CollectRenderedFiles(pyblish.api.ContextPlugin):
|
|||
This collector will try to find json files in provided
|
||||
`OPENPYPE_PUBLISH_DATA`. Those files _MUST_ share same context.
|
||||
|
||||
Note:
|
||||
We should split this collector and move the part which handle reading
|
||||
of file and it's context from session data before collect anatomy
|
||||
and instance creation dependent on anatomy can be done here.
|
||||
"""
|
||||
|
||||
order = pyblish.api.CollectorOrder - 0.2
|
||||
# Keep "filesequence" for backwards compatibility of older jobs
|
||||
targets = ["filesequence", "farm"]
|
||||
|
|
@ -118,23 +123,20 @@ class CollectRenderedFiles(pyblish.api.ContextPlugin):
|
|||
def process(self, context):
|
||||
self._context = context
|
||||
|
||||
assert os.environ.get("OPENPYPE_PUBLISH_DATA"), (
|
||||
"Missing `OPENPYPE_PUBLISH_DATA`")
|
||||
if not os.environ.get("OPENPYPE_PUBLISH_DATA"):
|
||||
raise KnownPublishError("Missing `OPENPYPE_PUBLISH_DATA`")
|
||||
|
||||
# QUESTION
|
||||
# Do we support (or want support) multiple files in the variable?
|
||||
# - what if they have different context?
|
||||
paths = os.environ["OPENPYPE_PUBLISH_DATA"].split(os.pathsep)
|
||||
|
||||
project_name = os.environ.get("AVALON_PROJECT")
|
||||
if project_name is None:
|
||||
raise AssertionError(
|
||||
"Environment `AVALON_PROJECT` was not found."
|
||||
"Could not set project `root` which may cause issues."
|
||||
)
|
||||
|
||||
# TODO root filling should happen after collect Anatomy
|
||||
# Using already collected Anatomy
|
||||
anatomy = context.data["anatomy"]
|
||||
self.log.info("Getting root setting for project \"{}\"".format(
|
||||
project_name
|
||||
anatomy.project_name
|
||||
))
|
||||
|
||||
anatomy = context.data["anatomy"]
|
||||
self.log.info("anatomy: {}".format(anatomy.roots))
|
||||
try:
|
||||
session_is_set = False
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ import copy
|
|||
|
||||
import pyblish.api
|
||||
|
||||
from openpype.pipeline import legacy_io
|
||||
|
||||
|
||||
class CollectResourcesPath(pyblish.api.InstancePlugin):
|
||||
"""Generate directory path where the files and resources will be stored"""
|
||||
|
|
@ -58,7 +56,6 @@ class CollectResourcesPath(pyblish.api.InstancePlugin):
|
|||
"effect",
|
||||
"staticMesh",
|
||||
"skeletalMesh"
|
||||
|
||||
]
|
||||
|
||||
def process(self, instance):
|
||||
|
|
@ -86,11 +83,10 @@ class CollectResourcesPath(pyblish.api.InstancePlugin):
|
|||
else:
|
||||
# solve deprecated situation when `folder` key is not underneath
|
||||
# `publish` anatomy
|
||||
project_name = legacy_io.Session["AVALON_PROJECT"]
|
||||
self.log.warning((
|
||||
"Deprecation warning: Anatomy does not have set `folder`"
|
||||
" key underneath `publish` (in global of for project `{}`)."
|
||||
).format(project_name))
|
||||
).format(anatomy.project_name))
|
||||
|
||||
file_path = anatomy_filled["publish"]["path"]
|
||||
# Directory
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class IntegrateHeroVersion(pyblish.api.InstancePlugin):
|
|||
template_key = self._get_template_key(instance)
|
||||
|
||||
anatomy = instance.context.data["anatomy"]
|
||||
project_name = legacy_io.Session["AVALON_PROJECT"]
|
||||
project_name = anatomy.project_name
|
||||
if template_key not in anatomy.templates:
|
||||
self.log.warning((
|
||||
"!!! Anatomy of project \"{}\" does not have set"
|
||||
|
|
@ -454,7 +454,6 @@ class IntegrateHeroVersion(pyblish.api.InstancePlugin):
|
|||
)
|
||||
|
||||
if bulk_writes:
|
||||
project_name = legacy_io.Session["AVALON_PROJECT"]
|
||||
legacy_io.database[project_name].bulk_write(
|
||||
bulk_writes
|
||||
)
|
||||
|
|
@ -517,11 +516,10 @@ class IntegrateHeroVersion(pyblish.api.InstancePlugin):
|
|||
anatomy_filled = anatomy.format(template_data)
|
||||
# solve deprecated situation when `folder` key is not underneath
|
||||
# `publish` anatomy
|
||||
project_name = legacy_io.Session["AVALON_PROJECT"]
|
||||
self.log.warning((
|
||||
"Deprecation warning: Anatomy does not have set `folder`"
|
||||
" key underneath `publish` (in global of for project `{}`)."
|
||||
).format(project_name))
|
||||
).format(anatomy.project_name))
|
||||
|
||||
file_path = anatomy_filled[template_key]["path"]
|
||||
# Directory
|
||||
|
|
|
|||
|
|
@ -39,9 +39,8 @@ class IntegrateThumbnails(pyblish.api.InstancePlugin):
|
|||
)
|
||||
return
|
||||
|
||||
project_name = legacy_io.Session["AVALON_PROJECT"]
|
||||
|
||||
anatomy = instance.context.data["anatomy"]
|
||||
project_name = anatomy.project_name
|
||||
if "publish" not in anatomy.templates:
|
||||
self.log.warning("Anatomy is missing the \"publish\" key!")
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue