From 9551729f79511572e46d07ef8152fff85366b8a7 Mon Sep 17 00:00:00 2001 From: Luca Scheller Date: Sat, 28 Oct 2023 15:14:07 +0200 Subject: [PATCH] Refactor install venv for arHttp --- tools/debug.py | 49 ----------------------------------------- tools/update_manager.py | 22 ++++++++++++------ 2 files changed, 15 insertions(+), 56 deletions(-) delete mode 100644 tools/debug.py diff --git a/tools/debug.py b/tools/debug.py deleted file mode 100644 index 1c14d50..0000000 --- a/tools/debug.py +++ /dev/null @@ -1,49 +0,0 @@ -import contextlib -import json -import os -import platform -import re -import shutil -import ssl -import subprocess -import tempfile -import urllib -import zipfile -from urllib import request - -def install_side_effect_httpResolver(platform_name, software_name, resolver_dir_path): - """The install side effect for the httpResolver. - # ToDo Instead of using 'HFS' for the Houdini install directory, add a software version input arg. - This does the following: - - Create a venv in the ./demo folder - - Install fastapi - Args: - platform_name(str): The active platform - directory_path(str): The resolver directory path - Returns: - str: A command to run before app execution - """ - # Validate - if platform_name == "macos": - raise Exception( - "Platform {} is currently not supported!".format(platform_name) - ) - - - demo_dir_path = os.path.join(resolver_dir_path, "demo") - python_exe = os.path.join(os.environ["HFS"], "python", "bin", "python") - - # Create venv - subprocess.check_call([python_exe, "-m", "venv", "venv"], cwd=demo_dir_path) - venv_python_exe = os.path.join(demo_dir_path, "venv", "bin", "python") - # Install deps (We can't use the pyproject.toml as it depends on .git) - subprocess.check_call([venv_python_exe, "-m", "pip", "install", "fastapi[all]"], cwd=demo_dir_path) - # Command - if platform_name == "linux": - command = "uvicorn arHttpSampleServer:app --reload &" - elif platform_name == "win64": - command = "" - return command - - -install_side_effect_httpResolver("", "", "/mnt/data/PROJECT/VFX-UsdAssetResolver/dist/httpResolver") \ No newline at end of file diff --git a/tools/update_manager.py b/tools/update_manager.py index 34ee0ae..0955307 100644 --- a/tools/update_manager.py +++ b/tools/update_manager.py @@ -53,22 +53,25 @@ def install_side_effect_httpResolver(platform_name, software_name, resolver_dir_ ) demo_dir_path = os.path.join(resolver_dir_path, "demo") + if not os.path.exists(demo_dir_path): + os.makedirs(demo_dir_path) python_exe = os.path.join(os.environ["HFS"], "python", "bin", "python") # Create venv - subprocess.check_call([python_exe, "-m", "venv", "venv"], cwd=demo_dir_path) + subprocess.check_call([python_exe, "-m", "venv", "venv"], cwd=demo_dir_path, env={}) venv_python_exe = os.path.join(demo_dir_path, "venv", "bin", "python") # Install deps (We can't use the pyproject.toml as it depends on .git) - subprocess.check_call([venv_python_exe, "-m", "pip", "install", "fastapi[all]"], cwd=demo_dir_path) + subprocess.check_call([venv_python_exe, "-m", "pip", "install", "fastapi[all]"], cwd=demo_dir_path, env={}) # Command if platform_name == "linux": - command = "{} uvicorn arHttpSampleServer:app --reload &".format(venv_python_exe) + venv_uvicorn_exe = os.path.join(demo_dir_path, "venv", "bin", "uvicorn") + command = "{} arHttpSampleServer:app --reload &".format(venv_uvicorn_exe) elif platform_name == "win64": - command = "" + command = 'start "ArHttp Webserver" {} arHttpSampleServer:app --reload'.format(venv_uvicorn_exe) return command -INSTALL_SIDE_EFFECTS = {"httpResolver": install_side_effect_httpResolver} +INSTALL_SIDE_EFFECTS = {"fileResolver": install_side_effect_httpResolver} class UpdateManagerUI(QtWidgets.QDialog): @@ -273,7 +276,7 @@ def uninstall_button_clicked(self): answer = QtWidgets.QMessageBox.information( self, QT_WINDOW_TITLE, - "Uninstall successfull. Please restart the application.\nDo you want to alternatively reinstall a different release? ", + "Uninstall successful. Please restart the application.\nDo you want to alternatively reinstall a different release? ", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.Cancel, ) if answer == QtWidgets.QMessageBox.Yes: @@ -503,6 +506,11 @@ def install_release( ) directory_path = self.uncompress_file(download_file_path) resolver_dir_path = os.path.join(directory_path, resolver_name) + # Cleanup other resolvers + for dir_name in os.listdir(directory_path): + if dir_name != resolver_name: + os.rmdir(os.path.join(directory_path, dir_name)) + # Build launcher env = { "PXR_PLUGINPATH_NAME": os.path.join(resolver_dir_path, "resources"), "PYTHONPATH": os.path.join(resolver_dir_path, "lib", "python"), @@ -531,7 +539,7 @@ def install_release( env_name=env_name, env_value=env_value, sep=os.pathsep ) ) - # Side effect command + # Side effect command if side_effect_command: lines.append(side_effect_command) # App