From 18d63433e0f190321038cf1b6c196d7a8f06f34f Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Fri, 8 Jan 2021 19:29:25 +0100 Subject: [PATCH] fixed tests, renamed entry point --- igniter/bootstrap_repos.py | 30 ++++++++++++++++++++------- igniter/install_thread.py | 10 ++++++++- setup.py | 12 +++++++---- pype.py => start.py | 1 + tests/igniter/test_bootstrap_repos.py | 27 ++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 13 deletions(-) rename pype.py => start.py (99%) diff --git a/igniter/bootstrap_repos.py b/igniter/bootstrap_repos.py index 448282b30b..29f6c7249c 100644 --- a/igniter/bootstrap_repos.py +++ b/igniter/bootstrap_repos.py @@ -346,12 +346,12 @@ class BootstrapRepos: if file in self.zip_filter: continue - zip_file.write( - os.path.relpath(os.path.join(root, file), - os.path.join(include_dir, '..')), - os.path.relpath(os.path.join(root, file), + file_name = os.path.relpath( + os.path.join(root, file), + os.path.join(include_dir, '..')) + arc_name = os.path.relpath(os.path.join(root, file), os.path.join(include_dir)) - ) + zip_file.write(file_name, arc_name) # add pype itself if include_pype: for root, _, files in os.walk("pype"): @@ -491,7 +491,13 @@ class BootstrapRepos: # contain Pype. for file in dir_to_search.iterdir(): - result = PypeVersion.version_in_str(file.stem) + # if file, strip extension, in case of dir not. + if file.is_dir(): + name = file.name + else: + name = file.stem + + result = PypeVersion.version_in_str(name) if result[0]: detected_version = result[1] @@ -500,8 +506,16 @@ class BootstrapRepos: # if item is directory that might (based on it's name) # contain Pype version, check if it really does contain # Pype and that their versions matches. - version_check = PypeVersion( - version=BootstrapRepos.get_version(file)) + try: + # add one 'pype' level as inside dir there should + # be many other repositories. + version_str = BootstrapRepos.get_version( + file / "pype") + version_check = PypeVersion(version=version_str) + except ValueError: + self._log.error( + f"cannot determine version from {file}") + continue if version_check != detected_version: self._log.error( (f"dir version ({detected_version}) and " diff --git a/igniter/install_thread.py b/igniter/install_thread.py index e4253958e5..e31de731ed 100644 --- a/igniter/install_thread.py +++ b/igniter/install_thread.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """Working thread for installer.""" import os +import sys from zipfile import ZipFile from Qt.QtCore import QThread, Signal @@ -96,7 +97,14 @@ class InstallThread(QThread): f"currently running one {local_version}" ), False) else: - self.message.emit("None detected.", False) + # we cannot build install package from frozen code. + if getattr(sys, 'frozen', False): + self.message.emit("None detected.", True) + self.message.emit(("Please set path to Pype sources to " + "build installation."), False) + return + else: + self.message.emit("None detected.", False) self.message.emit( f"We will use local Pype version {local_version}", False) diff --git a/setup.py b/setup.py index fcc2ddaf2f..38b8cf1dbc 100644 --- a/setup.py +++ b/setup.py @@ -13,8 +13,7 @@ __version__ = version["__version__"] base = None if sys.platform == "win32": - # base = "Win32GUI" - ... + base = "Win32GUI" # ----------------------------------------------------------------------- # build_exe @@ -34,7 +33,9 @@ install_requires = [ "jinxed", "blessed", "Qt", - "speedcopy" + "speedcopy", + "googleapiclient", + "httplib2" ] includes = [ @@ -70,7 +71,10 @@ buildOptions = dict( ) -executables = [Executable("pype.py", base=base, targetName="pype")] +executables = [ + Executable("start.py", base=None, targetName="pype_console"), + Executable("start.py", base=base, targetName="pype") +] setup( name="pype", diff --git a/pype.py b/start.py similarity index 99% rename from pype.py rename to start.py index d613e8e0fc..ad5411a679 100644 --- a/pype.py +++ b/start.py @@ -167,6 +167,7 @@ def boot(): m = re.search(r"--use-version=(?P\d+\.\d+\.\d*.+?)", arg) if m and m.group('version'): use_version = m.group('version') + sys.argv.remove(arg) break if not os.getenv("PYPE_MONGO"): diff --git a/tests/igniter/test_bootstrap_repos.py b/tests/igniter/test_bootstrap_repos.py index a04632c3cb..730c6f2917 100644 --- a/tests/igniter/test_bootstrap_repos.py +++ b/tests/igniter/test_bootstrap_repos.py @@ -224,6 +224,17 @@ def test_find_pype(fix_bootstrap, tmp_path_factory, monkeypatch, printer): test_pype(prefix="foo-v", version="3.2.0", suffix=".zip", type="zip", valid=True) ] + + test_versions_4 = [ + test_pype(prefix="foo-v", version="10.0.0", + suffix="", type="dir", valid=True), + test_pype(prefix="lom-v", version="11.2.6", + suffix=".zip", type="dir", valid=False), + test_pype(prefix="bom-v", version="7.2.7-client", + suffix=".zip", type="zip", valid=True), + test_pype(prefix="woo-v", version="7.2.8-client-strange", + suffix=".zip", type="txt", valid=False) + ] def _create_invalid_zip(path: Path): with ZipFile(path, "w") as zf: @@ -286,6 +297,12 @@ def test_find_pype(fix_bootstrap, tmp_path_factory, monkeypatch, printer): for test_file in test_versions_3: _build_test_item(g_path, test_file) + # dir vs zip preference + dir_path = tmp_path_factory.mktemp("dirZipPath") + for test_file in test_versions_4: + _build_test_item(dir_path, test_file) + + printer("testing finding Pype in given path ...") result = fix_bootstrap.find_pype(g_path, True) # we should have results as file were created assert result is not None, "no Pype version found" @@ -347,3 +364,13 @@ def test_find_pype(fix_bootstrap, tmp_path_factory, monkeypatch, printer): ) ) assert result[-1].path == expected_path, "not a latest version of Pype 1" + + result = fix_bootstrap.find_pype(dir_path, True) + assert result is not None, "no Pype versions found" + expected_path = Path( + e_path / "{}{}{}".format( + test_versions_4[0].prefix, + test_versions_4[0].version, + test_versions_4[0].suffix + ) + )