♻️ replace exceptions and asserts in validators

This commit is contained in:
Ondrej Samohel 2022-09-20 12:25:48 +02:00
parent 93b3b04034
commit ec4bcc474b
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
16 changed files with 121 additions and 69 deletions

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import pyblish.api
from openpype.pipeline.publish import ValidateContentsOrder
from openpype.pipeline import PublishValidationError
class ValidateBypassed(pyblish.api.InstancePlugin):
@ -11,7 +12,7 @@ class ValidateBypassed(pyblish.api.InstancePlugin):
"""
order = ValidateContentsOrder - 0.1
order = pyblish.api.ValidatorOrder - 0.1
families = ["*"]
hosts = ["houdini"]
label = "Validate ROP Bypass"
@ -26,9 +27,10 @@ class ValidateBypassed(pyblish.api.InstancePlugin):
invalid = self.get_invalid(instance)
if invalid:
rop = invalid[0]
raise RuntimeError(
"ROP node %s is set to bypass, publishing cannot continue.."
% rop.path()
raise PublishValidationError(
("ROP node {} is set to bypass, publishing cannot "
"continue.".format(rop.path())),
title=self.label
)
@classmethod

View file

@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import pyblish.api
from openpype.pipeline import PublishValidationError
class ValidateCopOutputNode(pyblish.api.InstancePlugin):
"""Validate the instance COP Output Node.
@ -20,9 +23,10 @@ class ValidateCopOutputNode(pyblish.api.InstancePlugin):
invalid = self.get_invalid(instance)
if invalid:
raise RuntimeError(
"Output node(s) `%s` are incorrect. "
"See plug-in log for details." % invalid
raise PublishValidationError(
("Output node(s) `{}` are incorrect. "
"See plug-in log for details.").format(invalid),
title=self.label
)
@classmethod
@ -54,7 +58,8 @@ class ValidateCopOutputNode(pyblish.api.InstancePlugin):
# For the sake of completeness also assert the category type
# is Cop2 to avoid potential edge case scenarios even though
# the isinstance check above should be stricter than this category
assert output_node.type().category().name() == "Cop2", (
"Output node %s is not of category Cop2. This is a bug.."
% output_node.path()
)
if output_node.type().category().name() != "Cop2":
raise PublishValidationError(
("Output node %s is not of category Cop2. "
"This is a bug...").format(output_node.path()),
title=cls.label)

View file

@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
import os
import pyblish.api
from openpype.hosts.houdini.api import lib
from openpype.pipeline import PublishValidationError
class ValidateFileExtension(pyblish.api.InstancePlugin):
@ -29,8 +31,9 @@ class ValidateFileExtension(pyblish.api.InstancePlugin):
invalid = self.get_invalid(instance)
if invalid:
raise RuntimeError(
"ROP node has incorrect " "file extension: %s" % invalid
raise PublishValidationError(
"ROP node has incorrect file extension: {}".format(invalid),
title=self.label
)
@classmethod
@ -53,7 +56,9 @@ class ValidateFileExtension(pyblish.api.InstancePlugin):
for family in families:
extension = cls.family_extensions.get(family, None)
if extension is None:
raise RuntimeError("Unsupported family: %s" % family)
raise PublishValidationError(
"Unsupported family: {}".format(family),
title=cls.label)
if output_extension != extension:
return [node.path()]

View file

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import pyblish.api
from openpype.pipeline import PublishValidationError
class ValidateHoudiniCommercialLicense(pyblish.api.InstancePlugin):
@ -24,7 +26,7 @@ class ValidateHoudiniCommercialLicense(pyblish.api.InstancePlugin):
license = hou.licenseCategory()
if license != hou.licenseCategoryType.Commercial:
raise RuntimeError(
"USD Publishing requires a full Commercial "
"license. You are on: %s" % license
)
raise PublishValidationError(
("USD Publishing requires a full Commercial "
"license. You are on: {}").format(license),
title=self.label)

View file

@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
import pyblish.api
from openpype.pipeline.publish import ValidateContentsOrder
from openpype.pipeline import PublishValidationError
class ValidateIntermediateDirectoriesChecked(pyblish.api.InstancePlugin):
"""Validate Create Intermediate Directories is enabled on ROP node."""
order = ValidateContentsOrder
order = pyblish.api.ValidatorOrder
families = ["pointcache", "camera", "vdbcache"]
hosts = ["houdini"]
label = "Create Intermediate Directories Checked"
@ -14,10 +15,10 @@ class ValidateIntermediateDirectoriesChecked(pyblish.api.InstancePlugin):
invalid = self.get_invalid(instance)
if invalid:
raise RuntimeError(
"Found ROP node with Create Intermediate "
"Directories turned off: %s" % invalid
)
raise PublishValidationError(
("Found ROP node with Create Intermediate "
"Directories turned off: {}".format(invalid)),
title=self.label)
@classmethod
def get_invalid(cls, instance):

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import pyblish.api
import hou
from openpype.pipeline.publish import ValidateContentsOrder
from openpype.pipeline import PublishValidationError
def cook_in_range(node, start, end):
@ -28,7 +29,7 @@ def get_errors(node):
class ValidateNoErrors(pyblish.api.InstancePlugin):
"""Validate the Instance has no current cooking errors."""
order = ValidateContentsOrder
order = pyblish.api.ValidatorOrder
hosts = ["houdini"]
label = "Validate no errors"
@ -62,4 +63,6 @@ class ValidateNoErrors(pyblish.api.InstancePlugin):
errors = get_errors(node)
if errors:
self.log.error(errors)
raise RuntimeError("Node has errors: %s" % node.path())
raise PublishValidationError(
"Node has errors: {}".format(node.path()),
title=self.label)

View file

@ -1,7 +1,9 @@
# -*-coding: utf-8 -*-
import pyblish.api
from openpype.hosts.houdini.api import lib
from openpype.pipeline.publish import RepairContextAction
from openpype.pipeline import PublishValidationError
import hou
@ -27,17 +29,24 @@ class ValidateRemotePublishOutNode(pyblish.api.ContextPlugin):
# We ensure it's a shell node and that it has the pre-render script
# set correctly. Plus the shell script it will trigger should be
# completely empty (doing nothing)
assert node.type().name() == "shell", "Must be shell ROP node"
assert node.parm("command").eval() == "", "Must have no command"
assert not node.parm("shellexec").eval(), "Must not execute in shell"
assert (
node.parm("prerender").eval() == cmd
), "REMOTE_PUBLISH node does not have correct prerender script."
assert (
node.parm("lprerender").eval() == "python"
), "REMOTE_PUBLISH node prerender script type not set to 'python'"
if node.type().name() != "shell":
self.raise_error("Must be shell ROP node")
if node.parm("command").eval() != "":
self.raise_error("Must have no command")
if node.parm("shellexec").eval():
self.raise_error("Must not execute in shell")
if node.parm("prerender").eval() != cmd:
self.raise_error(("REMOTE_PUBLISH node does not have "
"correct prerender script."))
if node.parm("lprerender").eval() != "python":
self.raise_error(("REMOTE_PUBLISH node prerender script "
"type not set to 'python'"))
@classmethod
def repair(cls, context):
"""(Re)create the node if it fails to pass validation."""
lib.create_remote_publish_node(force=True)
def raise_error(self, message):
self.log.error(message)
raise PublishValidationError(message, title=self.label)

View file

@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
import pyblish.api
import hou
from openpype.pipeline.publish import RepairContextAction
from openpype.pipeline import PublishValidationError
class ValidateRemotePublishEnabled(pyblish.api.ContextPlugin):
@ -18,10 +20,12 @@ class ValidateRemotePublishEnabled(pyblish.api.ContextPlugin):
node = hou.node("/out/REMOTE_PUBLISH")
if not node:
raise RuntimeError("Missing REMOTE_PUBLISH node.")
raise PublishValidationError(
"Missing REMOTE_PUBLISH node.", title=self.label)
if node.isBypassed():
raise RuntimeError("REMOTE_PUBLISH must not be bypassed.")
raise PublishValidationError(
"REMOTE_PUBLISH must not be bypassed.", title=self.label)
@classmethod
def repair(cls, context):
@ -29,7 +33,8 @@ class ValidateRemotePublishEnabled(pyblish.api.ContextPlugin):
node = hou.node("/out/REMOTE_PUBLISH")
if not node:
raise RuntimeError("Missing REMOTE_PUBLISH node.")
raise PublishValidationError(
"Missing REMOTE_PUBLISH node.", title=cls.label)
cls.log.info("Disabling bypass on /out/REMOTE_PUBLISH")
node.bypass(False)

View file

@ -58,10 +58,11 @@ class ValidateSopOutputNode(pyblish.api.InstancePlugin):
# For the sake of completeness also assert the category type
# is Sop to avoid potential edge case scenarios even though
# the isinstance check above should be stricter than this category
assert output_node.type().category().name() == "Sop", (
"Output node %s is not of category Sop. This is a bug.."
% output_node.path()
)
if output_node.type().category().name() != "Sop":
raise PublishValidationError(
("Output node {} is not of category Sop. "
"This is a bug.").format(output_node.path()),
title=cls.label)
# Ensure the node is cooked and succeeds to cook so we can correctly
# check for its geometry data.

View file

@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import pyblish.api
import openpype.hosts.houdini.api.usd as hou_usdlib
from openpype.pipeline import PublishValidationError
class ValidateUSDLayerPathBackslashes(pyblish.api.InstancePlugin):
@ -44,7 +46,7 @@ class ValidateUSDLayerPathBackslashes(pyblish.api.InstancePlugin):
invalid.append(layer)
if invalid:
raise RuntimeError(
raise PublishValidationError((
"Loaded layers have backslashes. "
"This is invalid for HUSK USD rendering."
)
"This is invalid for HUSK USD rendering."),
title=self.label)

View file

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
import pyblish.api
import openpype.hosts.houdini.api.usd as hou_usdlib
from openpype.pipeline import PublishValidationError
from pxr import UsdShade, UsdRender, UsdLux
@ -55,7 +56,8 @@ class ValidateUsdModel(pyblish.api.InstancePlugin):
if invalid:
prim_paths = sorted([str(prim.GetPath()) for prim in invalid])
raise RuntimeError("Found invalid primitives: %s" % prim_paths)
raise PublishValidationError(
"Found invalid primitives: {}".format(prim_paths))
class ValidateUsdShade(ValidateUsdModel):

View file

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import pyblish.api
from openpype.pipeline import PublishValidationError
class ValidateUSDOutputNode(pyblish.api.InstancePlugin):
@ -20,9 +22,10 @@ class ValidateUSDOutputNode(pyblish.api.InstancePlugin):
invalid = self.get_invalid(instance)
if invalid:
raise RuntimeError(
"Output node(s) `%s` are incorrect. "
"See plug-in log for details." % invalid
raise PublishValidationError(
("Output node(s) `{}` are incorrect. "
"See plug-in log for details.").format(invalid),
title=self.label
)
@classmethod

View file

@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import os
import pyblish.api
import os
from openpype.pipeline import PublishValidationError
class ValidateUSDRenderProductNames(pyblish.api.InstancePlugin):
@ -28,4 +30,5 @@ class ValidateUSDRenderProductNames(pyblish.api.InstancePlugin):
if invalid:
for message in invalid:
self.log.error(message)
raise RuntimeError("USD Render Paths are invalid.")
raise PublishValidationError(
"USD Render Paths are invalid.", title=self.label)

View file

@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import pyblish.api
import openpype.hosts.houdini.api.usd as hou_usdlib
from openpype.pipeline import PublishValidationError
class ValidateUsdSetDress(pyblish.api.InstancePlugin):
@ -47,8 +49,9 @@ class ValidateUsdSetDress(pyblish.api.InstancePlugin):
invalid.append(node)
if invalid:
raise RuntimeError(
raise PublishValidationError((
"SetDress contains local geometry. "
"This is not allowed, it must be an assembly "
"of referenced assets."
"of referenced assets."),
title=self.label
)

View file

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import re
import pyblish.api
@ -5,6 +6,7 @@ import pyblish.api
from openpype.client import get_subset_by_name
from openpype.pipeline import legacy_io
from openpype.pipeline.publish import ValidateContentsOrder
from openpype.pipeline import PublishValidationError
class ValidateUSDShadeModelExists(pyblish.api.InstancePlugin):
@ -32,7 +34,8 @@ class ValidateUSDShadeModelExists(pyblish.api.InstancePlugin):
project_name, model_subset, asset_doc["_id"], fields=["_id"]
)
if not subset_doc:
raise RuntimeError(
"USD Model subset not found: "
"%s (%s)" % (model_subset, asset_name)
raise PublishValidationError(
("USD Model subset not found: "
"{} ({})").format(model_subset, asset_name),
title=self.label
)

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import pyblish.api
from openpype.pipeline.publish import ValidateContentsOrder
from openpype.pipeline import PublishValidationError
import hou
@ -12,7 +13,7 @@ class ValidateUsdShadeWorkspace(pyblish.api.InstancePlugin):
"""
order = ValidateContentsOrder
order = pyblish.api.ValidatorOrder
hosts = ["houdini"]
families = ["usdShade"]
label = "USD Shade Workspace"
@ -39,13 +40,14 @@ class ValidateUsdShadeWorkspace(pyblish.api.InstancePlugin):
if node_type != other_node_type:
continue
# Get highest version
# Get the highest version
highest = max(highest, other_version)
if version != highest:
raise RuntimeError(
"Shading Workspace is not the latest version."
" Found %s. Latest is %s." % (version, highest)
raise PublishValidationError(
("Shading Workspace is not the latest version."
" Found {}. Latest is {}.").format(version, highest),
title=self.label
)
# There were some issues with the editable node not having the right
@ -56,8 +58,9 @@ class ValidateUsdShadeWorkspace(pyblish.api.InstancePlugin):
)
rop_value = rop.parm("lopoutput").rawValue()
if rop_value != value:
raise RuntimeError(
"Shading Workspace has invalid 'lopoutput'"
" parameter value. The Shading Workspace"
" needs to be reset to its default values."
raise PublishValidationError(
("Shading Workspace has invalid 'lopoutput'"
" parameter value. The Shading Workspace"
" needs to be reset to its default values."),
title=self.label
)