Skip to content

utils

ensure_addons_are_process_context_ready(process_context, addons_manager=None, exit_on_failure=True)

Ensure all enabled addons are ready to be used in the given context.

Call this method only in AYON launcher process and as first thing to avoid possible clashes with preparation. For example 'QApplication' should not be created.

Todos

Run all preparations and allow to "ignore" failed preparations. Right now single addon can block using certain actions.

Parameters:

Name Type Description Default
process_context ProcessContext

The context in which the addons should be prepared.

required
addons_manager Optional[AddonsManager]

The addons manager to use. If not provided, a new one will be created.

None
exit_on_failure bool

If True, the process will exit if an error occurs. Defaults to True.

True

Returns:

Name Type Description
bool bool

True if all addons are ready, False otherwise.

Source code in client/ayon_core/addon/utils.py
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def ensure_addons_are_process_context_ready(
    process_context: ProcessContext,
    addons_manager: Optional[AddonsManager] = None,
    exit_on_failure: bool = True,
) -> bool:
    """Ensure all enabled addons are ready to be used in the given context.

    Call this method only in AYON launcher process and as first thing
        to avoid possible clashes with preparation. For example 'QApplication'
        should not be created.

    Todos:
        Run all preparations and allow to "ignore" failed preparations.
            Right now single addon can block using certain actions.

    Args:
        process_context (ProcessContext): The context in which the
            addons should be prepared.
        addons_manager (Optional[AddonsManager]): The addons
            manager to use. If not provided, a new one will be created.
        exit_on_failure (bool, optional): If True, the process will exit
            if an error occurs. Defaults to True.

    Returns:
        bool: True if all addons are ready, False otherwise.

    """
    if addons_manager is None:
        addons_manager = AddonsManager()

    message = None
    failed = False
    use_detail = False
    # Wrap the output in StringIO to capture it for details on fail
    # - but in case stdout was invalid on start of process also store
    #   the tracebacks
    tracebacks = []
    output = StringIO()
    with contextlib.redirect_stdout(output):
        with contextlib.redirect_stderr(output):
            for addon in addons_manager.get_enabled_addons():
                addon_failed = True
                try:
                    addon.ensure_is_process_ready(process_context)
                    addon_failed = False
                except ProcessPreparationError as exc:
                    message = str(exc)
                    print(f"Addon preparation failed: '{addon.name}'")
                    print(message)

                except BaseException:
                    use_detail = True
                    message = "An unexpected error occurred."
                    formatted_traceback = "".join(traceback.format_exception(
                        *sys.exc_info()
                    ))
                    tracebacks.append(formatted_traceback)
                    print(f"Addon preparation failed: '{addon.name}'")
                    print(message)
                    # Print the traceback so it is in the stdout
                    print(formatted_traceback)

                if addon_failed:
                    failed = True
                    break

    output_str = output.getvalue()
    # Print stdout/stderr to console as it was redirected
    print(output_str)
    if not failed:
        if not process_context.headless:
            _start_tray()
        return True

    detail = None
    if use_detail:
        # In case stdout was not captured, use the tracebacks as detail
        if not output_str:
            output_str = "\n".join(tracebacks)
        detail = output_str

    _handle_error(process_context, message, detail)
    if exit_on_failure:
        sys.exit(1)
    return False

ensure_addons_are_process_ready(addon_name, addon_version, project_name=None, headless=None, *, addons_manager=None, exit_on_failure=True, **kwargs)

Ensure all enabled addons are ready to be used in the given context.

Call this method only in AYON launcher process and as first thing to avoid possible clashes with preparation. For example 'QApplication' should not be created.

Parameters:

Name Type Description Default
addon_name str

Addon name which triggered process.

required
addon_version str

Addon version which triggered process.

required
project_name Optional[str]

Project name. Can be filled in case process is triggered for specific project. Some addons can have different behavior based on project. Value is NOT autofilled.

None
headless Optional[bool]

Is process running in headless mode. Value is filled with value based on state set in AYON launcher.

None
addons_manager Optional[AddonsManager]

The addons manager to use. If not provided, a new one will be created.

None
exit_on_failure bool

If True, the process will exit if an error occurs. Defaults to True.

True
kwargs

The keyword arguments to pass to the ProcessContext.

{}

Returns:

Name Type Description
bool bool

True if all addons are ready, False otherwise.

Source code in client/ayon_core/addon/utils.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def ensure_addons_are_process_ready(
    addon_name: str,
    addon_version: str,
    project_name: Optional[str] = None,
    headless: Optional[bool] = None,
    *,
    addons_manager: Optional[AddonsManager] = None,
    exit_on_failure: bool = True,
    **kwargs,
) -> bool:
    """Ensure all enabled addons are ready to be used in the given context.

    Call this method only in AYON launcher process and as first thing
        to avoid possible clashes with preparation. For example 'QApplication'
        should not be created.

    Args:
        addon_name (str): Addon name which triggered process.
        addon_version (str): Addon version which triggered process.
        project_name (Optional[str]): Project name. Can be filled in case
            process is triggered for specific project. Some addons can have
            different behavior based on project. Value is NOT autofilled.
        headless (Optional[bool]): Is process running in headless mode. Value
            is filled with value based on state set in AYON launcher.
        addons_manager (Optional[AddonsManager]): The addons
            manager to use. If not provided, a new one will be created.
        exit_on_failure (bool, optional): If True, the process will exit
            if an error occurs. Defaults to True.
        kwargs: The keyword arguments to pass to the ProcessContext.

    Returns:
        bool: True if all addons are ready, False otherwise.

    """
    context: ProcessContext = ProcessContext(
        addon_name,
        addon_version,
        project_name,
        headless,
        **kwargs
    )
    return ensure_addons_are_process_context_ready(
        context, addons_manager, exit_on_failure
    )