Skip to content

Commit

Permalink
Merge pull request #158 from ynput/enhancement/add-distro-and-pyside2…
Browse files Browse the repository at this point in the history
…-info

Chore: Add distro and pyside2 information to installer filename
  • Loading branch information
iLLiCiTiT authored Aug 29, 2024
2 parents d55b725 + f1835a1 commit b745f81
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 24 deletions.
47 changes: 37 additions & 10 deletions tools/build_post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -649,19 +658,22 @@ def _create_windows_installer(
_build_root,
installer_root,
build_content_root,
ayon_version
ayon_version,
_distro_short,
pyside2_used,
):
"""Create Windows installer.
Returns:
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))
Expand All @@ -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

Expand All @@ -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).
Expand All @@ -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"])
Expand Down Expand Up @@ -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():
Expand All @@ -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())
Expand Down
6 changes: 4 additions & 2 deletions tools/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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"
Expand All @@ -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 ""
}

Expand All @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions tools/manage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,15 @@ 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
Write-Color -text " build-make-installer ", "Build desktop application and make installer" -Color White, Cyan
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 ""
}

Expand Down Expand Up @@ -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."
Expand All @@ -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") {
Expand Down
32 changes: 22 additions & 10 deletions tools/runtime_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import os
import shutil
import sys
import platform
import hashlib
Expand Down Expand Up @@ -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}"
Expand All @@ -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(
[
Expand All @@ -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")
Expand All @@ -123,39 +128,46 @@ 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"
)
for filepath in sqldrivers_dir.iterdir():
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", {})
.get("runtime", {})
.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.")
Expand Down

0 comments on commit b745f81

Please sign in to comment.