mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 12:54:40 +01:00
Merge pull request #1326 from ynput/enhancement/per-project-bundle
Chore: Per project bundle
This commit is contained in:
commit
912f920c28
6 changed files with 186 additions and 38 deletions
|
|
@ -156,18 +156,33 @@ def load_addons(force=False):
|
|||
|
||||
|
||||
def _get_ayon_bundle_data():
|
||||
studio_bundle_name = os.environ.get("AYON_STUDIO_BUNDLE_NAME")
|
||||
project_bundle_name = os.getenv("AYON_BUNDLE_NAME")
|
||||
bundles = ayon_api.get_bundles()["bundles"]
|
||||
|
||||
bundle_name = os.getenv("AYON_BUNDLE_NAME")
|
||||
|
||||
return next(
|
||||
project_bundle = next(
|
||||
(
|
||||
bundle
|
||||
for bundle in bundles
|
||||
if bundle["name"] == bundle_name
|
||||
if bundle["name"] == project_bundle_name
|
||||
),
|
||||
None
|
||||
)
|
||||
studio_bundle = None
|
||||
if studio_bundle_name and project_bundle_name != studio_bundle_name:
|
||||
studio_bundle = next(
|
||||
(
|
||||
bundle
|
||||
for bundle in bundles
|
||||
if bundle["name"] == studio_bundle_name
|
||||
),
|
||||
None
|
||||
)
|
||||
|
||||
if project_bundle and studio_bundle:
|
||||
addons = copy.deepcopy(studio_bundle["addons"])
|
||||
addons.update(project_bundle["addons"])
|
||||
project_bundle["addons"] = addons
|
||||
return project_bundle
|
||||
|
||||
|
||||
def _get_ayon_addons_information(bundle_info):
|
||||
|
|
|
|||
|
|
@ -27,25 +27,40 @@ from ayon_core.lib.env_tools import (
|
|||
|
||||
@click.group(invoke_without_command=True)
|
||||
@click.pass_context
|
||||
@click.option("--use-staging", is_flag=True,
|
||||
expose_value=False, help="use staging variants")
|
||||
@click.option("--debug", is_flag=True, expose_value=False,
|
||||
help="Enable debug")
|
||||
@click.option("--verbose", expose_value=False,
|
||||
help=("Change AYON log level (debug - critical or 0-50)"))
|
||||
@click.option("--force", is_flag=True, hidden=True)
|
||||
def main_cli(ctx, force):
|
||||
@click.option(
|
||||
"--use-staging",
|
||||
is_flag=True,
|
||||
expose_value=False,
|
||||
help="use staging variants")
|
||||
@click.option(
|
||||
"--debug",
|
||||
is_flag=True,
|
||||
expose_value=False,
|
||||
help="Enable debug")
|
||||
@click.option(
|
||||
"--project",
|
||||
help="Project name")
|
||||
@click.option(
|
||||
"--verbose",
|
||||
expose_value=False,
|
||||
help="Change AYON log level (debug - critical or 0-50)")
|
||||
@click.option(
|
||||
"--use-dev",
|
||||
is_flag=True,
|
||||
expose_value=False,
|
||||
help="use dev bundle")
|
||||
def main_cli(ctx, *_args, **_kwargs):
|
||||
"""AYON is main command serving as entry point to pipeline system.
|
||||
|
||||
It wraps different commands together.
|
||||
"""
|
||||
|
||||
if ctx.invoked_subcommand is None:
|
||||
# Print help if headless mode is used
|
||||
if os.getenv("AYON_HEADLESS_MODE") == "1":
|
||||
print(ctx.get_help())
|
||||
sys.exit(0)
|
||||
else:
|
||||
ctx.params.pop("project")
|
||||
ctx.forward(tray)
|
||||
|
||||
|
||||
|
|
@ -60,7 +75,6 @@ def tray(force):
|
|||
Default action of AYON command is to launch tray widget to control basic
|
||||
aspects of AYON. See documentation for more information.
|
||||
"""
|
||||
|
||||
from ayon_core.tools.tray import main
|
||||
|
||||
main(force)
|
||||
|
|
@ -306,6 +320,43 @@ def _add_addons(addons_manager):
|
|||
)
|
||||
|
||||
|
||||
def _cleanup_project_args():
|
||||
rem_args = list(sys.argv[1:])
|
||||
if "--project" not in rem_args:
|
||||
return
|
||||
|
||||
cmd = None
|
||||
current_ctx = None
|
||||
parent_name = "ayon"
|
||||
parent_cmd = main_cli
|
||||
while hasattr(parent_cmd, "resolve_command"):
|
||||
if current_ctx is None:
|
||||
current_ctx = main_cli.make_context(parent_name, rem_args)
|
||||
else:
|
||||
current_ctx = parent_cmd.make_context(
|
||||
parent_name,
|
||||
rem_args,
|
||||
parent=current_ctx
|
||||
)
|
||||
if not rem_args:
|
||||
break
|
||||
cmd_name, cmd, rem_args = parent_cmd.resolve_command(
|
||||
current_ctx, rem_args
|
||||
)
|
||||
parent_name = cmd_name
|
||||
parent_cmd = cmd
|
||||
|
||||
if cmd is None:
|
||||
return
|
||||
|
||||
param_names = {param.name for param in cmd.params}
|
||||
if "project" in param_names:
|
||||
return
|
||||
idx = sys.argv.index("--project")
|
||||
sys.argv.pop(idx)
|
||||
sys.argv.pop(idx)
|
||||
|
||||
|
||||
def main(*args, **kwargs):
|
||||
logging.basicConfig()
|
||||
|
||||
|
|
@ -332,10 +383,14 @@ def main(*args, **kwargs):
|
|||
addons_manager = AddonsManager()
|
||||
_set_addons_environments(addons_manager)
|
||||
_add_addons(addons_manager)
|
||||
|
||||
_cleanup_project_args()
|
||||
|
||||
try:
|
||||
main_cli(
|
||||
prog_name="ayon",
|
||||
obj={"addons_manager": addons_manager},
|
||||
args=(sys.argv[1:]),
|
||||
)
|
||||
except Exception: # noqa
|
||||
exc_info = sys.exc_info()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import collections
|
|||
import copy
|
||||
import time
|
||||
import warnings
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import ayon_api
|
||||
|
||||
|
|
@ -36,6 +37,37 @@ class CacheItem:
|
|||
return time.time() > self._outdate_time
|
||||
|
||||
|
||||
def _get_addons_settings(
|
||||
studio_bundle_name,
|
||||
project_bundle_name,
|
||||
variant,
|
||||
project_name=None,
|
||||
):
|
||||
"""Modified version of `ayon_api.get_addons_settings` function."""
|
||||
query_values = {
|
||||
key: value
|
||||
for key, value in (
|
||||
("bundle_name", studio_bundle_name),
|
||||
("variant", variant),
|
||||
("project_name", project_name),
|
||||
)
|
||||
if value
|
||||
}
|
||||
if project_bundle_name != studio_bundle_name:
|
||||
query_values["project_bundle_name"] = project_bundle_name
|
||||
|
||||
site_id = ayon_api.get_site_id()
|
||||
if site_id:
|
||||
query_values["site_id"] = site_id
|
||||
|
||||
response = ayon_api.get(f"settings?{urlencode(query_values)}")
|
||||
response.raise_for_status()
|
||||
return {
|
||||
addon["name"]: addon["settings"]
|
||||
for addon in response.data["addons"]
|
||||
}
|
||||
|
||||
|
||||
class _AyonSettingsCache:
|
||||
use_bundles = None
|
||||
variant = None
|
||||
|
|
@ -68,53 +100,70 @@ class _AyonSettingsCache:
|
|||
return _AyonSettingsCache.variant
|
||||
|
||||
@classmethod
|
||||
def _get_bundle_name(cls):
|
||||
def _get_studio_bundle_name(cls):
|
||||
bundle_name = os.environ.get("AYON_STUDIO_BUNDLE_NAME")
|
||||
if bundle_name:
|
||||
return bundle_name
|
||||
return os.environ["AYON_BUNDLE_NAME"]
|
||||
|
||||
@classmethod
|
||||
def _get_project_bundle_name(cls):
|
||||
return os.environ["AYON_BUNDLE_NAME"]
|
||||
|
||||
@classmethod
|
||||
def get_value_by_project(cls, project_name):
|
||||
cache_item = _AyonSettingsCache.cache_by_project_name[project_name]
|
||||
if cache_item.is_outdated:
|
||||
if cls._use_bundles():
|
||||
value = ayon_api.get_addons_settings(
|
||||
bundle_name=cls._get_bundle_name(),
|
||||
cache_item.update_value(
|
||||
_get_addons_settings(
|
||||
studio_bundle_name=cls._get_studio_bundle_name(),
|
||||
project_bundle_name=cls._get_project_bundle_name(),
|
||||
project_name=project_name,
|
||||
variant=cls._get_variant()
|
||||
variant=cls._get_variant(),
|
||||
)
|
||||
else:
|
||||
value = ayon_api.get_addons_settings(project_name)
|
||||
cache_item.update_value(value)
|
||||
)
|
||||
return cache_item.get_value()
|
||||
|
||||
@classmethod
|
||||
def _get_addon_versions_from_bundle(cls):
|
||||
expected_bundle = cls._get_bundle_name()
|
||||
studio_bundle_name = cls._get_studio_bundle_name()
|
||||
project_bundle_name = cls._get_project_bundle_name()
|
||||
bundles = ayon_api.get_bundles()["bundles"]
|
||||
bundle = next(
|
||||
project_bundle = next(
|
||||
(
|
||||
bundle
|
||||
for bundle in bundles
|
||||
if bundle["name"] == expected_bundle
|
||||
if bundle["name"] == project_bundle_name
|
||||
),
|
||||
None
|
||||
)
|
||||
if bundle is not None:
|
||||
return bundle["addons"]
|
||||
studio_bundle = None
|
||||
if studio_bundle_name and project_bundle_name != studio_bundle_name:
|
||||
studio_bundle = next(
|
||||
(
|
||||
bundle
|
||||
for bundle in bundles
|
||||
if bundle["name"] == studio_bundle_name
|
||||
),
|
||||
None
|
||||
)
|
||||
|
||||
if studio_bundle and project_bundle:
|
||||
addons = copy.deepcopy(studio_bundle["addons"])
|
||||
addons.update(project_bundle["addons"])
|
||||
project_bundle["addons"] = addons
|
||||
|
||||
if project_bundle is not None:
|
||||
return project_bundle["addons"]
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def get_addon_versions(cls):
|
||||
cache_item = _AyonSettingsCache.addon_versions
|
||||
if cache_item.is_outdated:
|
||||
if cls._use_bundles():
|
||||
addons = cls._get_addon_versions_from_bundle()
|
||||
else:
|
||||
settings_data = ayon_api.get_addons_settings(
|
||||
only_values=False,
|
||||
variant=cls._get_variant()
|
||||
)
|
||||
addons = settings_data["versions"]
|
||||
cache_item.update_value(addons)
|
||||
cache_item.update_value(
|
||||
cls._get_addon_versions_from_bundle()
|
||||
)
|
||||
|
||||
return cache_item.get_value()
|
||||
|
||||
|
|
|
|||
|
|
@ -517,7 +517,12 @@ class ActionsModel:
|
|||
uri = payload["uri"]
|
||||
else:
|
||||
uri = data["uri"]
|
||||
run_detached_ayon_launcher_process(uri)
|
||||
|
||||
# Remove bundles from environment variables
|
||||
env = os.environ.copy()
|
||||
env.pop("AYON_BUNDLE_NAME", None)
|
||||
env.pop("AYON_STUDIO_BUNDLE_NAME", None)
|
||||
run_detached_ayon_launcher_process(uri, env=env)
|
||||
|
||||
elif response_type in ("query", "navigate"):
|
||||
response.error_message = (
|
||||
|
|
|
|||
|
|
@ -240,6 +240,16 @@ class TrayManager:
|
|||
self.log.warning("Other tray started meanwhile. Exiting.")
|
||||
self.exit()
|
||||
|
||||
project_bundle = os.getenv("AYON_BUNDLE_NAME")
|
||||
studio_bundle = os.getenv("AYON_STUDIO_BUNDLE_NAME")
|
||||
if studio_bundle and project_bundle != studio_bundle:
|
||||
self.log.info(
|
||||
f"Project bundle '{project_bundle}' is defined, but tray"
|
||||
" cannot be running in project scope. Restarting tray to use"
|
||||
" studio bundle."
|
||||
)
|
||||
self.restart()
|
||||
|
||||
def get_services_submenu(self):
|
||||
return self._services_submenu
|
||||
|
||||
|
|
@ -270,11 +280,18 @@ class TrayManager:
|
|||
elif is_staging_enabled():
|
||||
additional_args.append("--use-staging")
|
||||
|
||||
if "--project" in additional_args:
|
||||
idx = additional_args.index("--project")
|
||||
additional_args.pop(idx)
|
||||
additional_args.pop(idx)
|
||||
|
||||
args.extend(additional_args)
|
||||
|
||||
envs = dict(os.environ.items())
|
||||
for key in {
|
||||
"AYON_BUNDLE_NAME",
|
||||
"AYON_STUDIO_BUNDLE_NAME",
|
||||
"AYON_PROJECT_NAME",
|
||||
}:
|
||||
envs.pop(key, None)
|
||||
|
||||
|
|
@ -329,6 +346,7 @@ class TrayManager:
|
|||
return json_response({
|
||||
"username": self._cached_username,
|
||||
"bundle": os.getenv("AYON_BUNDLE_NAME"),
|
||||
"studio_bundle": os.getenv("AYON_STUDIO_BUNDLE_NAME"),
|
||||
"dev_mode": is_dev_mode_enabled(),
|
||||
"staging_mode": is_staging_enabled(),
|
||||
"addons": {
|
||||
|
|
@ -516,6 +534,8 @@ class TrayManager:
|
|||
"AYON_SERVER_URL",
|
||||
"AYON_API_KEY",
|
||||
"AYON_BUNDLE_NAME",
|
||||
"AYON_STUDIO_BUNDLE_NAME",
|
||||
"AYON_PROJECT_NAME",
|
||||
}:
|
||||
os.environ.pop(key, None)
|
||||
self.restart()
|
||||
|
|
@ -549,6 +569,8 @@ class TrayManager:
|
|||
envs = dict(os.environ.items())
|
||||
for key in {
|
||||
"AYON_BUNDLE_NAME",
|
||||
"AYON_STUDIO_BUNDLE_NAME",
|
||||
"AYON_PROJECT_NAME",
|
||||
}:
|
||||
envs.pop(key, None)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ client_dir = "ayon_core"
|
|||
|
||||
plugin_for = ["ayon_server"]
|
||||
|
||||
project_can_override_addon_version = True
|
||||
|
||||
ayon_server_version = ">=1.8.4,<2.0.0"
|
||||
ayon_launcher_version = ">=1.0.2"
|
||||
ayon_required_addons = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue