Skip to content

Refactor profiles filtering: add rank_profile, get_matching_profiles, get_highest_score_profiles#1705

Open
vincentullmann wants to merge 2 commits intoynput:developfrom
vincentullmann:enhancement/profiles-filtering-refactor
Open

Refactor profiles filtering: add rank_profile, get_matching_profiles, get_highest_score_profiles#1705
vincentullmann wants to merge 2 commits intoynput:developfrom
vincentullmann:enhancement/profiles-filtering-refactor

Conversation

@vincentullmann
Copy link
Contributor

Changelog Description

Refactored profile filtering and added new methods so callers can match multiple profiles instead of only picking the single best one.

Additional info

Unchanged

  • filter_profiles expected behaviour is unchanged and backwards compatible. (hopefully)

New

  • rank_profile: ranks a single profile using a lexicographic binary score.
    • Each key contributes one bit (1 = exact match, 0 = wildcard); results form a bitmask so earlier keys matter more.
    • e.g. 0b110 = 6 beats 0b101 = 5 (both have 2 value matches and 1 wildcard).
    • Total number of exact matches = number of 1 bits (e.g. score.bit_count()).
  • rank_profiles: helper to rank multiple profiles
  • get_matching_profiles: returns all profiles with a non‑negative score.
  • get_highest_score_profiles: Returns all profiles with the highest score.
  • Unit tests added for the new helpers and edge cases.

Use case

Useful for addons that want to compose profiles dynamically (eg. merge multiple rules into one).

Example (eg. dynamic profiles for deadline):

profiles = {
    # default priority
    ["host": ["*"], "priority": 50],

    # increase chunk size to run the entire playblast in one chunk
    ["host": ["maya"],  "productBaseTypes": ["playblast"], "chunk_size": 999, "overrides": ["chunk_size"]],

    # allow FX tasks to choose the machine pool + allow them to overwrite the default pool
    ["host": ["maya"],  "task": ["fx"], "pool": "high_memory", "overrides": ["pool"]],
}


def get_profile_for_instance(self, instance):
    values = {
        "host": "maya",
        "productBaseTypes": "playblast",
        "task": "fx",
    }
    # custom filter to only include profiles with at least two exact matches
    profiles = [profile for profile, score in rank_profiles(self.profiles, values) if score.bit_count() >= 2]

    # addon specific merge of profiles
    profile = self.combine_profiles(profiles)
    # {
    #     "priority": 50,
    #     "chunk_size": 999,
    #     "pool": "high_memory",
    #     "overrides": ["chunk_size", "pool"]
    # }

@ynbot ynbot added size/M type: enhancement Improvement of existing functionality or minor addition labels Feb 16, 2026

def _profile_exclusion(matching_profiles, logger):
"""Find out most matching profile byt host, task and family match.
def fullmatch(regex, string, flags=0):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function is unchanged. the diff is incorrect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M type: enhancement Improvement of existing functionality or minor addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants