예제 #1
0
def test_fetch_git_hash(captured_shell_commands, tmpdir):
    packages = {"ert": "main"}
    repositories = {
        "ert": {
            "main": {
                "source": "git://github.com/equinor/ert.git",
                "fetch": "git",
                "make": "sh",
                "maintainer": "someone",
                "makefile": "setup-py.sh",
                "depends": [],
            }
        }
    }

    with patch("komodo.fetch.get_git_revision_hash"
               ) as mock_get_git_revision_hash:
        mock_get_git_revision_hash.return_value = (
            "439368d5f2e2eb0c0209e1b43afe6e88d58327d3")
        git_hashes = fetch(packages, repositories, str(tmpdir))
        assert (
            captured_shell_commands[0] ==
            "git clone -b main -q --recursive -- git://github.com/equinor/ert.git ert-main"
        )
        assert git_hashes == {
            "ert": "439368d5f2e2eb0c0209e1b43afe6e88d58327d3"
        }
예제 #2
0
def test_version_plus_marker(captured_shell_commands, tmpdir):
    packages = {"ert": "2.25.0+py10"}
    repositories = {
        "ert": {
            "2.25.0+py10": {
                "source": "pypi",
                "make": "pip",
                "maintainer": "someone",
                "depends": [],
            }
        }
    }
    fetch(packages, repositories, str(tmpdir))
    assert len(captured_shell_commands) == 1

    command = " ".join(captured_shell_commands[0])
    assert command.startswith("pip download")
    assert "ert==2.25.0" in command
예제 #3
0
def test_fetch_git_does_not_accept_pypi_package_name(captured_shell_commands,
                                                     tmpdir):
    packages = {"ert": "2.16.0"}
    repositories = {
        "ert": {
            "2.16.0": {
                "source": "git://github.com/equinor/ert.git",
                "pypi_package_name": "some-other-name",
                "fetch": "git",
                "make": "sh",
                "maintainer": "someone",
                "depends": [],
            }
        }
    }

    with pytest.raises(ValueError, match="pypi_package_name"):
        fetch(packages, repositories, str(tmpdir))
예제 #4
0
def test_fetch_pip_with_latest_version(captured_shell_commands, tmpdir):
    packages = {"ert": LATEST_PACKAGE_ALIAS}
    repositories = {
        "ert": {
            LATEST_PACKAGE_ALIAS: {
                "source": "pypi",
                "pypi_package_name": "ert3",
                "fetch": "pip",
                "make": "pip",
                "maintainer": "someone",
                "depends": [],
            }
        }
    }

    with patch("komodo.fetch.latest_pypi_version") as mock_latest_ver:
        mock_latest_ver.return_value = "1.0.0"
        fetch(packages, repositories, str(tmpdir))
        mock_latest_ver.assert_called_once_with("ert3")
        assert "ert3==1.0.0" in captured_shell_commands[0]
예제 #5
0
def test_fetch_with_empty_pypi_package_name(captured_shell_commands, tmpdir):
    packages = {"yaml": "20.4.0"}
    repositories = {
        "yaml": {
            "20.4.0": {
                "source": "pypi",
                "pypi_package_name": "PyYaml",
                "make": "pip",
                "maintainer": "someone",
                "depends": [],
            }
        }
    }
    fetch(packages, repositories, str(tmpdir))

    assert len(captured_shell_commands) == 1

    command = " ".join(captured_shell_commands[0])

    assert command.startswith("pip download")
    assert "PyYaml" in command
예제 #6
0
def test_allow_pre_release_with_dash(captured_shell_commands, tmpdir):
    packages = {"ert": "2.25.0-rc1"}
    repositories = {
        "ert": {
            "2.25.0-rc1": {
                "source": "pypi",
                "make": "pip",
                "maintainer": "someone",
                "depends": [],
            }
        }
    }

    fetch(packages, repositories, str(tmpdir))

    assert len(captured_shell_commands) == 1

    command = " ".join(captured_shell_commands[0])

    assert command.startswith("pip download")
    assert "ert==2.25.0-rc1" in command
