From 8df840995eddf0a5b528d48c0ee9bcb20f2f1406 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Tue, 19 Jan 2021 19:32:04 +0100 Subject: [PATCH] proper python environments --- pype/lib/__init__.py | 11 + pype/vendor/python/common/README.md | 2 + pype/vendor/{ => python/common}/capture.py | 0 .../common}/capture_gui/__init__.py | 0 .../common}/capture_gui/accordion.py | 0 .../{ => python/common}/capture_gui/app.py | 0 .../common}/capture_gui/colorpicker.py | 0 .../{ => python/common}/capture_gui/lib.py | 0 .../{ => python/common}/capture_gui/plugin.py | 0 .../capture_gui/plugins/cameraplugin.py | 0 .../capture_gui/plugins/codecplugin.py | 0 .../plugins/defaultoptionsplugin.py | 0 .../capture_gui/plugins/displayplugin.py | 0 .../capture_gui/plugins/genericplugin.py | 0 .../common}/capture_gui/plugins/ioplugin.py | 0 .../capture_gui/plugins/panzoomplugin.py | 0 .../capture_gui/plugins/rendererplugin.py | 0 .../capture_gui/plugins/resolutionplugin.py | 0 .../common}/capture_gui/plugins/timeplugin.py | 0 .../capture_gui/plugins/viewportplugin.py | 0 .../common}/capture_gui/presets.py | 0 .../common}/capture_gui/resources/config.png | Bin .../common}/capture_gui/resources/import.png | Bin .../common}/capture_gui/resources/reset.png | Bin .../common}/capture_gui/resources/save.png | Bin .../{ => python/common}/capture_gui/tokens.py | 0 .../common}/capture_gui/vendor/Qt.py | 0 .../common}/capture_gui/vendor/__init__.py | 0 .../common}/capture_gui/version.py | 0 pype/vendor/{ => python/common}/pysync.py | 0 pype/vendor/python/python_2/README.md | 3 + pype/vendor/python/python_3/README.md | 2 + setup.py | 1 - start.py | 215 ++++++++++++------ tools/build.ps1 | 8 + tools/build_dependencies.py | 5 +- tools/create_env.ps1 | 2 +- tools/create_zip.ps1 | 4 +- tools/run_mongo.ps1 | 90 +++++++- tools/run_settings.ps1 | 13 ++ tools/run_tests.ps1 | 15 ++ tools/run_tray.ps1 | 12 + 42 files changed, 302 insertions(+), 81 deletions(-) create mode 100644 pype/vendor/python/common/README.md rename pype/vendor/{ => python/common}/capture.py (100%) rename pype/vendor/{ => python/common}/capture_gui/__init__.py (100%) rename pype/vendor/{ => python/common}/capture_gui/accordion.py (100%) rename pype/vendor/{ => python/common}/capture_gui/app.py (100%) rename pype/vendor/{ => python/common}/capture_gui/colorpicker.py (100%) rename pype/vendor/{ => python/common}/capture_gui/lib.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/cameraplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/codecplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/defaultoptionsplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/displayplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/genericplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/ioplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/panzoomplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/rendererplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/resolutionplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/timeplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/plugins/viewportplugin.py (100%) rename pype/vendor/{ => python/common}/capture_gui/presets.py (100%) rename pype/vendor/{ => python/common}/capture_gui/resources/config.png (100%) rename pype/vendor/{ => python/common}/capture_gui/resources/import.png (100%) rename pype/vendor/{ => python/common}/capture_gui/resources/reset.png (100%) rename pype/vendor/{ => python/common}/capture_gui/resources/save.png (100%) rename pype/vendor/{ => python/common}/capture_gui/tokens.py (100%) rename pype/vendor/{ => python/common}/capture_gui/vendor/Qt.py (100%) rename pype/vendor/{ => python/common}/capture_gui/vendor/__init__.py (100%) rename pype/vendor/{ => python/common}/capture_gui/version.py (100%) rename pype/vendor/{ => python/common}/pysync.py (100%) create mode 100644 pype/vendor/python/python_2/README.md create mode 100644 pype/vendor/python/python_3/README.md diff --git a/pype/lib/__init__.py b/pype/lib/__init__.py index 691c105b76..d10f3d199d 100644 --- a/pype/lib/__init__.py +++ b/pype/lib/__init__.py @@ -1,5 +1,16 @@ # -*- coding: utf-8 -*- +# flake8: noqa E402 """Pype module API.""" +# add vendor to sys path based on Python version +import sys +import os +import site + +# add Python version specific vendor folder +site.addsitedir( + os.path.join( + os.getenv("PYPE_ROOT", ""), + "vendor", "python", "python_{}".format(sys.version[0]))) from .terminal import Terminal from .execute import ( diff --git a/pype/vendor/python/common/README.md b/pype/vendor/python/common/README.md new file mode 100644 index 0000000000..52effb5a63 --- /dev/null +++ b/pype/vendor/python/common/README.md @@ -0,0 +1,2 @@ +### Info +Here are modules that can run under both Python 2 and Python 3 hosts. \ No newline at end of file diff --git a/pype/vendor/capture.py b/pype/vendor/python/common/capture.py similarity index 100% rename from pype/vendor/capture.py rename to pype/vendor/python/common/capture.py diff --git a/pype/vendor/capture_gui/__init__.py b/pype/vendor/python/common/capture_gui/__init__.py similarity index 100% rename from pype/vendor/capture_gui/__init__.py rename to pype/vendor/python/common/capture_gui/__init__.py diff --git a/pype/vendor/capture_gui/accordion.py b/pype/vendor/python/common/capture_gui/accordion.py similarity index 100% rename from pype/vendor/capture_gui/accordion.py rename to pype/vendor/python/common/capture_gui/accordion.py diff --git a/pype/vendor/capture_gui/app.py b/pype/vendor/python/common/capture_gui/app.py similarity index 100% rename from pype/vendor/capture_gui/app.py rename to pype/vendor/python/common/capture_gui/app.py diff --git a/pype/vendor/capture_gui/colorpicker.py b/pype/vendor/python/common/capture_gui/colorpicker.py similarity index 100% rename from pype/vendor/capture_gui/colorpicker.py rename to pype/vendor/python/common/capture_gui/colorpicker.py diff --git a/pype/vendor/capture_gui/lib.py b/pype/vendor/python/common/capture_gui/lib.py similarity index 100% rename from pype/vendor/capture_gui/lib.py rename to pype/vendor/python/common/capture_gui/lib.py diff --git a/pype/vendor/capture_gui/plugin.py b/pype/vendor/python/common/capture_gui/plugin.py similarity index 100% rename from pype/vendor/capture_gui/plugin.py rename to pype/vendor/python/common/capture_gui/plugin.py diff --git a/pype/vendor/capture_gui/plugins/cameraplugin.py b/pype/vendor/python/common/capture_gui/plugins/cameraplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/cameraplugin.py rename to pype/vendor/python/common/capture_gui/plugins/cameraplugin.py diff --git a/pype/vendor/capture_gui/plugins/codecplugin.py b/pype/vendor/python/common/capture_gui/plugins/codecplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/codecplugin.py rename to pype/vendor/python/common/capture_gui/plugins/codecplugin.py diff --git a/pype/vendor/capture_gui/plugins/defaultoptionsplugin.py b/pype/vendor/python/common/capture_gui/plugins/defaultoptionsplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/defaultoptionsplugin.py rename to pype/vendor/python/common/capture_gui/plugins/defaultoptionsplugin.py diff --git a/pype/vendor/capture_gui/plugins/displayplugin.py b/pype/vendor/python/common/capture_gui/plugins/displayplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/displayplugin.py rename to pype/vendor/python/common/capture_gui/plugins/displayplugin.py diff --git a/pype/vendor/capture_gui/plugins/genericplugin.py b/pype/vendor/python/common/capture_gui/plugins/genericplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/genericplugin.py rename to pype/vendor/python/common/capture_gui/plugins/genericplugin.py diff --git a/pype/vendor/capture_gui/plugins/ioplugin.py b/pype/vendor/python/common/capture_gui/plugins/ioplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/ioplugin.py rename to pype/vendor/python/common/capture_gui/plugins/ioplugin.py diff --git a/pype/vendor/capture_gui/plugins/panzoomplugin.py b/pype/vendor/python/common/capture_gui/plugins/panzoomplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/panzoomplugin.py rename to pype/vendor/python/common/capture_gui/plugins/panzoomplugin.py diff --git a/pype/vendor/capture_gui/plugins/rendererplugin.py b/pype/vendor/python/common/capture_gui/plugins/rendererplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/rendererplugin.py rename to pype/vendor/python/common/capture_gui/plugins/rendererplugin.py diff --git a/pype/vendor/capture_gui/plugins/resolutionplugin.py b/pype/vendor/python/common/capture_gui/plugins/resolutionplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/resolutionplugin.py rename to pype/vendor/python/common/capture_gui/plugins/resolutionplugin.py diff --git a/pype/vendor/capture_gui/plugins/timeplugin.py b/pype/vendor/python/common/capture_gui/plugins/timeplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/timeplugin.py rename to pype/vendor/python/common/capture_gui/plugins/timeplugin.py diff --git a/pype/vendor/capture_gui/plugins/viewportplugin.py b/pype/vendor/python/common/capture_gui/plugins/viewportplugin.py similarity index 100% rename from pype/vendor/capture_gui/plugins/viewportplugin.py rename to pype/vendor/python/common/capture_gui/plugins/viewportplugin.py diff --git a/pype/vendor/capture_gui/presets.py b/pype/vendor/python/common/capture_gui/presets.py similarity index 100% rename from pype/vendor/capture_gui/presets.py rename to pype/vendor/python/common/capture_gui/presets.py diff --git a/pype/vendor/capture_gui/resources/config.png b/pype/vendor/python/common/capture_gui/resources/config.png similarity index 100% rename from pype/vendor/capture_gui/resources/config.png rename to pype/vendor/python/common/capture_gui/resources/config.png diff --git a/pype/vendor/capture_gui/resources/import.png b/pype/vendor/python/common/capture_gui/resources/import.png similarity index 100% rename from pype/vendor/capture_gui/resources/import.png rename to pype/vendor/python/common/capture_gui/resources/import.png diff --git a/pype/vendor/capture_gui/resources/reset.png b/pype/vendor/python/common/capture_gui/resources/reset.png similarity index 100% rename from pype/vendor/capture_gui/resources/reset.png rename to pype/vendor/python/common/capture_gui/resources/reset.png diff --git a/pype/vendor/capture_gui/resources/save.png b/pype/vendor/python/common/capture_gui/resources/save.png similarity index 100% rename from pype/vendor/capture_gui/resources/save.png rename to pype/vendor/python/common/capture_gui/resources/save.png diff --git a/pype/vendor/capture_gui/tokens.py b/pype/vendor/python/common/capture_gui/tokens.py similarity index 100% rename from pype/vendor/capture_gui/tokens.py rename to pype/vendor/python/common/capture_gui/tokens.py diff --git a/pype/vendor/capture_gui/vendor/Qt.py b/pype/vendor/python/common/capture_gui/vendor/Qt.py similarity index 100% rename from pype/vendor/capture_gui/vendor/Qt.py rename to pype/vendor/python/common/capture_gui/vendor/Qt.py diff --git a/pype/vendor/capture_gui/vendor/__init__.py b/pype/vendor/python/common/capture_gui/vendor/__init__.py similarity index 100% rename from pype/vendor/capture_gui/vendor/__init__.py rename to pype/vendor/python/common/capture_gui/vendor/__init__.py diff --git a/pype/vendor/capture_gui/version.py b/pype/vendor/python/common/capture_gui/version.py similarity index 100% rename from pype/vendor/capture_gui/version.py rename to pype/vendor/python/common/capture_gui/version.py diff --git a/pype/vendor/pysync.py b/pype/vendor/python/common/pysync.py similarity index 100% rename from pype/vendor/pysync.py rename to pype/vendor/python/common/pysync.py diff --git a/pype/vendor/python/python_2/README.md b/pype/vendor/python/python_2/README.md new file mode 100644 index 0000000000..f101ddbf54 --- /dev/null +++ b/pype/vendor/python/python_2/README.md @@ -0,0 +1,3 @@ +## Info + +Only **Python 2** specific modules are here. \ No newline at end of file diff --git a/pype/vendor/python/python_3/README.md b/pype/vendor/python/python_3/README.md new file mode 100644 index 0000000000..1b8ab4ce69 --- /dev/null +++ b/pype/vendor/python/python_3/README.md @@ -0,0 +1,2 @@ +## Info +Only **Python 3** modules are here. \ No newline at end of file diff --git a/setup.py b/setup.py index 0924f1070d..3a782a8d72 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,6 @@ include_files = [ "pype", "repos", "schema", - "setup", "vendor", "LICENSE", "README.md", diff --git a/start.py b/start.py index d9b825307b..2b450c0c3f 100644 --- a/start.py +++ b/start.py @@ -46,7 +46,7 @@ So, bootstrapping Pype looks like this:: YES NO | | | +------v--------------+ - | | Fire up Igniter GUI |<---------\ + | | Fire up Igniter GUI |<---------+ | | and ask User | | | +---------------------+ | | | @@ -72,9 +72,9 @@ So, bootstrapping Pype looks like this:: | | to user data dir. | | | +--------------|------------------+ | | .-- Is Pype found? --. | - | YES NO ---------/ + | YES NO ---------+ | | - |<--------/ + |<---------+ | +-------------v------------+ | Run Pype | @@ -97,6 +97,7 @@ import re import sys import traceback import subprocess +import site from pathlib import Path # add dependencies folder to sys.pat for frozen code @@ -112,7 +113,7 @@ if getattr(sys, 'frozen', False): from igniter import BootstrapRepos # noqa: E402 from igniter.tools import load_environments # noqa: E402 - +from igniter.bootstrap_repos import PypeVersion # noqa: E402 bootstrap = BootstrapRepos() silent_commands = ["run", "igniter"] @@ -214,7 +215,6 @@ def _process_arguments() -> tuple: tuple: Return tuple with specific version to use (if any) and flag to prioritize staging (if set) """ - # check for `--use-version=3.0.0` argument and `--use-staging` use_version = None use_staging = False @@ -268,10 +268,35 @@ def _determine_mongodb() -> str: return pype_mongo +def _initialize_environment(pype_version: PypeVersion) -> None: + version_path = pype_version.path + os.environ["PYPE_VERSION"] = pype_version.version + # inject version to Python environment (sys.path, ...) + print(">>> Injecting Pype version to running environment ...") + bootstrap.add_paths_from_directory(version_path) + + # add venv 'site-packages' to PYTHONPATH + python_path = os.getenv("PYTHONPATH", "") + split_paths = python_path.split(os.pathsep) + # add pype tools + split_paths.append(os.path.join(os.environ["PYPE_ROOT"], "pype", "tools")) + # add common pype vendor + # (common for multiple Python interpreter versions) + split_paths.append(os.path.join( + os.environ["PYPE_ROOT"], "pype", "vendor", "python", "common")) + os.environ["PYTHONPATH"] = os.pathsep.join(split_paths) + + # set PYPE_ROOT to point to currently used Pype version. + os.environ["PYPE_ROOT"] = os.path.normpath(version_path.as_posix()) + + def _find_frozen_pype(use_version: str = None, use_staging: bool = False) -> Path: """Find Pype to run from frozen code. + This will process and modify environment variables: + ``PYTHONPATH``, ``PYPE_VERSION``, ``PYPE_ROOT`` + Args: use_version (str, optional): Try to use specified version. use_staging (bool, optional): Prefer *staging* flavor over production. @@ -284,7 +309,6 @@ def _find_frozen_pype(use_version: str = None, (if requested). """ - pype_version = None pype_versions = bootstrap.find_pype(include_zips=True, staging=use_staging) @@ -299,15 +323,26 @@ def _find_frozen_pype(use_version: str = None, pype_versions = bootstrap.find_pype() if not pype_versions: - raise RuntimeError("No Pype versions found.") + # no Pype versions found anyway, lets use then the one + # shipped with frozen Pype + version_path = _bootstrap_from_code(use_version) + pype_version = PypeVersion( + version=BootstrapRepos.get_version(version_path), + path=version_path) + _initialize_environment(pype_version) + return version_path # get path of version specified in `--use-version` version_path = BootstrapRepos.get_version_path_from_list( use_version, pype_versions) + if not version_path: if use_version is not None: - print(("!!! Specified version was not found, using " - "latest available")) + if not pype_version: + ... + else: + print(("!!! Specified version was not found, using " + "latest available")) # specified version was not found so use latest detected. version_path = pype_version.path print(f">>> Using version [ {pype_version} ]") @@ -331,20 +366,76 @@ def _find_frozen_pype(use_version: str = None, if pype_version.path.is_file(): print(">>> Extracting zip file ...") version_path = bootstrap.extract_pype(pype_version) + pype_version.path = version_path - os.environ["PYPE_VERSION"] = pype_version.version - # inject version to Python environment (sys.path, ...) - print(">>> Injecting Pype version to running environment ...") - bootstrap.add_paths_from_directory(version_path) - - # set PYPE_ROOT to point to currently used Pype version. - os.environ["PYPE_ROOT"] = os.path.normpath(version_path.as_posix()) - + _initialize_environment(pype_version) return version_path +def _bootstrap_from_code(use_version): + """Bootstrap live code (or the one coming with frozen Pype. + + Args: + use_version: (str): specific version to use. + + Returns: + Path: path to sourced version. + + """ + # run through repos and add them to `sys.path` and `PYTHONPATH` + # set root + if getattr(sys, 'frozen', False): + pype_root = os.path.normpath( + os.path.dirname(sys.executable)) + local_version = bootstrap.get_version(Path(pype_root)) + else: + pype_root = os.path.normpath( + os.path.dirname(os.path.realpath(__file__))) + # get current version of Pype + local_version = bootstrap.get_local_live_version() + + os.environ["PYPE_VERSION"] = local_version + if use_version and use_version != local_version: + pype_versions = bootstrap.find_pype(include_zips=True) + version_path = BootstrapRepos.get_version_path_from_list( + use_version, pype_versions) + if version_path: + # use specified + bootstrap.add_paths_from_directory(version_path) + os.environ["PYPE_VERSION"] = use_version + else: + version_path = pype_root + os.environ["PYPE_ROOT"] = pype_root + repos = os.listdir(os.path.join(pype_root, "repos")) + repos = [os.path.join(pype_root, "repos", repo) for repo in repos] + # add self to python paths + repos.insert(0, pype_root) + for repo in repos: + sys.path.append(repo) + + # add venv 'site-packages' to PYTHONPATH + python_path = os.getenv("PYTHONPATH", "") + split_paths = python_path.split(os.pathsep) + split_paths += repos + # add pype tools + split_paths.append(os.path.join(os.environ["PYPE_ROOT"], "pype", "tools")) + # last one should be venv site-packages + # this is slightly convoluted as we can get here from frozen code too + # in case when we are running without any version installed. + if not getattr(sys, 'frozen', False): + split_paths.append(site.getsitepackages()[-1]) + # add common pype vendor + # (common for multiple Python interpreter versions) + split_paths.append(os.path.join( + os.environ["PYPE_ROOT"], "pype", "vendor", "python", "common")) + os.environ["PYTHONPATH"] = os.pathsep.join(split_paths) + + return Path(version_path) + + def boot(): """Bootstrap Pype.""" + version_path = None # ------------------------------------------------------------------------ # Play animation @@ -378,7 +469,12 @@ def boot(): # ------------------------------------------------------------------------ # Load environments from database # ------------------------------------------------------------------------ - + # set PYPE_ROOT to running location until proper version can be + # determined. + if getattr(sys, 'frozen', False): + os.environ["PYPE_ROOT"] = os.path.dirname(sys.executable) + else: + os.environ["PYPE_ROOT"] = os.path.dirname(__file__) set_environments() # ------------------------------------------------------------------------ @@ -394,37 +490,7 @@ def boot(): print(f"!!! {e}") sys.exit(1) else: - # run through repos and add them to sys.path and PYTHONPATH - # set root - pype_root = os.path.normpath( - os.path.dirname(os.path.realpath(__file__))) - # get current version of Pype - local_version = bootstrap.get_local_live_version() - os.environ["PYPE_VERSION"] = local_version - if use_version and use_version != local_version: - pype_versions = bootstrap.find_pype(include_zips=True) - version_path = BootstrapRepos.get_version_path_from_list( - use_version, pype_versions) - if version_path: - # use specified - bootstrap.add_paths_from_directory(version_path) - os.environ["PYPE_VERSION"] = use_version - else: - version_path = pype_root - os.environ["PYPE_ROOT"] = pype_root - repos = os.listdir(os.path.join(pype_root, "repos")) - repos = [os.path.join(pype_root, "repos", repo) for repo in repos] - # add self to python paths - repos.insert(0, pype_root) - for repo in repos: - sys.path.append(repo) - - pythonpath = os.getenv("PYTHONPATH", "") - paths = pythonpath.split(os.pathsep) - paths += repos - os.environ["PYTHONPATH"] = os.pathsep.join(paths) - - # TODO: add venv when running from source + version_path = _bootstrap_from_code(use_version) # set this to point either to `python` from venv in case of live code # or to `pype` or `pype_console` in case of frozen code @@ -433,14 +499,16 @@ def boot(): # TODO: DEPRECATE remove when `pype-config` dissolves into Pype for good. # PYPE_MODULE_ROOT should be changed to PYPE_REPOS_ROOT # This needs to replace environment building in hosts + # .-=-----------------------=-=. ^ .=-=--------------------------=-. os.environ["PYPE_MODULE_ROOT"] = os.environ["PYPE_ROOT"] + # -=------------------------=-=. v .=-=--------------------------=-. - # TODO: add pype tools and vendor to environment - os.environ["PYTHONPATH"] = os.pathsep.join( - [os.environ["PYTHONPATH"], - os.path.join(os.environ["PYPE_ROOT"], "pype", "tools"), - os.path.join(os.environ["PYPE_ROOT"], "pype", "vendor")]) + if getattr(sys, 'frozen', False): + os.environ["PYPE_REPOS_ROOT"] = os.environ["PYPE_ROOT"] + else: + os.environ["PYPE_REPOS_ROOT"] = os.path.join( + os.environ["PYPE_ROOT"], "repos") # delete Pype module from cache so it is used from specific version try: @@ -457,6 +525,7 @@ def boot(): print(">>> loading environments ...") set_modules_environments() + assert version_path, "Version path not defined." info = get_info() info.insert(0, f">>> Using Pype from [ {version_path} ]") @@ -485,42 +554,42 @@ def get_info() -> list: components = get_default_components() - infos = [] + inf = [] if not getattr(sys, 'frozen', False): - infos.append(("Pype variant", "staging")) + inf.append(("Pype variant", "staging")) else: - infos.append(("Pype variant", "production")) - infos.append(("Running pype from", os.environ.get('PYPE_ROOT'))) - infos.append(("Using mongodb", components["host"])) + inf.append(("Pype variant", "production")) + inf.append(("Running pype from", os.environ.get('PYPE_ROOT'))) + inf.append(("Using mongodb", components["host"])) if os.environ.get("FTRACK_SERVER"): - infos.append(("Using FTrack at", - os.environ.get("FTRACK_SERVER"))) + inf.append(("Using FTrack at", + os.environ.get("FTRACK_SERVER"))) if os.environ.get('DEADLINE_REST_URL'): - infos.append(("Using Deadline webservice at", - os.environ.get("DEADLINE_REST_URL"))) + inf.append(("Using Deadline webservice at", + os.environ.get("DEADLINE_REST_URL"))) if os.environ.get('MUSTER_REST_URL'): - infos.append(("Using Muster at", - os.environ.get("MUSTER_REST_URL"))) + inf.append(("Using Muster at", + os.environ.get("MUSTER_REST_URL"))) # Reinitialize PypeLogger.initialize() log_components = PypeLogger.log_mongo_url_components if log_components["host"]: - infos.append(("Logging to MongoDB", log_components["host"])) - infos.append((" - port", log_components["port"] or "")) - infos.append((" - database", PypeLogger.log_database_name)) - infos.append((" - collection", PypeLogger.log_collection_name)) - infos.append((" - user", log_components["username"] or "")) + inf.append(("Logging to MongoDB", log_components["host"])) + inf.append((" - port", log_components["port"] or "")) + inf.append((" - database", PypeLogger.log_database_name)) + inf.append((" - collection", PypeLogger.log_collection_name)) + inf.append((" - user", log_components["username"] or "")) if log_components["auth_db"]: - infos.append((" - auth source", log_components["auth_db"])) + inf.append((" - auth source", log_components["auth_db"])) - maximum = max(len(i[0]) for i in infos) + maximum = max(len(i[0]) for i in inf) formatted = [] - for info in infos: + for info in inf: padding = (maximum - len(info[0])) + 1 formatted.append( "... {}:{}[ {} ]".format(info[0], " " * padding, info[1])) diff --git a/tools/build.ps1 b/tools/build.ps1 index f2e6b3ba0d..9e067acb34 100644 --- a/tools/build.ps1 +++ b/tools/build.ps1 @@ -175,6 +175,14 @@ Write-Host "OK" -ForegroundColor green Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Building Pype ..." $out = & python setup.py build 2>&1 +if ($LASTEXITCODE -ne 0) +{ + Write-Host "!!! " -NoNewLine -ForegroundColor Red + Write-Host "Build failed. Check the log: " -NoNewline + Write-Host ".\build\build.log" -ForegroundColor Yellow + deactivate + Exit-WithCode $LASTEXITCODE +} Set-Content -Path "$($pype_root)\build\build.log" -Value $out & python -B "$($pype_root)\tools\build_dependencies.py" diff --git a/tools/build_dependencies.py b/tools/build_dependencies.py index 9b3618cd15..d28b631eca 100644 --- a/tools/build_dependencies.py +++ b/tools/build_dependencies.py @@ -88,7 +88,10 @@ elif sys.platform == "win32": build_dir = Path(os.path.dirname(__file__)).parent / "build" / build_dir _print(f"Using build at {build_dir}", 2) -assert build_dir.exists(), "Build directory doesn't exist" +if not build_dir.exists(): + _print("Build directory doesn't exist", 1) + _print("Probably freezing of code failed. Check ./build/build.log", 3) + sys.exit(1) deps_dir = build_dir / "dependencies" diff --git a/tools/create_env.ps1 b/tools/create_env.ps1 index bb04368964..38737a23a9 100644 --- a/tools/create_env.ps1 +++ b/tools/create_env.ps1 @@ -9,7 +9,7 @@ .EXAMPLE -PS> .\build.ps1 +PS> .\create_env.ps1 #> diff --git a/tools/create_zip.ps1 b/tools/create_zip.ps1 index a78b06bb20..35bddfeb4e 100644 --- a/tools/create_zip.ps1 +++ b/tools/create_zip.ps1 @@ -1,6 +1,6 @@ <# .SYNOPSIS - Helper script create virtual env. + Helper script create distributable Pype zip. .DESCRIPTION This script will detect Python installation, create venv and install @@ -9,7 +9,7 @@ .EXAMPLE -PS> .\build.ps1 +PS> .\create_zip.ps1 #> diff --git a/tools/run_mongo.ps1 b/tools/run_mongo.ps1 index 45d4679940..1b6d95ca57 100644 --- a/tools/run_mongo.ps1 +++ b/tools/run_mongo.ps1 @@ -1,7 +1,91 @@ +<# +.SYNOPSIS + Helper script to run mongodb. + +.DESCRIPTION + This script will detect mongodb, add it to the PATH and launch it on specified port and db location. + +.EXAMPLE + +PS> .\run_mongo.ps1 + +#> + +$art = @" + + + ____________ + /\ ___ \ + \ \ \/_\ \ + \ \ _____/ ______ ___ ___ ___ + \ \ \___/ /\ \ \ \\ \\ \ + \ \____\ \ \_____\ \__\\__\\__\ + \/____/ \/_____/ . PYPE Club . + +"@ + +Write-Host $art -ForegroundColor DarkGreen + +function Exit-WithCode($exitcode) { + # Only exit this host process if it's a child of another PowerShell parent process... + $parentPID = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId=$PID" | Select-Object -Property ParentProcessId).ParentProcessId + $parentProcName = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId=$parentPID" | Select-Object -Property Name).Name + if ('powershell.exe' -eq $parentProcName) { $host.SetShouldExit($exitcode) } + + exit $exitcode +} + + +function Find-Mongo { + Write-Host ">>> " -NoNewLine -ForegroundColor Green + Write-Host "Detecting MongoDB ... " -NoNewline + if (-not (Get-Command "mongod" -ErrorAction SilentlyContinue)) { + if(Test-Path 'C:\Program Files\MongoDB\Server\*\bin\mongod.exe' -PathType Leaf) { + # we have mongo server installed on standard Windows location + # so we can inject it to the PATH. We'll use latest version available. + $mongoVersions = Get-ChildItem -Directory 'C:\Program Files\MongoDB\Server' | Sort-Object -Property {$_.Name -as [int]} + if(Test-Path "C:\Program Files\MongoDB\Server\$($mongoVersions[-1])\bin\mongod.exe" -PathType Leaf) { + $env:PATH="$($env:PATH);C:\Program Files\MongoDB\Server\$($mongoVersions[-1])\bin\" + Write-Host "OK" -ForegroundColor Green + Write-Host " - auto-added from [ " -NoNewline + Write-Host "C:\Program Files\MongoDB\Server\$($mongoVersions[-1])\bin\" -NoNewLine -ForegroundColor Cyan + Write-Host " ]" + } else { + Write-Host "FAILED " -NoNewLine -ForegroundColor Red + Write-Host "MongoDB not detected" -ForegroundColor Yellow + Write-Host "Tried to find it on standard location [ " -NoNewline -ForegroundColor Gray + Write-Host "C:\Program Files\MongoDB\Server\$($mongoVersions[-1])\bin\" -NoNewline -ForegroundColor White + Write-Host " ] but failed." -ForegroundColor Gray + Exit-WithCode 1 + } + } else { + Write-Host "FAILED " -NoNewLine -ForegroundColor Red + Write-Host "MongoDB not detected in PATH" -ForegroundColor Yellow + Exit-WithCode 1 + } + + } else { + Write-Host "OK" -ForegroundColor Green + } + <# + .SYNOPSIS + Function to detect mongod in path. + .DESCRIPTION + This will test presence of mongod in PATH. If it's not there, it will try + to find it in default install location. It support different mongo versions + (using latest if found). When mongod is found, path to it is added to PATH + #> +} + $script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent $pype_root = (Get-Item $script_dir).parent.FullName -& "$($pype_root)\venv\Scripts\Activate.ps1" +# mongodb port +$port = 2707 -python "$($pype_root)\start.py" mongodb -deactivate +# path to database +$dbpath = (Get-Item $pype_root).parent.FullName + "\mongo_db_data" + +Find-Mongo +$mongo = Get-Command "mongod" | Select-Object -ExpandProperty Definition +Start-Process -FilePath $mongo "--dbpath $($dbpath) --port $($port)" diff --git a/tools/run_settings.ps1 b/tools/run_settings.ps1 index 64d35a4b81..725e0cd8a0 100644 --- a/tools/run_settings.ps1 +++ b/tools/run_settings.ps1 @@ -1,3 +1,16 @@ +<# +.SYNOPSIS + Helper script to Pype Settings UI + +.DESCRIPTION + This script will run Pype and open Settings UI. + +.EXAMPLE + +PS> .\run_settings.ps1 + +#> + $script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent $pype_root = (Get-Item $script_dir).parent.FullName diff --git a/tools/run_tests.ps1 b/tools/run_tests.ps1 index 498a3c3d7d..4159114ad3 100644 --- a/tools/run_tests.ps1 +++ b/tools/run_tests.ps1 @@ -1,3 +1,18 @@ +<# +.SYNOPSIS + Helper script to build Pype. + +.DESCRIPTION + This script will detect Python installation, create venv and install + all necessary packages from `requirements.txt` needed by Pype to be + included during application freeze on Windows. + +.EXAMPLE + +PS> .\run_test.ps1 + +#> + function Exit-WithCode($exitcode) { # Only exit this host process if it's a child of another PowerShell parent process... $parentPID = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId=$PID" | Select-Object -Property ParentProcessId).ParentProcessId diff --git a/tools/run_tray.ps1 b/tools/run_tray.ps1 index f794f85929..0b75354756 100644 --- a/tools/run_tray.ps1 +++ b/tools/run_tray.ps1 @@ -1,3 +1,15 @@ +<# +.SYNOPSIS + Helper script Pype Tray. + +.DESCRIPTION + + +.EXAMPLE + +PS> .\run_tray.ps1 + +#> $script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent $pype_root = (Get-Item $script_dir).parent.FullName