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

Variable family-matching algorithms #305

Merged
merged 5 commits into from Nov 18, 2016

Conversation

Projects
None yet
2 participants
@mottosso
Member

mottosso commented Nov 16, 2016

This enables the use of multiple families of an instance to be associated with a plug-in, only when said families are a subset of the families supported by a plug-in.

That's a mouth full!

All algorithms

Algorithm Description
Intersection Include instances that match any supported family of plug-in (default)
Subset Include instances that match all supported families of a plug-in
Exact Include instances that include only supported families of a plug-in

Example

Let's see an example.

from pyblish import api

class GenericPlugin(api.InstancePlugin):

  # Support both models and rigs
  families = ["model", "rig"]

  def process(self, instance):
    # Applies to both models and rigs
    assert "parent_GRP" in instance

class SpecificPlugin(api.InstancePlugin):

  # Support models, but only low-poly models
  families = ["model", "low"]
  match = api.Subset

  def process(self, instance):
    # Applies to only low-poly models
    assert instance.data["polyCount"] < 500

In this example, SpecificPlugin is associated to instances whose family(ies) are a subset of the supported families model and low. If the instance does not have at least both of these, it is not a match.

This is different from GenericPlugin, where only one of the families of an instance need to match any of the supported families of a plug-in.

The match parameter then is a matching algorithm, as provided by standard set functionality.

# 1. Include on any match
assert set(["a", "b"]).intersection(["b", "c"])

# 2. Include on all match
assert set(["a", "b"]).issubset(["a", "b", "c"])

# 3. Include on exact match (note order is independent)
assert set(["a", "b"]) == set(["b", "a"])

The default value for this parameter is api.Intersection to preserve backwards compatibility. The last possible value is api.Exact which means an instance only matches when families of both instance and plug-ins match exactly.

class EdgeCasePlugin(api.InstancePlugin):
  families = ["model", "low", "level21"]
  match = api.Exact

  def process(self, instance):
    assert "specialMember" in instance

See test_logic.py for complete examples.

mottosso added some commits Nov 16, 2016

Enable excluding key `family` from instances.
Before, the `family` key was assumed to always exist, which could make it difficult for when we sometime in the future decide to deprecate it completely in favor of `families`

@mottosso mottosso added the feature label Nov 16, 2016

@tokejepsen

This comment has been minimized.

Show comment
Hide comment
@tokejepsen

tokejepsen Nov 17, 2016

Member

It all looks good, but I was wondering why you limited the algorithms to Intersection, Subset and Exact?

Member

tokejepsen commented Nov 17, 2016

It all looks good, but I was wondering why you limited the algorithms to Intersection, Subset and Exact?

@mottosso

This comment has been minimized.

Show comment
Hide comment
@mottosso

mottosso Nov 17, 2016

Member

but I was wondering why you limited the algorithms to Intersection, Subset and Exact?

I didn't think of it that way, what other algorithms would you like to see? Are you looking to provide your own?

Member

mottosso commented Nov 17, 2016

but I was wondering why you limited the algorithms to Intersection, Subset and Exact?

I didn't think of it that way, what other algorithms would you like to see? Are you looking to provide your own?

@tokejepsen

This comment has been minimized.

Show comment
Hide comment
@tokejepsen

tokejepsen Nov 17, 2016

Member

I didn't think of it that way, what other algorithms would you like to see? Are you looking to provide your own?

Yeah, if you wanted to match by something else than the families data member. For example for pyblish-ftrack its expected for required data members to be present. We are currently working around that by returning early, but the plugin is still run which might be confusing for other users.

Member

tokejepsen commented Nov 17, 2016

I didn't think of it that way, what other algorithms would you like to see? Are you looking to provide your own?

Yeah, if you wanted to match by something else than the families data member. For example for pyblish-ftrack its expected for required data members to be present. We are currently working around that by returning early, but the plugin is still run which might be confusing for other users.

@mottosso

This comment has been minimized.

Show comment
Hide comment
@mottosso

mottosso Nov 17, 2016

Member

Aha, ok. I think that'd be a good topic for a separate feature request. It'd be an entirely new feature, so we'll need to narrow down use-cases and consequences. Off the top of my head, I might worry about every collection of plug-ins defining their own algorithm, making external plug-ins that much less usable, understandable and interchangeable.

Does this feature request at least fulfil the initial requirement from the forums?

Member

mottosso commented Nov 17, 2016

Aha, ok. I think that'd be a good topic for a separate feature request. It'd be an entirely new feature, so we'll need to narrow down use-cases and consequences. Off the top of my head, I might worry about every collection of plug-ins defining their own algorithm, making external plug-ins that much less usable, understandable and interchangeable.

Does this feature request at least fulfil the initial requirement from the forums?

@tokejepsen

This comment has been minimized.

Show comment
Hide comment
@tokejepsen

tokejepsen Nov 17, 2016

Member

Does this feature request at least fulfil the initial requirement from for forums?

It does indeed:-)

Member

tokejepsen commented Nov 17, 2016

Does this feature request at least fulfil the initial requirement from for forums?

It does indeed:-)

mottosso added some commits Nov 18, 2016

@mottosso mottosso merged commit 6dc5781 into pyblish:master Nov 18, 2016

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.2%) to 94.917%
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment