Skip to content

increment_workfile

IncrementWorkfile

Bases: InstancePlugin

Increment the current workfile.

Saves the current scene with an increased version number.

Source code in client/ayon_comfyui/plugins/publish/increment_workfile.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class IncrementWorkfile(pyblish.api.InstancePlugin):
    """Increment the current workfile.

    Saves the current scene with an increased version number.
    """

    label = "Increment Workfile"
    order = pyblish.api.IntegratorOrder + 9.0
    hosts = ["comfyui"]
    families = ["workfile"]
    optional = True

    def process(self, instance):
        context = instance.context
        errored_plugins = get_errored_plugins_from_context(context)
        if errored_plugins:
            raise RuntimeError(
                "Skipping incrementing current file because publishing failed."
            )

        version = None
        current_filepath: str = context.data["currentFile"]
        host: ComfyUIHost = registered_host()

        # TODO(Roy): Why do we need this?
        if not instance.data["do_increment"]:
            self.log.info("Not incremented since first publish")

            version = get_versioning_start(
                context.data.get("projectName"),
                host.name,
                task_name=context.data["taskEntity"]["name"],
                task_type=context.data["taskEntity"]["taskType"],
                product_base_type="workfile",
                product_name=instance.data["productName"],
                project_settings=context.data["project_settings"],
            )
            if version > 1:
                version -= 1

        current_filename = os.path.basename(current_filepath)

        save_next_version(
            version=version,
            description=(f"Incremented by publishing from {current_filename}"),
            # Optimize the save by reducing needed queries for context
            prepared_data=SaveWorkfileOptionalData(
                project_entity=context.data.get("projectEntity"),
                project_settings=context.data.get("project_settings"),
                anatomy=context.data.get("anatomy"),
            ),
        )

        new_scene_path = host.get_current_workfile()
        new_name = Path(new_scene_path).stem
        host.stub.client_stub.updateTab(new_name=new_name)

        self.log.info(f"Incremented workfile to: {new_scene_path}")  # noqa: G004