use settings summary to resolve which addon versions are used

This commit is contained in:
Jakub Trllo 2025-10-16 12:44:35 +02:00
parent 2cfb52ce02
commit 16d5fe45fc

View file

@ -2,7 +2,6 @@
"""Base class for AYON addons.""" """Base class for AYON addons."""
from __future__ import annotations from __future__ import annotations
import copy
import os import os
import sys import sys
import time import time
@ -13,6 +12,7 @@ import collections
import warnings import warnings
from uuid import uuid4 from uuid import uuid4
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from urllib.parse import urlencode
from types import ModuleType from types import ModuleType
import typing import typing
from typing import Optional, Any, Union from typing import Optional, Any, Union
@ -136,39 +136,47 @@ def load_addons(force: bool = False) -> None:
time.sleep(0.1) time.sleep(0.1)
def _get_ayon_bundle_data() -> Optional[dict[str, Any]]: def _get_ayon_bundle_data() -> tuple[
dict[str, Any], Optional[dict[str, Any]]
]:
studio_bundle_name = os.environ.get("AYON_STUDIO_BUNDLE_NAME") studio_bundle_name = os.environ.get("AYON_STUDIO_BUNDLE_NAME")
project_bundle_name = os.getenv("AYON_BUNDLE_NAME") project_bundle_name = os.getenv("AYON_BUNDLE_NAME")
bundles = ayon_api.get_bundles()["bundles"] bundles = ayon_api.get_bundles()["bundles"]
project_bundle = next( studio_bundle = next(
( (
bundle bundle
for bundle in bundles for bundle in bundles
if bundle["name"] == project_bundle_name if bundle["name"] == studio_bundle_name
), ),
None None
) )
studio_bundle = None
if studio_bundle_name and project_bundle_name != studio_bundle_name: if studio_bundle is None:
studio_bundle = next( raise RuntimeError(f"Failed to find bundle '{studio_bundle_name}'.")
project_bundle = None
if project_bundle_name and project_bundle_name != studio_bundle_name:
project_bundle = next(
( (
bundle bundle
for bundle in bundles for bundle in bundles
if bundle["name"] == studio_bundle_name if bundle["name"] == project_bundle_name
), ),
None None
) )
if project_bundle and studio_bundle: if project_bundle is None:
addons = copy.deepcopy(studio_bundle["addons"]) raise RuntimeError(
addons.update(project_bundle["addons"]) f"Failed to find project bundle '{project_bundle_name}'."
project_bundle["addons"] = addons )
return project_bundle
return studio_bundle, project_bundle
def _get_ayon_addons_information( def _get_ayon_addons_information(
bundle_info: dict[str, Any] studio_bundle: dict[str, Any],
) -> list[dict[str, Any]]: project_bundle: Optional[dict[str, Any]],
) -> dict[str, str]:
"""Receive information about addons to use from server. """Receive information about addons to use from server.
Todos: Todos:
@ -181,22 +189,20 @@ def _get_ayon_addons_information(
list[dict[str, Any]]: List of addon information to use. list[dict[str, Any]]: List of addon information to use.
""" """
output = [] key_values = {
bundle_addons = bundle_info["addons"] "summary": "true",
addons = ayon_api.get_addons_info()["addons"] "bundle_name": studio_bundle["name"],
for addon in addons: }
name = addon["name"] if project_bundle:
versions = addon.get("versions") key_values["project_bundle_name"] = project_bundle["name"]
addon_version = bundle_addons.get(name)
if addon_version is None or not versions: query = urlencode(key_values)
continue
version = versions.get(addon_version) response = ayon_api.get(f"settings?{query}")
if version: return {
version = copy.deepcopy(version) addon["name"]: addon["version"]
version["name"] = name for addon in response.data["addons"]
version["version"] = addon_version }
output.append(version)
return output
def _load_ayon_addons(log: logging.Logger) -> list[ModuleType]: def _load_ayon_addons(log: logging.Logger) -> list[ModuleType]:
@ -214,8 +220,8 @@ def _load_ayon_addons(log: logging.Logger) -> list[ModuleType]:
""" """
all_addon_modules = [] all_addon_modules = []
bundle_info = _get_ayon_bundle_data() studio_bundle, project_bundle = _get_ayon_bundle_data()
addons_info = _get_ayon_addons_information(bundle_info) addons_info = _get_ayon_addons_information(studio_bundle, project_bundle)
if not addons_info: if not addons_info:
return all_addon_modules return all_addon_modules
@ -227,17 +233,16 @@ def _load_ayon_addons(log: logging.Logger) -> list[ModuleType]:
dev_addons_info = {} dev_addons_info = {}
if dev_mode_enabled: if dev_mode_enabled:
# Get dev addons info only when dev mode is enabled # Get dev addons info only when dev mode is enabled
dev_addons_info = bundle_info.get("addonDevelopment", dev_addons_info) dev_addons_info = studio_bundle.get(
"addonDevelopment", dev_addons_info
)
addons_dir_exists = os.path.exists(addons_dir) addons_dir_exists = os.path.exists(addons_dir)
if not addons_dir_exists: if not addons_dir_exists:
log.warning( log.warning(
f"Addons directory does not exists. Path \"{addons_dir}\"") f"Addons directory does not exists. Path \"{addons_dir}\"")
for addon_info in addons_info: for addon_name, addon_version in addons_info.items():
addon_name = addon_info["name"]
addon_version = addon_info["version"]
# core addon does not have any addon object # core addon does not have any addon object
if addon_name == "core": if addon_name == "core":
continue continue