Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions avalon/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def create(name, asset, family, options=None, data=None):
Arguments:
name (str): Name of subset
asset (str): Name of asset
family (str): Name of family
family (str, Creator): Name of family, or a Creator plugin class
options (dict, optional): Additional options from GUI
data (dict, optional): Additional data from GUI

Expand All @@ -878,12 +878,14 @@ def create(name, asset, family, options=None, data=None):

host = registered_host()

plugins = list()
for Plugin in discover(Creator):
has_family = family == Plugin.family
if inspect.isclass(family) and issubclass(family, Creator):
# Allow passing in a specific Creator to run only that plug-in
Plugins = [family]
else:
Plugins = [P for P in discover(Creator) if family == P.family]

if not has_family:
continue
plugins = list()
for Plugin in Plugins:

Plugin.log.info(
"Creating '%s' with '%s'" % (name, Plugin.__name__)
Expand Down
34 changes: 34 additions & 0 deletions avalon/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ def setup():
pipeline.register_root(self.tempdir)

# Mock host
dummy_maintained_selection = type(
"empty_ctx", (object,),
{"__enter__": lambda s: s, "__exit__": lambda *a, **k: None}
)

host = types.ModuleType("Test")
host.__dict__.update({
"ls": lambda: [],
"maintained_selection": dummy_maintained_selection,
})

pipeline.register_host(host)
Expand Down Expand Up @@ -76,6 +82,34 @@ def process(self, name, namespace, context):
shutil.rmtree(tempdir)


@with_setup(clear)
def test_creators():
"""Register a Creator and create instance by different family input"""

data = {"value": 0}

class CreateA(pipeline.Creator):
def process(self):
data["value"] += 1
family = "foobar"

class CreateB(pipeline.Creator):
def process(self):
data["value"] += 10
family = "foobar"

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

# Create with regular string type family
pipeline.create("foo", "my_asset", family="foobar")
assert data["value"] == 11, "Must run both Creator Plugins"

# Create with plugin class, see getavalon/core#531
pipeline.create("foo", "my_asset", family=CreateA)
assert data["value"] == 12, "Must run only CreatorA Plugin"


@with_setup(clear)
def test_on():
"""api.on() works as advertised"""
Expand Down
4 changes: 2 additions & 2 deletions avalon/tools/creator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,13 @@ def on_create(self):

subset_name = result.text()
asset = asset.text()
family = item.data(FamilyRole)
Plugin = item.data(PluginRole)
use_selection = self.data["Use Selection Checkbox"].isChecked()

try:
api.create(subset_name,
asset,
family,
Plugin,
options={"useSelection": use_selection})

except NameError as e:
Expand Down
1 change: 1 addition & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# We can expect any vendors to
# be well tested beforehand.
"--exclude-dir=avalon/vendor",
"--exclude-dir=avalon/style",
])

nose.main(argv=argv,
Expand Down