Skip to content

Commit

Permalink
Merge pull request #72 from ynput/enhancement/binary_distribution_beh…
Browse files Browse the repository at this point in the history
…ind_toggles

Make LakeFS distribution of USD Libs and AYON USD Resolver optional
  • Loading branch information
BigRoy authored Oct 28, 2024
2 parents 3893d83 + e3158a6 commit b402efb
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 83 deletions.
60 changes: 28 additions & 32 deletions client/ayon_usd/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,39 @@ def tray_init(self):

def initialize(self, studio_settings):
"""Initialize USD Addon."""
if not studio_settings["usd"]["allow_addon_start"]:
self.log.error(
"The experimental AYON USD addon is currently activated, "
"but you haven't yet acknowledged the user agreement "
"indicating your understanding that this feature is "
"experimental. Please go to the Studio Settings and "
"check the agreement checkbox. The AYON USD addon will now "
"be disabled"
)
self.enabled = False
self._download_window = None

def tray_start(self):
"""Start tray module.
Download USD if needed.
"""
self._download_global_lakefs_binaries()

def tray_exit(self):
"""Exit tray module."""
pass

def tray_menu(self, tray_menu):
"""Add menu items to tray menu."""
pass

def get_launch_hook_paths(self):
"""Get paths to launch hooks."""
return [os.path.join(USD_ADDON_DIR, "hooks")]

def get_plugin_paths(self):
return {
"publish": [
os.path.join(USD_ADDON_DIR, "plugins", "publish")
]
}

def _download_global_lakefs_binaries(self):
settings = get_studio_settings()
if not settings["usd"]["distribution"]["enabled"]:
self.log.info("USD Binary distribution is disabled.")
return

os.makedirs(DOWNLOAD_DIR, exist_ok=True)

Expand All @@ -66,9 +82,8 @@ def tray_start(self):
}
json.dump(init_data, json_file)

settings = get_studio_settings()
if not utils.is_usd_lib_download_needed(settings):
print("usd is already downloaded")
self.log.info("USD Libs already available. Skipping download.")
return

lake_fs_usd_lib_path = config.get_lakefs_usdlib_path(settings)
Expand Down Expand Up @@ -133,23 +148,4 @@ def tray_start(self):
)
download_ui.setStyleSheet(style.load_stylesheet())
download_ui.start()
self._download_window = download_ui

def tray_exit(self):
"""Exit tray module."""
pass

def tray_menu(self, tray_menu):
"""Add menu items to tray menu."""
pass

def get_launch_hook_paths(self):
"""Get paths to launch hooks."""
return [os.path.join(USD_ADDON_DIR, "hooks")]

def get_plugin_paths(self):
return {
"publish": [
os.path.join(USD_ADDON_DIR, "plugins", "publish")
]
}
self._download_window = download_ui
10 changes: 5 additions & 5 deletions client/ayon_usd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def get_global_lake_instance(settings=None):

if not settings:
settings = get_studio_settings()
lakefs = settings["usd"]["lakefs"]
distribution = settings["usd"]["distribution"]
return wrapper.LakeCtl(
server_url=lakefs["server_uri"],
access_key_id=lakefs["access_key_id"],
secret_access_key=lakefs["secret_access_key"],
server_url=distribution["server_uri"],
access_key_id=distribution["access_key_id"],
secret_access_key=distribution["secret_access_key"],
)


Expand All @@ -59,6 +59,6 @@ def get_lakefs_usdlib_name(lake_fs_repo: str) -> str:

def get_lakefs_usdlib_path(settings: dict) -> str:
"""Return AyonUsdBin/usd LakeFS full url for current platform. """
lake_fs_repo = settings["usd"]["lakefs"]["server_repo"]
lake_fs_repo = settings["usd"]["distribution"]["server_repo"]
usd_lib_conf = get_lakefs_usdlib_name(lake_fs_repo)
return f"{lake_fs_repo}{usd_lib_conf}"
26 changes: 16 additions & 10 deletions client/ayon_usd/hooks/pre_resolver_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ class InitializeAssetResolver(PreLaunchHook):
app_groups = {"maya", "houdini", "unreal"}
launch_types = {LaunchTypes.local}

