<commit_before>from maya import cmds
from mindbender import api


class RigLoader(api.Loader):
    """Specific loader for rigs

    This automatically creates an instance for animators upon load.

    """

    families = ["mindbender.rig"]
    representations = ["ma"]

    def process(self, name, namespace, context):
        nodes = cmds.file(self.fname,
                          namespace=namespace,
                          reference=True,
                          returnNewNodes=True,
                          groupReference=True,
                          groupName=namespace + ":" + name)

        # Store for post-process
        self[:] = nodes

    def post_process(self, name, namespace, context):
        from mindbender import maya

        # TODO(marcus): We are hardcoding the name "out_SET" here.
        #   Better register this keyword, so that it can be used
        #   elsewhere, such as in the Integrator plug-in,
        #   without duplication.
        output = next(
            (node for node in self
                if node.endswith("out_SET")), None)
        controls = next(
            (node for node in self
                if node.endswith("controls_SET")), None)

        assert output, "No out_SET in rig, this is a bug."
        assert controls, "No controls_SET in rig, this is a bug."

        with maya.maintained_selection():
            cmds.select([output, controls], noExpand=True)

            dependencies = [context["representation"]["_id"]]
            asset = context["asset"]["name"] + "_"

            # TODO(marcus): Hardcoding the family here, better separate this.
            maya.create(
                name=maya.unique_name(asset, suffix="_SET"),
                asset=context["asset"]["name"],
                family="mindbender.animation",
                options={"useSelection": True},
                data={
                    "dependencies": " ".join(str(d) for d in dependencies)
                })<commit_msg>Fix rigs publishing to their corresponding asset<commit_after>from maya import cmds
from mindbender import api


class RigLoader(api.Loader):
    """Specific loader for rigs

    This automatically creates an instance for animators upon load.

    """

    families = ["mindbender.rig"]
    representations = ["ma"]

    def process(self, name, namespace, context):
        nodes = cmds.file(self.fname,
                          namespace=namespace,
                          reference=True,
                          returnNewNodes=True,
                          groupReference=True,
                          groupName=namespace + ":" + name)

        # Store for post-process
        self[:] = nodes

    def post_process(self, name, namespace, context):
        import os
        from mindbender import maya

        # TODO(marcus): We are hardcoding the name "out_SET" here.
        #   Better register this keyword, so that it can be used
        #   elsewhere, such as in the Integrator plug-in,
        #   without duplication.
        output = next(
            (node for node in self
                if node.endswith("out_SET")), None)
        controls = next(
            (node for node in self
                if node.endswith("controls_SET")), None)

        assert output, "No out_SET in rig, this is a bug."
        assert controls, "No controls_SET in rig, this is a bug."

        with maya.maintained_selection():
            cmds.select([output, controls], noExpand=True)

            dependencies = [context["representation"]["_id"]]
            asset = context["asset"]["name"] + "_"

            maya.create(
                name=maya.unique_name(asset, suffix="_SET"),

                # Publish to the currently set asset, and not the
                # asset from which the Rig was produced.
                asset=os.environ["MINDBENDER_ASSET"],

                family="mindbender.animation",
                options={"useSelection": True},
                data={
                    "dependencies": " ".join(str(d) for d in dependencies)
                })
{'fraction_non_alphanumeric': 0.09625800098473658, 'fraction_numerical': 0.0, 'mean_word_length': 1.780971937029432, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '239664', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1012, 'n_words': 320}