getavalon / core

The safe post-production pipeline - https://getavalon.github.io/2.0
MIT License
218 stars 49 forks source link

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

Open davidlatwe opened 4 years ago

davidlatwe commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Merging this today :D

BigRoy commented 4 years ago

@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.

davidlatwe commented 4 years ago

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

davidlatwe commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Test fixed ! See log

BigRoy commented 4 years ago

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.

davidlatwe commented 4 years ago

That indeed much better ! Thanks. 🚀