예제 #7
0
파일: cli.py 프로젝트: equinor/komodo
def _main(args):
    args.prefix = os.path.abspath(args.prefix)

    data = Data(extra_data_dirs=args.extra_data_dirs)

    if args.download or (not args.build and not args.install):
        git_hashes = fetch(args.pkgs,
                           args.repo,
                           outdir=args.cache,
                           pip=args.pip)

    if args.download and not args.build:
        sys.exit(0)

    # append root to the temporary build dir, as we want a named root/
    # directory as the distribution root, organised under the distribution name
    # (release)
    tmp_prefix = os.path.join(os.path.join(args.prefix), args.release, "root")
    fakeroot = os.path.abspath(args.release)
    if args.build or not args.install:
        make(
            args.pkgs,
            args.repo,
            data,
            prefix=tmp_prefix,
            dlprefix=args.cache,
            builddir=args.tmp,
            jobs=args.jobs,
            cmk=args.cmake,
            pip=args.pip,
            virtualenv=args.virtualenv,
            fakeroot=fakeroot,
        )
        shell("mv {} {}".format(args.release + tmp_prefix, args.release))
        shell("rmdir -p --ignore-fail-on-non-empty {}".format(
            os.path.dirname(args.release + tmp_prefix)))

    if args.build and not args.install:
        sys.exit(0)

    # create the enable script
    for tmpl, target in [("enable.in", "enable"),
                         ("enable.csh.in", "enable.csh")]:
        # TODO should args.release be release_path?
        with open("{}/{}".format(args.release, target), "w") as f:
            f.write(
                shell([
                    "m4 {}".format(data.get("enable.m4")),
                    "-D komodo_prefix={}".format(tmp_prefix),
                    "-D komodo_pyver={}".format(args.pyver),
                    "-D komodo_release={}".format(args.release),
                    data.get(tmpl),
                ]).decode("utf-8"))

    with open(args.locations_config) as defs, open(
            os.path.join(args.release, "local"), "w") as local_activator, open(
                os.path.join(args.release, "local.csh"),
                "w") as local_csh_activator:
        defs = yml.safe_load(defs)
        local.write_local_activators(data, defs, local_activator,
                                     local_csh_activator)

    releasedoc = os.path.join(args.release, args.release)
    with open(releasedoc, "w") as y:
        release = {}
        for pkg, ver in args.pkgs.items():
            entry = args.repo[pkg][ver]
            maintainer = args.repo[pkg][ver]["maintainer"]
            if ver == LATEST_PACKAGE_ALIAS:
                ver = latest_pypi_version(entry.get("pypi_package_name", pkg))
            elif args.repo[pkg][ver].get("fetch") == "git":
                ver = git_hashes[pkg]
            release[pkg] = {
                "version": ver,
                "maintainer": maintainer,
            }
        yml.dump(release, y, default_flow_style=False)

    if args.dry_run:
        return

    print("Installing {} to {}".format(args.release, args.prefix))
    install_root = os.path.join(args.prefix, args.release, "root")

    shell("{1} {0} .{0} {0}".format(args.release, args.renamer))
    shell("rsync -a .{} {}".format(args.release, args.prefix), sudo=args.sudo)

    if os.path.exists("{1}/{0}".format(args.release, args.prefix)):
        shell(
            "{2} {0} {0}.delete {1}/{0}".format(args.release, args.prefix,
                                                args.renamer),
            sudo=args.sudo,
        )

    shell(
        "{2} .{0} {0} {1}/.{0}".format(args.release, args.prefix,
                                       args.renamer),
        sudo=args.sudo,
    )
    shell("rm -rf {1}/{0}.delete".format(args.release, args.prefix),
          sudo=args.sudo)

    if args.tmp:
        # Allows e.g. pip to use this folder as tmpfolder, instead of in some
        # cases falling back to /tmp, which is undesired when building on nfs.
        os.environ["TMPDIR"] = args.tmp

    print('Fixup #! in pip-provided packages if bin exist')
    release_path = os.path.join(args.prefix, args.release)
    release_root = os.path.join(release_path, "root")
    for pkg, ver in args.pkgs.items():
        current = args.repo[pkg][ver]
        if current["make"] != "pip":
            continue

        package_name = current.get("pypi_package_name", pkg)
        if ver == LATEST_PACKAGE_ALIAS:
            ver = latest_pypi_version(package_name)
        shell_input = [
            args.pip,
            "install {}=={}".format(package_name, strip_version(ver)),
            "--prefix",
            release_root,
            "--no-index",
            "--no-deps",
            "--ignore-installed",
            "--cache-dir {}".format(args.cache),
            "--find-links {}".format(args.cache),
        ]
        shell_input.append(current.get("makeopts"))

        print(shell(shell_input, sudo=args.sudo))

    fixup_python_shebangs(args.prefix, args.release)

    switch.create_activator_switch(data, args.prefix, args.release)

    # run any post-install scripts on the release
    if args.postinst:
        shell([args.postinst, release_path])

    print("running", "find {} -name '*.pyc' -delete".format(release_root))
    shell("find {} -name '*.pyc' -delete".format(release_root))

    print("Setting permissions",
          [data.get("set_permissions.sh"), release_path])
    shell([data.get("set_permissions.sh"), release_path])