diff --git a/api/addons/__init__.py b/api/addons/__init__.py index 1ef9fda8..d2ada442 100644 --- a/api/addons/__init__.py +++ b/api/addons/__init__.py @@ -32,10 +32,12 @@ def register_addon_endpoints(): tags=[f"{addon_name} {addon_version}"], ) - library = AddonLibrary.getinstance() - for addon_name, addon_definition in library.items(): - for version in addon_definition.versions: - addon = addon_definition.versions[version] + for addon_name, addon_definition in addons_library.items(): + for package in addon_definition.iter_packages(): + version = package.version + addon = addons_library.addon(addon_name, version) + print(addon) + print(type(addon)) addon_router = APIRouter( prefix=f"/{addon_name}/{version}", tags=[f"{addon_definition.friendly_name} {version}"], @@ -102,15 +104,13 @@ async def list_addons( active_versions = await addon_library.get_active_versions() for addon_name, addon_version_dict in addon_library.get_available_addons().items(): - addon_active_versions = active_versions.get(addon_name) + addon_active_versions = active_versions.get(addon_name, {}) - if not addon_active_versions: - addon = addon_library.addon(addon_name, addon_version_dict["latest"].version) + if addon_active_versions and addon_active_versions["production"] is not None: + addon = addon_library.addon(addon_name, str(addon_active_versions["production"])) else: - addon = addon_library.addon(addon_name, addon_active_versions["production"]) - logging.error(f"ADDON IS {addon} ({type(addon)})") - - addon_version_dict.pop("latest") + latest_version = addon_library.get_latest_version(addon_name) + addon = addon_library.addon(addon_name, str(latest_version.version)) versions = {} @@ -137,11 +137,10 @@ async def list_addons( vinf["services"] = addon.services or None versions[version_number] = VersionInfo(**vinf) - logging.error(f"Version is: {versions[version_number]}") result.append( AddonListItem( - name=addon.name, + name=addon_name, title=addon.friendly_name, versions=versions, description=addon.__doc__ or "", diff --git a/api/addons/common.py b/api/addons/common.py index 4b9fc130..d4bfa686 100644 --- a/api/addons/common.py +++ b/api/addons/common.py @@ -22,7 +22,8 @@ async def remove_override( variant: str = "production", project_name: str | None = None, ): - if (addon := AddonLibrary.addon(addon_name, addon_version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, addon_version)) is None: raise NotFoundException(f"Addon {addon_name} {addon_version} not found") # TODO: ensure the path is not a part of a group @@ -62,7 +63,8 @@ async def pin_override( variant: str = "production", project_name: str | None = None, ): - if (addon := AddonLibrary.addon(addon_name, addon_version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, addon_version)) is None: raise NotFoundException(f"Addon {addon_name} {addon_version} not found") if project_name: @@ -136,7 +138,8 @@ async def remove_site_override( user_name: str, path: list[str], ): - if (addon := AddonLibrary.addon(addon_name, addon_version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, addon_version)) is None: raise NotFoundException(f"Addon {addon_name} {addon_version} not found") overrides = await addon.get_project_site_overrides(project_name, user_name, site_id) @@ -171,7 +174,8 @@ async def pin_site_override( user_name: str, path: list[str], ): - if (addon := AddonLibrary.addon(addon_name, addon_version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, addon_version)) is None: raise NotFoundException(f"Addon {addon_name} {addon_version} not found") overrides = await addon.get_project_site_overrides(project_name, user_name, site_id) diff --git a/api/addons/project_settings.py b/api/addons/project_settings.py index db40d11b..fce1b3e3 100644 --- a/api/addons/project_settings.py +++ b/api/addons/project_settings.py @@ -41,8 +41,8 @@ async def get_addon_project_settings_schema( site: str | None = Query(None, regex="^[a-z0-9-]+$"), ) -> dict[str, Any]: """Return the JSON schema of the addon settings.""" - - if (addon := AddonLibrary.addon(addon_name, version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, version)) is None: raise NotFoundException(f"Addon {addon_name} {version} not found") model = addon.get_settings_model() @@ -76,7 +76,9 @@ async def get_addon_project_settings( variant: str = Query("production"), site: str | None = Query(None, regex="^[a-z0-9-]+$"), ) -> dict[str, Any]: - if (addon := AddonLibrary.addon(addon_name, version)) is None: + + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, version)) is None: raise NotFoundException(f"Addon {addon_name} {version} not found") if site: @@ -98,7 +100,8 @@ async def get_addon_project_overrides( variant: str = Query("production"), site: str | None = Query(None, regex="^[a-z0-9-]+$"), ): - addon = AddonLibrary.addon(addon_name, version) + addon_library = AddonLibrary() + addon = addon_library.addon(addon_name, version) studio_settings = await addon.get_studio_settings(variant=variant) if studio_settings is None: return {} @@ -140,7 +143,8 @@ async def set_addon_project_settings( ) -> EmptyResponse: """Set the studio overrides of the given addon.""" - addon = AddonLibrary.addon(addon_name, version) + addon_library = AddonLibrary() + addon = addon_library.addon(addon_name, version) model = addon.get_settings_model() if model is None: raise BadRequestException(f"Addon {addon_name} has no settings") @@ -237,7 +241,8 @@ async def delete_addon_project_overrides( site: str | None = Query(None, regex="^[a-z0-9-]+$"), ): # Ensure the addon and the project exist - _ = AddonLibrary.addon(addon_name, version) + addon_library = AddonLibrary() + _ = addon_library.addon(addon_name, version) _ = await ProjectEntity.load(project_name) if not site: diff --git a/api/addons/site_settings.py b/api/addons/site_settings.py index f1f4411a..2bd2eb3e 100644 --- a/api/addons/site_settings.py +++ b/api/addons/site_settings.py @@ -19,8 +19,8 @@ async def get_addon_site_settings_schema( user: CurrentUser, ) -> dict[str, Any]: """Return the JSON schema of the addon site settings.""" - - if (addon := AddonLibrary.addon(addon_name, version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, version)) is None: raise NotFoundException(f"Addon {addon_name} {version} not found") model = addon.get_site_settings_model() @@ -47,8 +47,8 @@ async def get_addon_site_settings( site: str = Query(...), ) -> dict[str, Any]: """Return the JSON schema of the addon site settings.""" - - if (addon := AddonLibrary.addon(addon_name, version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, version)) is None: raise NotFoundException(f"Addon {addon_name} {version} not found") model = addon.get_site_settings_model() @@ -77,7 +77,8 @@ async def set_addon_site_settings( user: CurrentUser, site: str = Query(..., title="Site ID", regex="^[a-z0-9-]+$"), ) -> EmptyResponse: - if (addon := AddonLibrary.addon(addon_name, version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, version)) is None: raise NotFoundException(f"Addon {addon_name} {version} not found") model = addon.get_site_settings_model() diff --git a/api/addons/studio_settings.py b/api/addons/studio_settings.py index 311b39e9..80c0763f 100644 --- a/api/addons/studio_settings.py +++ b/api/addons/studio_settings.py @@ -31,8 +31,8 @@ async def get_addon_settings_schema( user: CurrentUser, ) -> dict[str, Any]: """Return the JSON schema of the addon settings.""" - - if (addon := AddonLibrary.addon(addon_name, addon_version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, addon_version)) is None: raise NotFoundException(f"Addon {addon_name} {addon_version} not found") model = addon.get_settings_model() @@ -58,8 +58,8 @@ async def get_addon_studio_settings( variant: str = Query("production"), ) -> dict[str, Any]: """Return the settings (including studio overrides) of the given addon.""" - - if (addon := AddonLibrary.addon(addon_name, addon_version)) is None: + addon_library = AddonLibrary() + if (addon := addon_library.addon(addon_name, addon_version)) is None: raise NotFoundException(f"Addon {addon_name} {addon_version} not found") settings = await addon.get_studio_settings(variant=variant) @@ -80,8 +80,8 @@ async def set_addon_studio_settings( if not user.is_manager: raise ForbiddenException - - addon = AddonLibrary.addon(addon_name, addon_version) + addon_library = AddonLibrary() + addon = addon_library.addon(addon_name, addon_version) original = await addon.get_studio_settings(variant=variant) existing = await addon.get_studio_overrides(variant=variant) model = addon.get_settings_model() @@ -138,8 +138,8 @@ async def get_addon_studio_overrides( ): if not user.is_manager: raise ForbiddenException - - addon = AddonLibrary.addon(addon_name, addon_version) + addon_library = AddonLibrary() + addon = addon_library.addon(addon_name, addon_version) settings = await addon.get_studio_settings(variant=variant) if settings is None: return {} @@ -160,7 +160,8 @@ async def delete_addon_studio_overrides( raise ForbiddenException # Ensure addon exists - _ = AddonLibrary.addon(addon_name, addon_version) + addon_library = AddonLibrary() + _ = addon_library.addon(addon_name, addon_version) await Postgres.execute( """ diff --git a/ayon_server/addons/__init__.py b/ayon_server/addons/__init__.py index 0fcbc7df..952f8387 100644 --- a/ayon_server/addons/__init__.py +++ b/ayon_server/addons/__init__.py @@ -2,5 +2,5 @@ from ayon_server.addons.addon import BaseServerAddon from ayon_server.addons.definition import ServerAddonDefinition -from ayon_server.addons.library import AddonLibrary +from ayon_server.addons.rezlibrary import RezRepo as AddonLibrary from ayon_server.addons.models import SSOOption diff --git a/ayon_server/addons/addon.py b/ayon_server/addons/addon.py index 35753c96..bd1e978a 100644 --- a/ayon_server/addons/addon.py +++ b/ayon_server/addons/addon.py @@ -46,7 +46,7 @@ def __repr__(self) -> str: @property def friendly_name(self) -> str: """Return the friendly name of the addon.""" - return f"{self.definition.friendly_name} {self.version}" + return f"{self.name.capitalize()}" def initialize(self) -> None: """Initialize the addon. diff --git a/ayon_server/addons/rezlibrary.py b/ayon_server/addons/rezlibrary.py index 22964b9f..555780ce 100644 --- a/ayon_server/addons/rezlibrary.py +++ b/ayon_server/addons/rezlibrary.py @@ -2,17 +2,11 @@ from pathlib import Path from typing import ItemsView -<<<<<<< HEAD from nxtools import logging, slugify from rez.exceptions import PackageFamilyNotFoundError from rez.packages import Package, PackageFamily, get_package, get_latest_package from rez.package_repository import package_repository_manager from rez.package_search import get_plugins -======= -from nxtools import log_traceback, logging -from rez.packages import PackageFamily, get_latest_package, get_plugins -from rez.package_repository import package_repository_manager ->>>>>>> d829e4c (Improved the Rez library intitialization) from ayon_server.addons.addon import BaseServerAddon from ayon_server.addons.utils import classes_from_module, import_module @@ -105,7 +99,6 @@ def _init_addon_from_rez_package(self, module_name, rez_package): except AttributeError as e: logging.error(f"Addon {module_name} - {module_init_path} is not a valid Python module.") raise e - # It makes little sense to allow several addons from one init, # since they would be separate rez-packages addon_class = next(iter(classes_from_module(BaseServerAddon, addon_module)), None) @@ -139,18 +132,13 @@ def addon(self, addon_name, addon_version): if not addon: # Attempt to find it and initialize it - logging.error(f"PACKAGES ARE: {self.packages}") - logging.error(f"ADDON NAME: {addon_name}") - logging.error(f"IN PKGS: {self.packages.get(addon_name)}") - logging.error(f"ADDON VERSION: {addon_version}") - logging.error(f"IN PKGS: {self.packages[addon_name].get(addon_version)}") addon_package = self.packages.get(addon_name, {}).get(addon_version, None) if not addon_package: raise NotFoundException(f"Unable to find addon {addon_name}-{addon_version}") try: - addon = self.init_addon_from_rez_package_addon( + addon = self._init_addon_from_rez_package( module_name, addon_package ) diff --git a/ayon_server/api/server.py b/ayon_server/api/server.py index c967133c..df89372c 100644 --- a/ayon_server/api/server.py +++ b/ayon_server/api/server.py @@ -390,6 +390,7 @@ async def startup_event() -> None: start_event = await dispatch_event("server.started", finished=False) library = AddonLibrary() + if library.restart_requested: logging.warning("Restart requested, skipping addon setup") await dispatch_event( diff --git a/ayon_server/config.py b/ayon_server/config.py index 3ef1c5d0..a5ce917d 100644 --- a/ayon_server/config.py +++ b/ayon_server/config.py @@ -29,7 +29,7 @@ class AyonConfig(BaseModel): ) rez_dir: str = Field( - default="/rezrepo", + default="/addons", description="Path to the directory containing the Rez repository.", ) diff --git a/rezrepo/ayon_shotgrid/1.0.0/build.rxt b/rezrepo/ayon_shotgrid/1.0.0/build.rxt deleted file mode 100644 index f911e254..00000000 --- a/rezrepo/ayon_shotgrid/1.0.0/build.rxt +++ /dev/null @@ -1,84 +0,0 @@ -{ - "append_sys_path": true, - "arch": "x86_64", - "building": true, - "caching": true, - "created": 1684342689, - "default_patch_lock": "no_lock", - "failure_description": null, - "from_cache": false, - "graph": "{'nodes': [((('fillcolor', '#FFFFAA'), ('fontsize', 10), ('style', 'filled,dashed')), [('_1', 'python'), ('_2', '~platform==linux'), ('_3', '~arch==x86_64'), ('_4', '~os==Fedora-37')]), ((('fillcolor', '#AAFFAA'), ('fontsize', 10), ('style', 'filled')), [('_5', 'platform-linux[]'), ('_6', 'arch-x86_64[]'), ('_7', 'os-Fedora-37[]'), ('_8', 'python-3.10.11[0]')]), ((('fillcolor', '#F6F6F6'), ('fontsize', 10), ('style', 'filled,dashed')), [('_9', 'platform-linux'), ('_10', 'arch-x86_64'), ('_11', 'os-Fedora-37')])], 'edges': [((('arrowsize', '0.5'),), [('_1', '_8'), ('_2', '_5'), ('_3', '_6'), ('_4', '_7'), ('_7', '_10'), ('_7', '_9'), ('_8', '_10'), ('_8', '_11'), ('_8', '_9'), ('_9', '_5'), ('_10', '_6'), ('_11', '_7')])]}", - "host": "fuchikoma", - "implicit_packages": [ - "~platform==linux", - "~arch==x86_64", - "~os==Fedora-37" - ], - "load_time": 0.0, - "num_loaded_packages": 4, - "os": "Fedora-37", - "package_caching": false, - "package_filter": [], - "package_orderers": null, - "package_paths": [ - "/home/minkiu/Projects/ASWF/rez/repo" - ], - "package_requests": [ - "python" - ], - "parent_suite_path": null, - "patch_locks": {}, - "platform": "linux", - "requested_timestamp": null, - "resolved_ephemerals": [], - "resolved_packages": [ - { - "key": "filesystem.variant", - "variables": { - "index": null, - "location": "/home/minkiu/Projects/ASWF/rez/repo", - "name": "platform", - "repository_type": "filesystem", - "version": "linux" - } - }, - { - "key": "filesystem.variant", - "variables": { - "index": null, - "location": "/home/minkiu/Projects/ASWF/rez/repo", - "name": "arch", - "repository_type": "filesystem", - "version": "x86_64" - } - }, - { - "key": "filesystem.variant", - "variables": { - "index": null, - "location": "/home/minkiu/Projects/ASWF/rez/repo", - "name": "os", - "repository_type": "filesystem", - "version": "Fedora-37" - } - }, - { - "key": "filesystem.variant", - "variables": { - "index": 0, - "location": "/home/minkiu/Projects/ASWF/rez/repo", - "name": "python", - "repository_type": "filesystem", - "version": "3.10.11" - } - } - ], - "rez_path": "/home/minkiu/Projects/ASWF/rez-install/lib/python3.10/site-packages/rez", - "rez_version": "2.112.0", - "serialize_version": "4.7", - "solve_time": 0.004936933517456055, - "status": "solved", - "suite_context_name": null, - "timestamp": 1684342689, - "user": "minkiu" -} \ No newline at end of file diff --git a/rezrepo/ayon_shotgrid/1.0.0/package.py b/rezrepo/ayon_shotgrid/1.0.0/package.py deleted file mode 100644 index e3cbdbfc..00000000 --- a/rezrepo/ayon_shotgrid/1.0.0/package.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- - -name = 'ayon_shotgrid' - -version = '1.0.0' - -description = 'AYON Shotgrid integration.' - -requires = ['python'] - -def commands(): - env.PYTHONPATH.append("{root}/python") - -timestamp = 1684342689 - -format_version = 2 diff --git a/rezrepo/ayon_shotgrid/1.0.1/build.rxt b/rezrepo/ayon_shotgrid/1.0.1/build.rxt deleted file mode 100644 index 19f12cc6..00000000 --- a/rezrepo/ayon_shotgrid/1.0.1/build.rxt +++ /dev/null @@ -1,84 +0,0 @@ -{ - "append_sys_path": true, - "arch": "x86_64", - "building": true, - "caching": true, - "created": 1684342715, - "default_patch_lock": "no_lock", - "failure_description": null, - "from_cache": false, - "graph": "{'nodes': [((('fillcolor', '#FFFFAA'), ('fontsize', 10), ('style', 'filled,dashed')), [('_1', 'python'), ('_2', '~platform==linux'), ('_3', '~arch==x86_64'), ('_4', '~os==Fedora-37')]), ((('fillcolor', '#AAFFAA'), ('fontsize', 10), ('style', 'filled')), [('_5', 'platform-linux[]'), ('_6', 'arch-x86_64[]'), ('_7', 'os-Fedora-37[]'), ('_8', 'python-3.10.11[0]')]), ((('fillcolor', '#F6F6F6'), ('fontsize', 10), ('style', 'filled,dashed')), [('_9', 'platform-linux'), ('_10', 'arch-x86_64'), ('_11', 'os-Fedora-37')])], 'edges': [((('arrowsize', '0.5'),), [('_1', '_8'), ('_2', '_5'), ('_3', '_6'), ('_4', '_7'), ('_7', '_10'), ('_7', '_9'), ('_8', '_10'), ('_8', '_11'), ('_8', '_9'), ('_9', '_5'), ('_10', '_6'), ('_11', '_7')])]}", - "host": "fuchikoma", - "implicit_packages": [ - "~platform==linux", - "~arch==x86_64", - "~os==Fedora-37" - ], - "load_time": 0.0, - "num_loaded_packages": 4, - "os": "Fedora-37", - "package_caching": false, - "package_filter": [], - "package_orderers": null, - "package_paths": [ - "/home/minkiu/Projects/ASWF/rez/repo" - ], - "package_requests": [ - "python" - ], - "parent_suite_path": null, - "patch_locks": {}, - "platform": "linux", - "requested_timestamp": null, - "resolved_ephemerals": [], - "resolved_packages": [ - { - "key": "filesystem.variant", - "variables": { - "index": null, - "location": "/home/minkiu/Projects/ASWF/rez/repo", - "name": "platform", - "repository_type": "filesystem", - "version": "linux" - } - }, - { - "key": "filesystem.variant", - "variables": { - "index": null, - "location": "/home/minkiu/Projects/ASWF/rez/repo", - "name": "arch", - "repository_type": "filesystem", - "version": "x86_64" - } - }, - { - "key": "filesystem.variant", - "variables": { - "index": null, - "location": "/home/minkiu/Projects/ASWF/rez/repo", - "name": "os", - "repository_type": "filesystem", - "version": "Fedora-37" - } - }, - { - "key": "filesystem.variant", - "variables": { - "index": 0, - "location": "/home/minkiu/Projects/ASWF/rez/repo", - "name": "python", - "repository_type": "filesystem", - "version": "3.10.11" - } - } - ], - "rez_path": "/home/minkiu/Projects/ASWF/rez-install/lib/python3.10/site-packages/rez", - "rez_version": "2.112.0", - "serialize_version": "4.7", - "solve_time": 0.0068781375885009766, - "status": "solved", - "suite_context_name": null, - "timestamp": 1684342714, - "user": "minkiu" -} \ No newline at end of file diff --git a/rezrepo/ayon_shotgrid/1.0.1/package.py b/rezrepo/ayon_shotgrid/1.0.1/package.py deleted file mode 100644 index 06bf5faf..00000000 --- a/rezrepo/ayon_shotgrid/1.0.1/package.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- - -name = 'ayon_shotgrid' - -version = '1.0.1' - -description = 'AYON Shotgrid integration.' - -requires = ['python'] - -def commands(): - env.PYTHONPATH.append("{root}/python") - -timestamp = 1684342715 - -format_version = 2