Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator now sorting the plugins before iteration #358

Closed
Closed
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ docs/_*
build
playground.py
*.sublime-*
__pycache__
__pycache__
venv/
6 changes: 4 additions & 2 deletions pyblish/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
Subset,
Exact,

registered_targets
registered_targets,

sort
)

_algorithms = {
Expand Down Expand Up @@ -358,7 +360,7 @@ def Iterator(plugins, context, state=None):
# when running the Iterator directly without registering any targets.
targets = registered_targets() or ["default"]

plugins = plugins_by_targets(plugins, targets)
plugins = sort(plugins_by_targets(plugins, targets))

for plugin in plugins:
if not plugin.active:
Expand Down
23 changes: 19 additions & 4 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def no_guis():

@with_setup(lib.setup, lib.teardown)
def test_iterator():
"""Iterator skips inactive plug-ins and instances"""
"""Iterator skips inactive plug-ins and instances.

Also processes plugins in order.
"""

count = {"#": 0}

Expand All @@ -47,24 +50,36 @@ def process(self, instance):
count["#"] += 10

class MyValidatorB(api.InstancePlugin):
order = api.ValidatorOrder + 0.1

def process(self, instance):
count["#"] += 100

class MyValidatorC(api.InstancePlugin):
order = api.ValidatorOrder

def process(self, instance):
count["#"] += 100

context = api.Context()
plugins = [MyCollector, MyValidatorA, MyValidatorB]
plugins = [MyCollector, MyValidatorA, MyValidatorB, MyValidatorC]

assert count["#"] == 0, count

order = []

for Plugin, instance in logic.Iterator(plugins, context):
assert instance.name != "Inactive" if instance else True
assert Plugin.__name__ != "MyValidatorA"
order.append(Plugin)

plugin.process(Plugin, context, instance)

# Collector runs once, one Validator runs once
assert count["#"] == 101, count
# Collector runs once, the two Validators run once
assert count["#"] == 201, count

# Plugins are processed in correct order
assert order == [MyCollector, MyValidatorC, MyValidatorB]


def test_register_gui():
Expand Down