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

make Instance able to return all families, for convenience #331

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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: 3 additions & 11 deletions pyblish/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,7 @@ def plugins_by_instance(plugins, instance):

"""

family = instance.data.get("family")
families = instance.data.get("families", [])

return plugins_by_families(
plugins, ([family] if family else []) + families)
return plugins_by_families(plugins, instance.families)


def plugins_by_host(plugins, host):
Expand Down Expand Up @@ -299,11 +295,7 @@ def instances_by_plugin(instances, plugin):
assert algorithm, ("Plug-in did not provide "
"valid matching algorithm: %s" % plugin.match)

family = instance.data.get("family")
families = [family] if family else []
families += instance.data.get("families", [])

if algorithm(plugin.families, families):
if algorithm(plugin.families, instance.families):
compatible.append(instance)

return compatible
Expand All @@ -327,7 +319,7 @@ def _extract_traceback(exception):
exc_type, exc_value, exc_traceback = sys.exc_info()
exception.traceback = traceback.extract_tb(exc_traceback)[-1]

except:
except Exception:
pass

finally:
Expand Down
9 changes: 9 additions & 0 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,15 @@ def __repr__(self):
def __str__(self):
return self._name

@property
def families(self):
"""Return list of family and families"""
family = self._data.get("family")
families = [family] if family else []
families += self._data.get("families", [])

return families

@property
def context(self):
"""Return top-level parent; the context"""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ def test_context_from_instance():
assert_equals(context, instance.context)


def test_families_from_instance():
"""Instances provide access to their families"""

context = pyblish.plugin.Context()
instance = context.create_instance("MyInstance")
instance.data["family"] = "A"
families = list(instance.data["family"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're lucky; this would actually make each character of the family into individual members of a list. :)

>>> list("abc")
['a', 'b', 'c']
>>>

Better make it..

families = [instance.data["family"]]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch ! Right !!

assert_equals(families, instance.families)

instance.data["families"] = ["B", "C"]
families.extend(instance.data["families"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always found this syntax a little more readable.

families += instance.data["families"]

assert_equals(families, instance.families)


def test_legacy():
"""Legacy is determined by existing process_* methods"""
class LegacyPlugin(pyblish.plugin.Collector):
Expand Down