diff --git a/tools/build_post_process.py b/tools/build_post_process.py index 27d17e262..bf2d2e600 100755 --- a/tools/build_post_process.py +++ b/tools/build_post_process.py @@ -35,6 +35,10 @@ import blessed import enlighten +if platform.system().lower() == "linux": + import distro +else: + distro = None term = blessed.Terminal() manager = enlighten.get_manager() @@ -582,10 +586,15 @@ def store_base_metadata(build_root, build_content_root, ayon_version): build_content_root (Path): Path build content directory. ayon_version (str): AYON version. """ + platform_name = platform.system().lower() + distro_short = None + if platform_name == "linux": + distro_short = f"{distro.id()}{distro.major_version()}" metadata = { "version": ayon_version, - "platform": platform.system().lower(), + "platform": platform_name, + "distro_short": distro_short, "python_version": platform.python_version(), "python_modules": get_packages_info(build_root), "runtime_python_modules": get_runtime_modules(build_content_root), @@ -649,7 +658,9 @@ def _create_windows_installer( _build_root, installer_root, build_content_root, - ayon_version + ayon_version, + _distro_short, + pyside2_used, ): """Create Windows installer. @@ -657,11 +668,12 @@ def _create_windows_installer( Path: Path to installer file. """ + pyside2_suffix = "-pyside2" if pyside2_used else "" iscc_executable = _find_iscc() inno_setup_path = ayon_root / "inno_setup.iss" env = os.environ.copy() - installer_basename = f"AYON-{ayon_version}-win-setup" + installer_basename = f"AYON-{ayon_version}-win{pyside2_suffix}-setup" env["BUILD_SRC_DIR"] = str(build_content_root.relative_to(ayon_root)) env["BUILD_DST_DIR"] = str(installer_root.relative_to(ayon_root)) @@ -679,15 +691,18 @@ def _create_linux_installer( _build_root, installer_root, build_content_root, - ayon_version + ayon_version, + distro_short, + pyside2_used, ): """Linux installer is just tar file. Returns: Path: Path to installer file. - """ - basename = f"AYON-{ayon_version}-linux" + """ + pyside2_suffix = "-pyside2" if pyside2_used else "" + basename = f"AYON-{ayon_version}-linux-{distro_short}{pyside2_suffix}" filename = f"{basename}.tar.gz" output_path = installer_root / filename @@ -701,7 +716,13 @@ def _create_linux_installer( def _create_darwin_installer( - _ayon_root, build_root, installer_root, _build_content_root, ayon_version + _ayon_root, + build_root, + installer_root, + _build_content_root, + ayon_version, + _distro_short, + pyside2_used, ): """Create MacOS installer (.dmg). @@ -710,10 +731,12 @@ def _create_darwin_installer( Raises: ValueError: If 'create-dmg' is not available. - """ + """ + pyside2_suffix = "-pyside2" if pyside2_used else "" app_filepath = _get_darwin_output_path(build_root, ayon_version) - output_path = installer_root / f"AYON-{ayon_version}-macos.dmg" + filename = f"AYON-{ayon_version}-macos{pyside2_suffix}.dmg" + output_path = installer_root / filename # TODO check if 'create-dmg' is available try: subprocess.call(["create-dmg"]) @@ -785,6 +808,8 @@ def store_installer_metadata(build_root, installer_root, installer_path): def create_installer(ayon_root, build_root): metadata = get_build_metadata(build_root) ayon_version = metadata["version"] + distro_short = metadata["distro_short"] + pyside2_used = "PySide2" in metadata["runtime_python_modules"] build_content_root = get_build_content_root(build_root, ayon_version) installer_root = build_root / "installer" if installer_root.exists(): @@ -796,7 +821,9 @@ def create_installer(ayon_root, build_root): build_root, installer_root, build_content_root, - ayon_version + ayon_version, + distro_short, + pyside2_used, ) store_installer_metadata( build_root, installer_root, str(installer_path.absolute()) diff --git a/tools/make.sh b/tools/make.sh index 621465111..2e558a689 100755 --- a/tools/make.sh +++ b/tools/make.sh @@ -228,7 +228,7 @@ install_runtime_dependencies () { pushd "$repo_root" > /dev/null || return > /dev/null echo -e "${BIGreen}>>>${RST} Installing runtime dependencies ..." - "$poetry_home_root/bin/poetry" run python "$repo_root/tools/runtime_dependencies.py" + "$poetry_home_root/bin/poetry" run python "$repo_root/tools/runtime_dependencies.py" "$@" } fix_macos_build () { @@ -426,6 +426,7 @@ default_help() { echo "Runtime targets:" echo " create-env Install Poetry and update venv by lock file" echo " install-runtime-dependencies Install runtime dependencies (Qt binding)" + echo " --use-pyside2 Install PySide2 instead of PySide6." echo " install-runtime Alias for 'install-runtime-dependencies'" echo " build Build desktop application" echo " make-installer Make desktop application installer" @@ -434,6 +435,7 @@ default_help() { echo " create-server-package Create package ready for AYON server" echo " run Run desktop application from code" echo " docker-build [variant] Build AYON using Docker. Variant can be 'debian', 'rocky8' or 'rocky9'" + echo " --use-pyside2 Use PySide2 instead of PySide6." echo "" } @@ -453,7 +455,7 @@ main() { exit $return_code ;; "installruntimedependencies"|"installruntime") - install_runtime_dependencies || return_code=$? + install_runtime_dependencies "${@:2}" || return_code=$? exit $return_code ;; "build"|"buildayon") diff --git a/tools/manage.ps1 b/tools/manage.ps1 index bb30b735e..aff90b722 100755 --- a/tools/manage.ps1 +++ b/tools/manage.ps1 @@ -259,6 +259,7 @@ function Default-Func { Write-Host "Runtime targets:" Write-Color -text " create-env ", "Install Poetry and update venv by lock file" -Color White, Cyan Write-Color -text " install-runtime-dependencies ", "Install runtime dependencies (Qt binding)" -Color White, Cyan + Write-Color -text " --use-pyside2 Install ", "PySide2", " instead of ", "PySide6", "." -Color White, Cyan, White, Cyan, White Write-Color -text " install-runtime ", "Alias for '", "install-runtime-dependencies", "'" -Color White, Cyan, White, Cyan Write-Color -text " build ", "Build desktop application" -Color White, Cyan Write-Color -text " make-installer ", "Make desktop application installer" -Color White, Cyan @@ -266,6 +267,7 @@ function Default-Func { Write-Color -text " upload ", "Upload installer to server" -Color White, Cyan Write-Color -text " run ", "Run desktop application from code" -Color White, Cyan Write-Color -text " docker-build ","[variant] ", "Build AYON using Docker. Variant can be '", "ubuntu", "', '", "debian", "', '", "rocky8", "' or '", "rocky9", "'" -Color White, Yellow, Cyan, Yellow, Cyan, Yellow, Cyan, Yellow, Cyan, Yellow, Cyan + Write-Color -text " --use-pyside2 Use ", "PySide2", " instead of ", "PySide6", "." -Color White, Cyan, White, Cyan, White Write-Host "" } @@ -462,7 +464,7 @@ function Install-Runtime-Dependencies() { Write-Color -Text "OK" -Color Green } $startTime = [int][double]::Parse((Get-Date -UFormat %s)) - & "$($poetry_home)\bin\poetry" run python "$($repo_root)\tools\runtime_dependencies.py" + & "$($poetry_home)\bin\poetry" run python "$($repo_root)\tools\runtime_dependencies.py" @args $endTime = [int][double]::Parse((Get-Date -UFormat %s)) try { New-BurntToastNotification -AppLogo "$app_logo" -Text "AYON", "Dependencies downloaded", "All done in $( $endTime - $startTime ) secs." @@ -485,7 +487,7 @@ function Main { } elseif ($FunctionName -eq "createenv") { Create-Env } elseif (($FunctionName -eq "installruntimedependencies") -or ($FunctionName -eq "installruntime")) { - Install-Runtime-Dependencies + Install-Runtime-Dependencies @arguments } elseif ($FunctionName -eq "build") { Build-Ayon } elseif ($FunctionName -eq "makeinstaller") { diff --git a/tools/runtime_dependencies.py b/tools/runtime_dependencies.py index b2cc3611f..207881e0b 100755 --- a/tools/runtime_dependencies.py +++ b/tools/runtime_dependencies.py @@ -5,6 +5,7 @@ """ import os +import shutil import sys import platform import hashlib @@ -61,7 +62,7 @@ def _print(msg: str, message_type: int = 0) -> None: print(f"{header}{msg}") -def _pip_install(runtime_dep_root, package, version=None): +def _pip_install(python_vendor_dir, package, version=None): arg = None if package and version: arg = f"{package}=={version}" @@ -74,7 +75,6 @@ def _pip_install(runtime_dep_root, package, version=None): _print(f"We'll install {arg}") - python_vendor_dir = runtime_dep_root / "python" try: subprocess.run( [ @@ -93,10 +93,15 @@ def _pip_install(runtime_dep_root, package, version=None): sys.exit(1) -def install_qtbinding(pyproject, runtime_dep_root, platform_name): +def install_qtbinding( + pyproject, python_vendor_dir, platform_name, use_pyside2 +): _print("Handling Qt binding framework ...") qt_variants = [] + if use_pyside2: + qt_variants.append("pyside2") + # Use QT_BINDING environment variable if set # - existence is not validate, if does not exists it is just skipped qt_package = os.getenv("QT_BINDING") @@ -123,13 +128,12 @@ def install_qtbinding(pyproject, runtime_dep_root, platform_name): package = qtbinding_def["package"] version = qtbinding_def.get("version") - _pip_install(runtime_dep_root, package, version) + _pip_install(python_vendor_dir, package, version) # Remove libraries for QtSql which don't have available libraries # by default and Postgre library would require to modify rpath of # dependency if platform_name == "darwin": - python_vendor_dir = runtime_dep_root / "python" sqldrivers_dir = ( python_vendor_dir / package / "Qt" / "plugins" / "sqldrivers" ) @@ -137,7 +141,7 @@ def install_qtbinding(pyproject, runtime_dep_root, platform_name): os.remove(str(filepath)) -def install_runtime_dependencies(pyproject, runtime_dep_root): +def install_runtime_dependencies(pyproject, python_vendor_dir): runtime_deps = ( pyproject .get("ayon", {}) @@ -145,17 +149,25 @@ def install_runtime_dependencies(pyproject, runtime_dep_root): .get("deps", {}) ) for package, version in runtime_deps.items(): - _pip_install(runtime_dep_root, package, version) + _pip_install(python_vendor_dir, package, version) def main(): start_time = time.time_ns() repo_root = Path(os.path.dirname(__file__)).parent - runtime_dep_root = repo_root / "vendor" + python_vendor_dir = repo_root / "vendor" / "python" + if python_vendor_dir.exists(): + _print("Removing existing vendor directory") + shutil.rmtree(python_vendor_dir) + python_vendor_dir.mkdir(parents=True, exist_ok=True) pyproject = toml.load(repo_root / "pyproject.toml") platform_name = platform.system().lower() - install_qtbinding(pyproject, runtime_dep_root, platform_name) - install_runtime_dependencies(pyproject, runtime_dep_root) + use_pyside2 = "--use-pyside2" in sys.argv + + install_qtbinding( + pyproject, python_vendor_dir, platform_name, use_pyside2 + ) + install_runtime_dependencies(pyproject, python_vendor_dir) end_time = time.time_ns() total_time = (end_time - start_time) / 1000000000 _print(f"Downloading and extracting took {total_time} secs.")