Open davidlatwe opened 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.
Merging this today :D
@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.
Just added, also fixed an obvious bug that I missed in ebcb78c. :P
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.
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'
Test fixed ! See log
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.
That indeed much better ! Thanks. 🚀
Changes
This PR closes #507. Depends on the type of input argument
family
ofapi.create
, try matching all plugins viafamily
if it's a string, or dierctly run the given plugin iffamily
is that plugin.