def _setup_resolver(self, local_resolver, settings):
self.log.info(
f"Initializing USD asset resolver for application: {self.app_name}"
)

updated_env = utils.get_resolver_setup_info(
local_resolver, settings, env=self.launch_context.env
)
self.launch_context.env.update(updated_env)

def execute(self):
"""Pre-launch hook entry method."""
project_settings = self.data["project_settings"]
if not project_settings["usd"]["distribution"]["enabled"]:
self.log.info(
"USD Binary distribution for AYON USD Resolver is"
" disabled.")
return

resolver_lake_fs_path = utils.get_resolver_to_download(
project_settings, self.app_name)
if not resolver_lake_fs_path:
Expand Down Expand Up @@ -85,3 +81,13 @@ def execute(self):
json.dump(addon_data_json, addon_json)

self._setup_resolver(local_resolver, project_settings)

def _setup_resolver(self, local_resolver, settings):
self.log.info(
f"Initializing USD asset resolver for application: {self.app_name}"
)

updated_env = utils.get_resolver_setup_info(
local_resolver, settings, env=self.launch_context.env
)
self.launch_context.env.update(updated_env)
10 changes: 5 additions & 5 deletions client/ayon_usd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def is_usd_lib_download_needed(settings: dict) -> bool:
bool: When true, a new download is required.
"""
lake_fs_repo = settings["usd"]["lakefs"]["server_repo"]
lake_fs_repo = settings["usd"]["distribution"]["server_repo"]
usd_lib_dir = os.path.abspath(get_downloaded_usd_root(lake_fs_repo))
if not os.path.exists(usd_lib_dir):
return True
Expand Down Expand Up @@ -119,8 +119,8 @@ def get_resolver_to_download(settings, app_name: str) -> str:
Returns: str: LakeFs object path to be used with lake_fs_py wrapper
"""
lakefs = settings["usd"]["lakefs"]
resolver_overwrite_list = lakefs["lake_fs_overrides"]
distribution = settings["usd"]["distribution"]
resolver_overwrite_list = distribution["lake_fs_overrides"]
if resolver_overwrite_list:
resolver_overwrite = next(
(
Expand All @@ -134,7 +134,7 @@ def get_resolver_to_download(settings, app_name: str) -> str:
if resolver_overwrite:
return resolver_overwrite["lake_fs_path"]

resolver_list = lakefs["asset_resolvers"]
resolver_list = distribution["asset_resolvers"]
if not resolver_list:
return ""

Expand All @@ -150,7 +150,7 @@ def get_resolver_to_download(settings, app_name: str) -> str:
if not resolver:
return ""

lake_fs_repo_uri = lakefs["server_repo"]
lake_fs_repo_uri = distribution["server_repo"]
resolver_lake_path = lake_fs_repo_uri + resolver["lake_fs_path"]
return resolver_lake_path

Expand Down
60 changes: 29 additions & 31 deletions server/settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AppPlatformPathModel(BaseSettingsModel):
description="windows / linux / darwin",
)
lake_fs_path: str = SettingsField(
title="LakeFs Object Path",
title="Repository Object Path",
description=(
"The LakeFs internal path to the resolver zip, e.g: "
"`AyonUsdResolverBin/Hou/ayon-usd-resolver_hou19.5_linux_py37.zip`"
Expand All @@ -89,41 +89,43 @@ class AppPlatformURIModel(BaseSettingsModel):
description="windows / linux / darwin",
)
uri: str = SettingsField(
title="LakeFs Object Uri",
title="Repository Object Uri",
description=(
"Path to USD Asset Resolver plugin zip file on the LakeFs server, "
"e.g: `lakefs://ayon-usd/V001/AyonUsdResolverBin/Hou/ayon-usd-resolver_hou19.5_linux_py37.zip`" # noqa
),
)


class LakeFsSettings(BaseSettingsModel):
"""LakeFs Settings / Download Settings ?"""
class BinaryDistributionSettings(BaseSettingsModel):
"""Binary distribution of USD and AYON USD Resolver"""

_layout = "collapsed"

enabled: bool = SettingsField(False)

server_uri: str = SettingsField(
"https://lake.ayon.cloud",
title="LakeFs Server Uri",
title="Server Uri",
description="The url to your LakeFs server.",
)
server_repo: str = SettingsField(
"lakefs://ayon-usd/v0.2.0/",
title="LakeFs Repository Uri",
title="Repository Uri",
description="The url to your LakeFs Repository Path",
)
access_key_id: str = SettingsField(
"{Ayon_LakeFs_Key_Id}",
"{AYON_Distribution_Key_Id}",
title="Access Key Id",
description="LakeFs Access Key Id",
)
secret_access_key: str = SettingsField(
"{Ayon_LakeFs_Key}",
"{AYON_Distribution_Access_Key}",
title="Access Key",
description="LakeFs Access Key",
)
asset_resolvers: list[AppPlatformPathModel] = SettingsField(
title="Resolver Application LakeFs Paths",
title="Resolver Application Paths",
description="Allows an admin to define a specific Resolver Zip for a specific Application",
default=[
AppPlatformPathModel(
Expand Down Expand Up @@ -229,7 +231,7 @@ class LakeFsSettings(BaseSettingsModel):
],
)
lake_fs_overrides: list[AppPlatformURIModel] = SettingsField(
title="Resolver Application overwrites",
title="Resolver Application Overwrites",
description=(
"Allows to define a specific Resolver Zip for a specific Application"
),
Expand All @@ -238,41 +240,41 @@ class LakeFsSettings(BaseSettingsModel):


class AyonResolverSettings(BaseSettingsModel):
"""LakeFs Settings / Download Settings ?"""
"""AYON USD resolver Settings"""

_layout = "collapsed"

ayon_log_lvl: str = SettingsField(
"WARN",
title="AyonResolver Log Lvl",
title="Resolver Log Lvl",
enum_resolver=log_lvl_enum,
description="Set verbosity of the AyonUsdResolver logger",
)
ayon_file_logger_enabled: str = SettingsField(
"OFF",
title="AyonResolver File Logger Enabled ",
title="Resolver File Logger Enabled ",
enum_resolver=file_logger_enum,
description="Enable or disable AyonUsdResolver file logger",
)
ayon_logger_logging_keys: str = SettingsField(
"",
title="AyonCppApi Logging Keys",
enum_resolver=logger_logging_keys_enum,
description="List of extra logging options for the AyonCppApi",
)
file_logger_file_path: str = SettingsField(
"",
title="AyonResolver File logger file path",
title="Resolver File logger file path",
description=(
"Allows you to set a custom location where the file logger will "
"export to. This can be a relative or absolute path. This is only "
"used if `ayon_file_logger_enabled` is enabled."
),
)
ayon_logger_logging_keys: str = SettingsField(
"",
title="AyonCppApi Logging Keys",
enum_resolver=logger_logging_keys_enum,
description="List of extra logging options for the AyonCppApi",
)


class UsdSettings(BaseSettingsModel):
"""LakeFs Settings / Download Settings ?"""
class UsdLibConfigSettings(BaseSettingsModel):
"""Settings for USD"""

_layout = "collapsed"
usd_tf_debug: str = SettingsField(
Expand All @@ -283,18 +285,14 @@ class UsdSettings(BaseSettingsModel):


class USDSettings(BaseSettingsModel):
"""USD settings."""

allow_addon_start: bool = SettingsField(
False, title=("I understand and accept that this is an experimental feature")
)

lakefs: LakeFsSettings = SettingsField(
default_factory=LakeFsSettings, title="LakeFs Config"
distribution: BinaryDistributionSettings = SettingsField(
default_factory=BinaryDistributionSettings, title="Binary Distribution"
)

ayon_usd_resolver: AyonResolverSettings = SettingsField(
default_factory=AyonResolverSettings, title="UsdResolver Config"
default_factory=AyonResolverSettings, title="AYON USD Resolver Config"
)

usd: UsdSettings = SettingsField(default_factory=UsdSettings, title="UsdLib Config")
usd: UsdLibConfigSettings = SettingsField(
default_factory=UsdLibConfigSettings, title="USD Library Config")

0 comments on commit b402efb

Please sign in to comment.