Validating I
Sometimes, sharing means to first agree on a format in which to share, such that you don't end up with one big mess.
1
import pyblish.api
2
3
items = ["JOHN.person", "door.prop"]
4
5
class CollectInstances(pyblish.api.ContextPlugin):
6
order = 0
7
8
def process(self, context):
9
for item in items:
10
name, suffix = item.split(".")
11
context.create_instance(name, family=suffix)
12
13
class ValidateNamingConvention(pyblish.api.InstancePlugin):
14
order = 1
15
16
def process(self, instance):
17
name = instance.data["name"]
18
assert name == name.title(), "Sorry, %s should have been %s" % (
19
name, name.title())
20
21
pyblish.api.register_plugin(CollectInstances)
22
pyblish.api.register_plugin(ValidateNamingConvention)
23
24
import pyblish.util
25
pyblish.util.publish()
26
# Sorry, JOHN should have been John
27
# Sorry, door should have been Door
28
Stopped due to: failed validation
Copied!
We indicate failure by throwing exceptions of any kind, including assertions. Making the change, we now "pass validation".
1
...
2
items = ["John.person", "Door.prop"]
3
...
4
pyblish.util.publish()
5
# John is valid
6
# Door is valid
Copied!
Last modified 1yr ago
Copy link