Skip to content

pre_launch_args

Attempt to get arguments from server pre-launch.

ComfyPrelaunchHook

Bases: PreLaunchHook

Launch arguments preparation.

Hook add python executable and script path to AE implementation before AE executable and add last workfile path to launch arguments.

TODO: REVISE THIS, LIFTED FROM AFTEREFFECTS

Source code in client/ayon_comfyui/hooks/pre_launch_args.py
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
class ComfyPrelaunchHook(PreLaunchHook):
    """Launch arguments preparation.

    Hook add python executable and script path to AE implementation before
    AE executable and add last workfile path to launch arguments.

    TODO: REVISE THIS, LIFTED FROM AFTEREFFECTS
    """

    app_groups: ClassVar[set] = {"comfyui"}

    order: ClassVar[int] = 20
    launch_types: ClassVar[set] = {LaunchTypes.local}

    def execute(self) -> None:
        """Abstract execute method where logic of hook is."""
        self.log.warning(msg=str(self.launch_context.launch_args))
        self.log.warning(msg=str(self.launch_context.kwargs))
        self.log.warning(msg=str(self.launch_context.env))

        script_path = get_launch_script_path()
        # uses ayon_console to launch a script, respecting dev mode.
        dev_args = ["--use-dev"] if is_dev_mode_enabled() else []

        new_launch_args = get_ayon_launcher_args(*dev_args, "run", script_path)

        self.launch_context.launch_args = new_launch_args

        self.launch_context.kwargs = get_launch_kwargs(
            self.launch_context.kwargs
        )

execute()

Abstract execute method where logic of hook is.

Source code in client/ayon_comfyui/hooks/pre_launch_args.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def execute(self) -> None:
    """Abstract execute method where logic of hook is."""
    self.log.warning(msg=str(self.launch_context.launch_args))
    self.log.warning(msg=str(self.launch_context.kwargs))
    self.log.warning(msg=str(self.launch_context.env))

    script_path = get_launch_script_path()
    # uses ayon_console to launch a script, respecting dev mode.
    dev_args = ["--use-dev"] if is_dev_mode_enabled() else []

    new_launch_args = get_ayon_launcher_args(*dev_args, "run", script_path)

    self.launch_context.launch_args = new_launch_args

    self.launch_context.kwargs = get_launch_kwargs(
        self.launch_context.kwargs
    )

get_launch_kwargs(kwargs=None)

Returns Explicit setting of kwargs for Popen.

A client process to the launched ComfyUI should use these.

Expected behavior - ayon_console opens window with logs - ayon has stdout/stderr available for capturing

Source code in client/ayon_comfyui/hooks/pre_launch_args.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def get_launch_kwargs(kwargs: Optional[dict] = None) -> dict:
    """Returns Explicit setting of kwargs for Popen.

    A client process to the launched ComfyUI should use these.

    Expected behavior
    - ayon_console opens window with logs
    - ayon has stdout/stderr available for capturing
    """
    if kwargs is None:
        kwargs = {}

    if platform.system().lower() != "windows":
        return kwargs

    if is_using_ayon_console():
        kwargs.update({"creationflags": subprocess.CREATE_NEW_CONSOLE})
    else:
        kwargs.update(
            {
                "creationflags": subprocess.CREATE_NO_WINDOW,
                "stdout": subprocess.DEVNULL,
                "stderr": subprocess.DEVNULL,
            }
        )
    return kwargs