def test_make_sh_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"): make(packages, repositories, {}, str(tmpdir))
def test_make_one_pip_package(captured_shell_commands, tmpdir): packages = {"pyaml": "20.4.0"} repositories = { "pyaml": { "20.4.0": { "source": "pypi", "make": "pip", "maintainer": "someone", "depends": [], } } } make(packages, repositories, {}, str(tmpdir)) assert len(captured_shell_commands) == 2 assert "mkdir" in " ".join(captured_shell_commands[0]) assert "pip install pyaml" in " ".join(captured_shell_commands[1])
def test_make_pip_package_from_latest(captured_shell_commands, tmpdir): packages = {"yaml": LATEST_PACKAGE_ALIAS} repositories = { "yaml": { LATEST_PACKAGE_ALIAS: { "source": "pypi", "pypi_package_name": "PyYaml", "make": "pip", "maintainer": "someone", "depends": [], } } } with patch("komodo.build.latest_pypi_version") as mock_latest_version: mock_latest_version.return_value = "1.0.0" make(packages, repositories, {}, str(tmpdir)) mock_latest_version.assert_called_once_with("PyYaml") assert len(captured_shell_commands) == 2 assert "mkdir" in " ".join(captured_shell_commands[0]) assert "pip install PyYaml==1.0.0" in " ".join(captured_shell_commands[1])
def test_make_with_empty_pkgs(captured_shell_commands, tmpdir): make({}, {}, {}, str(tmpdir)) assert len(captured_shell_commands) == 1 assert "mkdir" in " ".join(captured_shell_commands[0])
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])