pyblish / pyblish-base

Pyblish base library - see https://github.com/pyblish/pyblish for details.
Other
127 stars 59 forks source link

Can't order Collectors negatively #210

Closed mottosso closed 9 years ago

mottosso commented 9 years ago

Investigate this.

mottosso commented 9 years ago

Hey @tokejepsen, I can't reproduce this, it works fine here.

Could you try this?

import pyblish.api

count = {"#": 0}

class MyCollector(pyblish.api.Collector):
    order = pyblish.api.Collector.order - 0.49

    def process(self):
        count["#"] += 1

pyblish.api.register_plugin(MyCollector)

import pyblish.util
pyblish.util.publish()

assert count["#"] == 1
tokejepsen commented 9 years ago

I get this error in the Hiero integration, when I try to inject some data into the context;

import pyblish.api

import hiero

@pyblish.api.log
class SelectProject(pyblish.api.Selector):
    """Inject the active project into context"""

    version = (0, 1, 0)

    def process(self, context):

        context.set_data('activeProject', value=hiero.activeProject)

If I renamed the plugin to SelectActiveProject it gets evaluated first, but can't rely on that (?). When I have a negative order like order = pyblish.api.Collector.order - 0.49, the plugin gets ignored by Pyblish.

tokejepsen commented 9 years ago

I tried pyblish.util.publish(), and that works, so it seems to be something with pyblish ui?

mottosso commented 9 years ago

It's not very obvious at the moment, but you can't store anything but plain-old-data (POD) as data in the context or instances; that is, nothing that isn't JSON serialisable.

As a test, you can ensure that whatever you store doesn't throw an exception when you pass it to json.dumps, and in general it includes any regular Python datatype, like dicts, lists, strings, ints etc.

If you need to store custom classes, you will need to implement a serialisation method on them and generally a deserialisation equivalent also, but its simpler to stick with the basics types, a.k.a. plain-old-data.

Was this what caused the problem? In that case, the negative order shouldn't have any effect, could you confirm?

tokejepsen commented 9 years ago

I tried with just passing a plain string, and still got the problem. Can replicate in Maya with this plugin;

import pyblish.api

@pyblish.api.log
class SelectActiveProject(pyblish.api.Selector):
    """"""

    order = pyblish.api.Collector.order - 0.1

    def process(self, context):

        context.set_data('activeProject', value='something')

Initially the plugin doesn't show in the pyblish ui terminal, but if you comment out the order attribute of the plugin, it appears in the terminal.

mottosso commented 9 years ago

Ok, I can replicate this. Will investigate.