From 4055536411794dd089c23db8e455e7e93f854434 Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Tue, 25 Jul 2023 11:48:32 +0100 Subject: [PATCH 1/4] Added env variable to set existing built Ayon plugin --- .../unreal/hooks/pre_workfile_preparation.py | 40 ++++++++++++------- openpype/hosts/unreal/lib.py | 30 ++++++++++++++ 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py index 760d55077a..e6662e7420 100644 --- a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py +++ b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py @@ -187,24 +187,36 @@ class UnrealPrelaunchHook(PreLaunchHook): project_path.mkdir(parents=True, exist_ok=True) - # Set "AYON_UNREAL_PLUGIN" to current process environment for - # execution of `create_unreal_project` - - if self.launch_context.env.get("AYON_UNREAL_PLUGIN"): - self.log.info(( - f"{self.signature} using Ayon plugin from " - f"{self.launch_context.env.get('AYON_UNREAL_PLUGIN')}" - )) - env_key = "AYON_UNREAL_PLUGIN" - if self.launch_context.env.get(env_key): - os.environ[env_key] = self.launch_context.env[env_key] - # engine_path points to the specific Unreal Engine root # so, we are going up from the executable itself 3 levels. engine_path: Path = Path(executable).parents[3] - if not unreal_lib.check_plugin_existence(engine_path): - self.exec_plugin_install(engine_path) + # Check if new env variable exists, and if it does, if the path + # actually contains the plugin. If not, install it. + + built_plugin_path = self.launch_context.env.get( + "AYON_BUILT_UNREAL_PLUGIN", None) + + if unreal_lib.check_built_plugin_existance(built_plugin_path): + self.log.info(( + f"{self.signature} using existing built Ayon plugin from " + f"{built_plugin_path}" + )) + unreal_lib.move_built_plugin(engine_path, Path(built_plugin_path)) + else: + # Set "AYON_UNREAL_PLUGIN" to current process environment for + # execution of `create_unreal_project` + env_key = "AYON_UNREAL_PLUGIN" + if self.launch_context.env.get(env_key): + self.log.info(( + f"{self.signature} using Ayon plugin from " + f"{self.launch_context.env.get(env_key)}" + )) + if self.launch_context.env.get(env_key): + os.environ[env_key] = self.launch_context.env[env_key] + + if not unreal_lib.check_plugin_existence(engine_path): + self.exec_plugin_install(engine_path) project_file = project_path / unreal_project_filename diff --git a/openpype/hosts/unreal/lib.py b/openpype/hosts/unreal/lib.py index 67e7891344..cffb5fd1c0 100644 --- a/openpype/hosts/unreal/lib.py +++ b/openpype/hosts/unreal/lib.py @@ -429,6 +429,36 @@ def get_build_id(engine_path: Path, ue_version: str) -> str: return "{" + loaded_modules.get("BuildId") + "}" +def check_built_plugin_existance(plugin_path) -> bool: + if not plugin_path: + return False + + integration_plugin_path = Path(plugin_path) + + if not os.path.isdir(integration_plugin_path): + raise RuntimeError("Path to the integration plugin is null!") + + if not (integration_plugin_path / "Binaries").is_dir() \ + or not (integration_plugin_path / "Intermediate").is_dir(): + return False + + return True + + +def move_built_plugin(engine_path: Path, plugin_path: Path) -> None: + ayon_plugin_path: Path = engine_path / "Engine/Plugins/Marketplace/Ayon" + + if not ayon_plugin_path.is_dir(): + ayon_plugin_path.mkdir(parents=True, exist_ok=True) + + engine_plugin_config_path: Path = ayon_plugin_path / "Config" + engine_plugin_config_path.mkdir(exist_ok=True) + + dir_util._path_created = {} + + dir_util.copy_tree(plugin_path.as_posix(), ayon_plugin_path.as_posix()) + + def check_plugin_existence(engine_path: Path, env: dict = None) -> bool: env = env or os.environ integration_plugin_path: Path = Path(env.get("AYON_UNREAL_PLUGIN", "")) From edbed9ed0e90c5745604a4568109eeab74198efb Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Tue, 25 Jul 2023 14:43:55 +0100 Subject: [PATCH 2/4] Improved code based on suggestions Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- openpype/hosts/unreal/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/unreal/lib.py b/openpype/hosts/unreal/lib.py index cffb5fd1c0..5b2e35958b 100644 --- a/openpype/hosts/unreal/lib.py +++ b/openpype/hosts/unreal/lib.py @@ -435,7 +435,7 @@ def check_built_plugin_existance(plugin_path) -> bool: integration_plugin_path = Path(plugin_path) - if not os.path.isdir(integration_plugin_path): + if not integration_plugin_path.is_dir(): raise RuntimeError("Path to the integration plugin is null!") if not (integration_plugin_path / "Binaries").is_dir() \ From 2bc8b49b9c5005950b481904a7ee3efdc0bd99bf Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Thu, 27 Jul 2023 09:52:17 +0100 Subject: [PATCH 3/4] Use more appropriate name for function Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- openpype/hosts/unreal/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/unreal/lib.py b/openpype/hosts/unreal/lib.py index 5b2e35958b..0c39773c19 100644 --- a/openpype/hosts/unreal/lib.py +++ b/openpype/hosts/unreal/lib.py @@ -445,7 +445,7 @@ def check_built_plugin_existance(plugin_path) -> bool: return True -def move_built_plugin(engine_path: Path, plugin_path: Path) -> None: +def copy_built_plugin(engine_path: Path, plugin_path: Path) -> None: ayon_plugin_path: Path = engine_path / "Engine/Plugins/Marketplace/Ayon" if not ayon_plugin_path.is_dir(): From 22288486b63de491fb2010d40658722552cb2107 Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Thu, 27 Jul 2023 14:46:55 +0100 Subject: [PATCH 4/4] Fix call to renamed function --- openpype/hosts/unreal/hooks/pre_workfile_preparation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py index e6662e7420..1c42d7d246 100644 --- a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py +++ b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py @@ -202,7 +202,7 @@ class UnrealPrelaunchHook(PreLaunchHook): f"{self.signature} using existing built Ayon plugin from " f"{built_plugin_path}" )) - unreal_lib.move_built_plugin(engine_path, Path(built_plugin_path)) + unreal_lib.copy_built_plugin(engine_path, Path(built_plugin_path)) else: # Set "AYON_UNREAL_PLUGIN" to current process environment for # execution of `create_unreal_project`