mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
🐛 fix use and detection of compatible integrations
This commit is contained in:
parent
11691f091c
commit
da6b2b3133
2 changed files with 61 additions and 27 deletions
|
|
@ -1,5 +1,8 @@
|
|||
import os
|
||||
from openpype.modules import OpenPypeModule, IHostAddon
|
||||
from pathlib import Path
|
||||
|
||||
from openpype.modules import IHostAddon, OpenPypeModule
|
||||
from .lib import get_compatible_integration
|
||||
|
||||
UNREAL_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
|
@ -19,9 +22,15 @@ class UnrealAddon(OpenPypeModule, IHostAddon):
|
|||
unreal_plugin_path = os.path.join(
|
||||
UNREAL_ROOT_DIR, "integration", f"UE_{ue_version}", "Ayon"
|
||||
)
|
||||
if not Path(unreal_plugin_path).exists():
|
||||
if compatible_versions := get_compatible_integration(
|
||||
ue_version, Path(UNREAL_ROOT_DIR) / "integration"
|
||||
):
|
||||
unreal_plugin_path = compatible_versions[-1] / "Ayon"
|
||||
unreal_plugin_path = unreal_plugin_path.as_posix()
|
||||
|
||||
if not env.get("AYON_UNREAL_PLUGIN") or \
|
||||
env.get("AYON_UNREAL_PLUGIN") != unreal_plugin_path:
|
||||
env.get("AYON_UNREAL_PLUGIN") != unreal_plugin_path:
|
||||
env["AYON_UNREAL_PLUGIN"] = unreal_plugin_path
|
||||
|
||||
# Set default environments if are not set via settings
|
||||
|
|
|
|||
|
|
@ -321,6 +321,47 @@ def get_path_to_uat(engine_path: Path) -> Path:
|
|||
return engine_path / "Engine/Build/BatchFiles/RunUAT.sh"
|
||||
|
||||
|
||||
def get_compatible_integration(
|
||||
ue_version: str, integration_root: Path) -> List[Path]:
|
||||
"""Get path to compatible version of integration plugin.
|
||||
|
||||
This will try to get the closest compatible versions to the one
|
||||
specified in sorted list.
|
||||
|
||||
Args:
|
||||
ue_version (str): version of the current Unreal Engine.
|
||||
integration_root (Path): path to built-in integration plugins.
|
||||
|
||||
Returns:
|
||||
list of Path: Sorted list of paths closest to the specified
|
||||
version.
|
||||
|
||||
"""
|
||||
major, minor = ue_version.split(".")
|
||||
integration_paths = [p for p in integration_root.iterdir()
|
||||
if p.is_dir()]
|
||||
|
||||
compatible_versions = []
|
||||
for i in integration_paths:
|
||||
# parse version from path
|
||||
try:
|
||||
i_major, i_minor = re.search(
|
||||
r"(?P<major>\d+).(?P<minor>\d+)$", i.name).groups()
|
||||
except AttributeError:
|
||||
# in case there is no match, just skip to next
|
||||
continue
|
||||
|
||||
# consider versions with different major so different that they
|
||||
# are incompatible
|
||||
if int(major) != int(i_major):
|
||||
continue
|
||||
|
||||
compatible_versions.append(i)
|
||||
|
||||
sorted(set(compatible_versions))
|
||||
return compatible_versions
|
||||
|
||||
|
||||
def get_path_to_cmdlet_project(ue_version: str) -> Path:
|
||||
cmd_project = Path(
|
||||
os.path.abspath(os.getenv("OPENPYPE_ROOT")))
|
||||
|
|
@ -334,31 +375,15 @@ def get_path_to_cmdlet_project(ue_version: str) -> Path:
|
|||
if cmd_project.exists():
|
||||
return cmd_project / "CommandletProject/CommandletProject.uproject"
|
||||
|
||||
major, minor = ue_version.split(".")
|
||||
integration_paths = [p for p in cmd_project.parent.iterdir()
|
||||
if p.is_dir()]
|
||||
|
||||
compatible_versions = [cmd_project]
|
||||
for i in integration_paths:
|
||||
|
||||
# parse version from path
|
||||
i_major, i_minor = re.search(
|
||||
r"(?P<major>\d+).(?P<minor>\d+)$", i.name).groups()
|
||||
|
||||
# consider versions with different major so different that they
|
||||
# are incompatible
|
||||
if int(major) != int(i_major):
|
||||
continue
|
||||
|
||||
compatible_versions.append(i)
|
||||
|
||||
sorted(set(compatible_versions))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return cmd_project / "CommandletProject/CommandletProject.uproject"
|
||||
if compatible_versions := get_compatible_integration(
|
||||
ue_version, cmd_project.parent
|
||||
):
|
||||
return compatible_versions[-1] / "CommandletProject/CommandletProject.uproject" # noqa: E501
|
||||
else:
|
||||
raise RuntimeError(
|
||||
("There are no compatible versions of Unreal "
|
||||
"integration plugin compatible with running version "
|
||||
f"of Unreal Engine {ue_version}"))
|
||||
|
||||
|
||||
def get_path_to_ubt(engine_path: Path, ue_version: str) -> Path:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue