Ejemplo n.º 1
0
def test_get_version_path_from_list():
    versions = [
        PypeVersion(1, 2, 3, path=Path('/foo/bar')),
        PypeVersion(3, 4, 5, variant="staging", path=Path("/bar/baz")),
        PypeVersion(6, 7, 8, client="x", path=Path("boo/goo"))
    ]
    path = BootstrapRepos.get_version_path_from_list("3.4.5-staging", versions)

    assert path == Path("/bar/baz")
Ejemplo n.º 2
0
def test_search_string_for_pype_version(printer):
    strings = [("3.0.1", True), ("foo-3.0", False), ("foo-3.0.1", True),
               ("3", False), ("foo-3.0.1-client-staging", True),
               ("foo-3.0.1-bar-baz", True)]
    for ver_string in strings:
        printer(f"testing {ver_string[0]} should be {ver_string[1]}")
        assert PypeVersion.version_in_str(ver_string[0])[0] == ver_string[1]
Ejemplo n.º 3
0
def test_pype_version():
    v1 = PypeVersion(1, 2, 3)
    assert str(v1) == "1.2.3"

    v2 = PypeVersion(1, 2, 3, client="x")
    assert str(v2) == "1.2.3-x"
    assert v1 < v2

    v3 = PypeVersion(1, 2, 3, variant="staging")
    assert str(v3) == "1.2.3-staging"

    v4 = PypeVersion(1, 2, 3, variant="staging", client="client")
    assert str(v4) == "1.2.3-client-staging"
    assert v3 < v4
    assert v1 < v4

    v5 = PypeVersion(1, 2, 3, variant="foo", client="x")
    assert str(v5) == "1.2.3-x"
    assert v4 < v5

    v6 = PypeVersion(1, 2, 3, variant="foo")
    assert str(v6) == "1.2.3"

    v7 = PypeVersion(2, 0, 0)
    assert v1 < v7

    v8 = PypeVersion(0, 1, 5)
    assert v8 < v7

    v9 = PypeVersion(1, 2, 4)
    assert v9 > v1

    v10 = PypeVersion(1, 2, 2)
    assert v10 < v1

    v11 = PypeVersion(1, 2, 3, path=Path("/foo/bar"))
    assert v10 < v11

    assert v5 == v2

    sort_versions = [
        PypeVersion(3, 2, 1),
        PypeVersion(1, 2, 3),
        PypeVersion(0, 0, 1),
        PypeVersion(4, 8, 10),
        PypeVersion(4, 8, 20),
        PypeVersion(4, 8, 9),
        PypeVersion(1, 2, 3, variant="staging"),
        PypeVersion(1, 2, 3, client="client")
    ]
    res = sorted(sort_versions)

    assert res[0] == sort_versions[2]
    assert res[1] == sort_versions[6]
    assert res[2] == sort_versions[1]
    assert res[-1] == sort_versions[4]

    str_versions = [
        "5.5.1",
        "5.5.2-client",
        "5.5.3-client-strange",
        "5.5.4-staging",
        "5.5.5-staging-client",
        "5.6.3",
        "5.6.3-staging"
    ]
    res_versions = []
    for v in str_versions:
        res_versions.append(PypeVersion(version=v))

    sorted_res_versions = sorted(res_versions)

    assert str(sorted_res_versions[0]) == str_versions[0]
    assert str(sorted_res_versions[-1]) == str_versions[5]

    with pytest.raises(ValueError):
        _ = PypeVersion()

    with pytest.raises(ValueError):
        _ = PypeVersion(major=1)

    with pytest.raises(ValueError):
        _ = PypeVersion(version="booobaa")

    v11 = PypeVersion(version="4.6.7-client-staging")
    assert v11.major == 4
    assert v11.minor == 6
    assert v11.subversion == 7
    assert v11.variant == "staging"
    assert v11.client == "client"
Ejemplo n.º 4
0
def test_get_main_version():
    ver = PypeVersion(1, 2, 3, variant="staging", client="foo")
    assert ver.get_main_version() == "1.2.3"
Ejemplo n.º 5
0
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.

    Returns:
        Path: Path to version to be used.

    Raises:
        RuntimeError: If no Pype version are found or no staging version
            (if requested).

    """
    pype_version = None
    pype_versions = bootstrap.find_pype(include_zips=True,
                                        staging=use_staging)
    if not os.getenv("PYPE_TRYOUT"):
        try:
            # use latest one found (last in the list is latest)
            pype_version = pype_versions[-1]
        except IndexError:
            # no pype version found, run Igniter and ask for them.
            print('*** No Pype versions found.')
            print("--- launching setup UI ...")
            import igniter
            return_code = igniter.open_dialog()
            if return_code == 2:
                os.environ["PYPE_TRYOUT"] = "1"
            if return_code == 3:
                # run Pype after installation

                print('>>> Finding Pype again ...')
                pype_versions = bootstrap.find_pype(staging=use_staging)
                try:
                    pype_version = pype_versions[-1]
                except IndexError:
                    print(("!!! Something is wrong and we didn't "
                          "found it again."))
                    pype_versions = None
                    sys.exit(1)
            elif return_code != 2:
                print(f"  . finished ({return_code})")
                sys.exit(return_code)

    if not pype_versions:
        # no Pype versions found anyway, lets use then the one
        # shipped with frozen Pype
        if not os.getenv("PYPE_TRYOUT"):
            print("*** Still no luck finding Pype.")
            print(("*** We'll try to use the one coming "
                   "with Pype installation."))
        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:
            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} ]")
        print(f"    From {version_path}")

    # test if latest detected is installed (in user data dir)
    is_inside = False
    try:
        is_inside = pype_version.path.resolve().relative_to(
            bootstrap.data_dir)
    except ValueError:
        # if relative path cannot be calculated, Pype version is not
        # inside user data dir
        pass

    if not is_inside:
        # install latest version to user data dir
        version_path = bootstrap.install_version(
            pype_version, force=True)

    if pype_version.path.is_file():
        print(">>> Extracting zip file ...")
        version_path = bootstrap.extract_pype(pype_version)
        pype_version.path = version_path

    _initialize_environment(pype_version)
    return version_path