core icon indicating copy to clipboard operation
core copied to clipboard

Make `api.create` able to run with one specific creator plugin

Open davidlatwe opened this issue 5 years ago • 9 comments

Changes

This PR closes #507. Depends on the type of input argument family of api.create, try matching all plugins via family if it's a string, or dierctly run the given plugin if family is that plugin.

davidlatwe avatar Mar 10 '20 04:03 davidlatwe

Here's my test code

class CreateA(api.Creator):
    label = "A"
    family = "foobar"

    def process(self):
        print("A")

class CreateB(api.Creator):
    label = "B"
    family = "foobar"

    def process(self):
        print("B")
        

from avalon import api
from avalon.tools import creator
# Deregister all plugins for clarity
for path in api.registered_plugin_paths()[api.Creator]:
    api.deregister_plugin_path(api.Creator, path)

api.register_plugin(api.Creator, CreateA)
api.register_plugin(api.Creator, CreateB)

creator.show()

After this PR, only one creator obove will be triggered.

davidlatwe avatar Mar 10 '20 04:03 davidlatwe

Merging this today :D

davidlatwe avatar Sep 30 '20 07:09 davidlatwe

@davidlatwe I'm wondering. Since you've a ready to go test for this? Any chance you can add a test too for the unittests?

One that tests the old by string family behavior, and the new behavior? Just to make sure we preserve it well for the future - or at least know about any potential changes.

It would be in core/avalon/tests then.

BigRoy avatar Sep 30 '20 09:09 BigRoy

Just added, also fixed an obvious bug that I missed in ebcb78c. :P

davidlatwe avatar Sep 30 '20 11:09 davidlatwe

Weird, the test actually failed, but build passed. :/

The test passed in my Maya session, maybe I should write the test plugin into an actual script file.

davidlatwe avatar Sep 30 '20 11:09 davidlatwe

Ah, now I see the problem, the host registed in test_pipeline has no attribute 'maintained_selection'

avalon.pipeline: WARNING: 'module' object has no attribute 'maintained_selection'

davidlatwe avatar Sep 30 '20 11:09 davidlatwe

Test fixed ! See log

davidlatwe avatar Sep 30 '20 12:09 davidlatwe

Awesome work!

The only thing you are missing in the test is the test case where two plug-ins register to the same family where running it by family string name it should run both (as originally) and by solely Plugin run only the single one. That's the test case we want to preserve over time I suppose (or at least know about that it changes).

# psuedocode

data= {"value": 0}

class CreateA(api.Creator):
    label = "A"
    family = "foobar"

    def process(self):
        data["value"] += 1

class CreateB(api.Creator):
    label = "B"
    family = "foobar"

    def process(self):
        data["value"] += 10
        

from avalon import api
from avalon.tools import creator
# Deregister all plugins for clarity
for path in api.registered_plugin_paths()[api.Creator]:
    api.deregister_plugin_path(api.Creator, path)

api.register_plugin(api.Creator, CreateA)
api.register_plugin(api.Creator, CreateB)

api.create("foo", "my_asset", family="foobar")
assert data["value"] == 11, "Must run both Creator Plugins"

api.create("foo", "my_asset", family=CreateA)
assert data["value"] == 12, "Must run onlyCreatorA Plugin"

Following counting-like logic from pyblish tests, example.

BigRoy avatar Sep 30 '20 14:09 BigRoy

That indeed much better ! Thanks. 🚀

davidlatwe avatar Sep 30 '20 14:09 davidlatwe