Skip to content

Commit

Permalink
Fix pylint unused-argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Jan 11, 2024
1 parent 34883fd commit ff8e04e
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 101 deletions.
188 changes: 119 additions & 69 deletions komodo/build.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python


import hashlib
import itertools as itr
import os
import pathlib
import stat
import sys
from pathlib import Path
from typing import Dict, Union

import requests

Expand Down Expand Up @@ -42,7 +42,7 @@ def dfs(pkg, version, pkgs, repo):
return flatten(dependencies)


def rpm(pkg, ver, path, data, prefix, *args, **kwargs):
def rpm(pkg, ver, path, prefix):
# cpio always outputs to cwd, can't be overriden with switches
with pushd(prefix):
print(f"Installing {pkg} ({ver}) from rpm")
Expand All @@ -64,20 +64,19 @@ def cmake(
pkg,
ver,
path,
data,
prefix,
builddir,
makeopts,
jobs,
*args,
cmake="cmake",
**kwargs,
cmake,
fakeroot,
ld_lib_path=None,
binpath=None,
):
bdir = f"{pkg}-{ver}-build"
if builddir is not None:
bdir = os.path.join(builddir, bdir)

fakeroot = kwargs["fakeroot"]
fakeprefix = fakeroot + prefix

flags = [
Expand All @@ -92,9 +91,9 @@ def cmake(

Path(bdir).mkdir(parents=True, exist_ok=True)
with pushd(bdir):
os.environ["LD_LIBRARY_PATH"] = kwargs.get("ld_lib_path")
os.environ["LD_LIBRARY_PATH"] = ld_lib_path
_pre_PATH = os.environ["PATH"]
os.environ["PATH"] = kwargs.get("binpath")
os.environ["PATH"] = binpath

print(f"Installing {pkg} ({ver}) from source with cmake")
shell([cmake, path, *flags, makeopts])
Expand All @@ -105,60 +104,75 @@ def cmake(
os.environ["PATH"] = _pre_PATH


def sh(pkg, ver, pkgpath, data, prefix, makefile, *args, **kwargs):
def sh(
pkg,
ver,
pkgpath,
data,
prefix,
makefile,
fakeroot,
pythonpath,
binpath,
pip,
virtualenv,
ld_lib_path,
makeopts,
jobs=None,
cmake=None,
):
makefile = data.get(makefile)

with pushd(pkgpath):
cmd = [
f"bash {makefile} --prefix {prefix}",
f"--fakeroot {kwargs['fakeroot']}",
f"--fakeroot {fakeroot}",
f"--python {prefix}/bin/python",
]
if "jobs" in kwargs:
cmd.append(f"--jobs {kwargs['jobs']}")
if "cmake" in kwargs:
cmd.append(f"--cmake {kwargs['cmake']}")
cmd.append(f"--pythonpath {kwargs['pythonpath']}")
cmd.append(f"--path {kwargs['binpath']}")
cmd.append(f"--pip {kwargs['pip']}")
cmd.append(f"--virtualenv {kwargs['virtualenv']}")
cmd.append(f"--ld-library-path {kwargs['ld_lib_path']}")
cmd.append(kwargs.get("makeopts"))
if jobs:
cmd.append(f"--jobs {jobs}")
if cmake:
cmd.append(f"--cmake {cmake}")
cmd.append(f"--pythonpath {pythonpath}")
cmd.append(f"--path {binpath}")
cmd.append(f"--pip {pip}")
cmd.append(f"--virtualenv {virtualenv}")
cmd.append(f"--ld-library-path {ld_lib_path}")
cmd.append(makeopts)

print(f"Installing {pkg} ({ver}) from sh")
shell(cmd)


def rsync(pkg, ver, pkgpath, data, prefix, *args, **kwargs):
def rsync(pkg, ver, pkgpath, prefix, fakeroot, makeopts=None):
print(f"Installing {pkg} ({ver}) with rsync")
# assume a root-like layout in the pkgpath dir, and just copy it
shell(
[
"rsync -am",
kwargs.get("makeopts"),
makeopts,
f"{pkgpath}/",
kwargs["fakeroot"] + prefix,
fakeroot + prefix,
],
)


def download(pkg, ver, pkgpath, data, prefix, *args, **kwargs):
def download(pkg, ver, prefix, url, input_hash, fakeroot, destination):
print(f"Installing {pkg} ({ver}) with download")

url = kwargs["url"]
if not url.startswith("https"):
msg = f"{url} does not use https:// protocol"
raise ValueError(msg)

hash_type, hash_value = kwargs["hash"].split(":")
hash_type, hash_value = input_hash.split(":")
if hash_type != "sha256":
msg = f"Hash type {hash_type} given - only sha256 implemented"
raise NotImplementedError(
msg,
)

fakeprefix = pathlib.Path(kwargs["fakeroot"] + prefix)
dest_path = fakeprefix / kwargs["destination"]
fakeprefix = pathlib.Path(fakeroot + prefix)
dest_path = fakeprefix / destination

session = requests.Session()
session.mount("https://", requests.adapters.HTTPAdapter(max_retries=20))
Expand Down Expand Up @@ -190,28 +204,28 @@ def download(pkg, ver, pkgpath, data, prefix, *args, **kwargs):
)


def pip_install(pkg, ver, pkgpath, data, prefix, dlprefix, *args, pip="pip", **kwargs):
def pip_install(pkg, ver, prefix, dlprefix, fakeroot, makeopts="", pip="pip"):
ver = strip_version(ver)
if ver == LATEST_PACKAGE_ALIAS:
ver = latest_pypi_version(pkg)
cmd = [
pip,
f"install {pkg}=={strip_version(ver)}",
f"--root {kwargs['fakeroot']}",
f"--root {fakeroot}",
f"--prefix {prefix}",
"--no-index",
"--no-deps",
"--ignore-installed",
f"--cache-dir {dlprefix}",
f"--find-links {dlprefix}",
kwargs.get("makeopts", ""),
makeopts,
]

print(f"Installing {pkg} ({ver}) from pip")
shell(cmd)


def noop(pkg, ver, *args, **kwargs):
def noop(pkg, ver):
print(f"Doing nothing for noop package {pkg} ({ver})")


Expand Down Expand Up @@ -281,19 +295,9 @@ def make(
def resolve(x):
return x.replace("$(prefix)", prefix)

build = {
"rpm": rpm,
"cmake": cmake,
"sh": sh,
"pip": pip_install,
"rsync": rsync,
"noop": noop,
"download": download,
}

for pkg, path in zip(pkgorder, pkgpaths):
ver = pkgs[pkg]
current = repo[pkg][ver]
current: Dict[str, Union[str, dict]] = repo[pkg][ver]
make = current["make"]
pkgpath = os.path.abspath(path)

Expand All @@ -313,30 +317,76 @@ def resolve(x):

package_name = current.get("pypi_package_name", pkg)

makeopts = None
if extra_makeopts:
oldopts = current.get("makeopts", "")
current["makeopts"] = f"{oldopts} {extra_makeopts}"

current["makeopts"] = resolve(current.get("makeopts", ""))
build[make](
package_name,
ver,
pkgpath,
data,
prefix=prefix,
builddir=builddir,
makeopts=current.get("makeopts"),
makefile=current.get("makefile"),
dlprefix=dlprefix,
jobs=jobs,
cmake=cmk,
pip=pip,
virtualenv=virtualenv,
fakeroot=fakeroot,
pythonpath=build_pythonpath,
binpath=build_path,
ld_lib_path=build_ld_lib_path,
url=current.get("url"),
destination=current.get("destination"),
hash=current.get("hash"),
)
makeopts = f"{oldopts} {extra_makeopts}"

makeopts = resolve(makeopts or "")
if make == "rpm":
rpm(package_name, ver, pkgpath, prefix)
elif make == "cmake":
cmake(
pkg=package_name,
ver=ver,
path=pkgpath,
prefix=prefix,
builddir=builddir,
makeopts=makeopts,
jobs=jobs,
cmake=cmk,
fakeroot=fakeroot,
ld_lib_path=build_ld_lib_path,
binpath=build_path,
)
elif make == "sh":
sh(
pkg=package_name,
ver=ver,
pkgpath=pkgpath,
data=data,
prefix=prefix,
makefile=current.get("makefile"),
fakeroot=fakeroot,
pythonpath=build_pythonpath,
binpath=build_path,
pip=pip,
virtualenv=virtualenv,
ld_lib_path=build_ld_lib_path,
makeopts=makeopts,
jobs=jobs,
cmake=cmk,
)
elif make == "pip":
pip_install(
package_name,
ver,
prefix,
dlprefix,
fakeroot=fakeroot,
makeopts=makeopts,
pip=pip,
)
elif make == "rsync":
rsync(
pkg=pkg,
ver=ver,
pkgpath=pkgpath,
prefix=prefix,
fakeroot=fakeroot,
makeopts=makeopts,
)
elif make == "noop":
noop(pkg=pkg, ver=ver)
elif make == "download":
download(
pkg=package_name,
ver=ver,
prefix=prefix,
url=current.get("url"),
input_hash=current.get("hash"),
fakeroot=fakeroot,
destination=current.get("destination"),
)
else:
raise ValueError(f"Make not handled: {make}")
4 changes: 2 additions & 2 deletions komodo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def eprint(*args, **kwargs):
return print(*args, file=sys.stderr, **kwargs)


def grab(path, filename=None, version=None, protocol=None, pip="pip"):
def grab(path, filename=None, version=None, protocol=None):
# guess protocol if it's obvious from the url (usually is)
if protocol is None:
protocol = path.split(":")[0]
Expand Down Expand Up @@ -143,7 +143,7 @@ def fetch(pkgs, repo, outdir, pip="pip") -> dict:
continue

print(f"Downloading {name}")
grab(url, filename=dst, version=ver, protocol=protocol, pip=pip)
grab(url, filename=dst, version=ver, protocol=protocol)

if protocol == "git":
git_hashes[pkg] = get_git_revision_hash(path=dst)
Expand Down
9 changes: 0 additions & 9 deletions komodo/yaml_file_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ def _komodo_error(package=None, version=None, maintainer=None, depends=None, err
)


def __reg_version_err(errs, package, version, maintainer, err=MALFORMED_VERSION):
return _komodo_error(
package=package,
version=version,
maintainer=maintainer,
err=err,
)


def load_yaml_from_string(value: str) -> dict:
try:
return YAML().load(value)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ disable = [
"too-many-statements",
"unnecessary-lambda",
"unspecified-encoding",
"unused-argument",
"use-a-generator",
"use-implicit-booleaness-not-comparison",
"use-symbolic-message-instead",
Expand Down
3 changes: 3 additions & 0 deletions tests/data/test_releases/test_release_matrix-py38-rhel7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib1: 1.2.4+builtin
lib2: 2.3.4
lib3: 3.4.6
3 changes: 2 additions & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def test_make_pip_package_from_latest(captured_shell_commands, tmpdir):
assert "pip install PyYaml==1.0.0" in " ".join(captured_shell_commands[1])


def test_make_sh_does_not_accept_pypi_package_name(captured_shell_commands, tmpdir):
@pytest.mark.usefixtures("captured_shell_commands")
def test_make_sh_does_not_accept_pypi_package_name(tmpdir):
packages = {"ert": "2.16.0"}
repositories = {
"ert": {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_minimal_main(args, tmpdir):
assert not os.path.exists(os.path.join(release_path, "local.csh"))


def test_pyver_is_deprecated(capsys):
def test_pyver_is_deprecated():
"""Pyver is not being used anywhere in the code and has been deprecated.
This test ensures that its use prints a message in stderr.
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def test_fetch_with_empty_pypi_package_name(captured_shell_commands, tmpdir):
assert "PyYaml" in command


def test_fetch_git_does_not_accept_pypi_package_name(captured_shell_commands, tmpdir):
@pytest.mark.usefixtures("captured_shell_commands")
def test_fetch_git_does_not_accept_pypi_package_name(tmpdir):
packages = {"ert": "2.16.0"}
repositories = {
"ert": {
Expand Down
Loading

0 comments on commit ff8e04e

Please sign in to comment.