Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish: Workfile collector #4

Merged
merged 4 commits into from
Apr 10, 2024
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
21 changes: 11 additions & 10 deletions client/ayon_openrv/plugins/publish/collect_workfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class CollectWorkfile(pyblish.api.InstancePlugin):
"""Inject the current working file into context"""

order = pyblish.api.CollectorOrder - 0.01
order = pyblish.api.CollectorOrder - 0.49
label = "OpenRV Session Workfile"
hosts = ["openrv"]
families = ["workfile"]
Expand All @@ -15,20 +15,21 @@ def process(self, instance):
"""Inject the current working file"""

host = registered_host()
current_file = host.get_current_workfile()
if not current_file:
self.log.error("No current filepath detected. "
"Make sure to save your OpenRV session")
current_file = ""
current_file = host.get_current_workfile() or ""

folder, file = os.path.split(current_file)
filename, ext = os.path.splitext(file)

instance.context.data["currentFile"] = current_file
Copy link
Contributor

@BigRoy BigRoy Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In many hosts the currentFile is used for all instances in the context, not just the workfile product type. But applying this here only when there is a workfile instance that context.data["currentFile"] is not set when the workfile instance is disabled during publishing. (Because it is an InstancePlugin that runs over families = ["workfile"]. The question then arises, whether this should actually run in a separate ContextPlugin instead of here. That also makes it way less important to run at the earlier order maybe?

Copy link
Member Author

@iLLiCiTiT iLLiCiTiT Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell. I just noticed this weird logic and made a PR, that at least validate that we don't try to publish invalid representation.


instance.data['representations'] = [{
'name': ext.lstrip("."),
'ext': ext.lstrip("."),
'files': file,
if not current_file:
self.log.error("No current filepath detected. "
"Make sure to save your OpenRV session")
return

instance.data["representations"] = [{
"name": ext.lstrip("."),
"ext": ext.lstrip("."),
"files": file,
"stagingDir": folder,
}]
17 changes: 17 additions & 0 deletions client/ayon_openrv/plugins/publish/validate_workfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pyblish.api

from ayon_core.pipeline.publish import PublishValidationError


class ValidateCurrentWorkFile(pyblish.api.InstancePlugin):
"""There must be workfile to publish."""

label = "Validate Workfile"
order = pyblish.api.ValidatorOrder - 0.1
hosts = ["openrv"]
families = ["workfile"]

def process(self, instance):
current_file = instance.context.data["currentFile"]
if not current_file:
raise PublishValidationError("There is no workfile to publish.")