added one more ensure function for easier approach.

This commit is contained in:
Jakub Trllo 2024-07-30 14:59:28 +02:00
parent cb0dfc0bb9
commit f8e1b6eeb1
2 changed files with 33 additions and 2 deletions

View file

@ -17,6 +17,7 @@ from .base import (
)
from .utils import (
ensure_addons_are_process_context_ready,
ensure_addons_are_process_ready,
)
@ -36,5 +37,6 @@ __all__ = (
"AddonsManager",
"load_addons",
"ensure_addons_are_process_context_ready",
"ensure_addons_are_process_ready",
)

View file

@ -62,7 +62,7 @@ def _handle_error(
os.remove(tmp_path)
def ensure_addons_are_process_ready(
def ensure_addons_are_process_context_ready(
process_context: ProcessContext,
addons_manager: Optional[AddonsManager] = None,
exit_on_failure: bool = True,
@ -134,7 +134,7 @@ def ensure_addons_are_process_ready(
if failed:
detail = None
if use_detail:
# In case stdout was not captured, use the tracebacks
# In case stdout was not captured, use the tracebacks as detail
if not output_str:
output_str = "\n".join(tracebacks)
detail = output_str
@ -143,3 +143,32 @@ def ensure_addons_are_process_ready(
if not exit_on_failure:
return exception
sys.exit(1)
def ensure_addons_are_process_ready(
addons_manager: Optional[AddonsManager] = None,
exit_on_failure: bool = True,
**kwargs,
) -> Optional[Exception]:
"""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:
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:
Optional[Exception]: The exception that occurred during the
preparation, if any.
"""
context: ProcessContext = ProcessContext(**kwargs)
return ensure_addons_are_process_context_ready(
context, addons_manager, exit_on_failure
)