enforce E501 partially in pmb/aportgen (MR 2058)

This commit is contained in:
Caio Fontes 2021-05-19 16:08:17 -03:00 committed by Oliver Smith
parent cfa5bc2cf7
commit fb98ad5329
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
5 changed files with 26 additions and 19 deletions

View File

@ -37,14 +37,16 @@ def properties(pkgname):
def generate(args, pkgname): def generate(args, pkgname):
if args.fork_alpine: if args.fork_alpine:
prefix, folder, options = (pkgname, "temp", {"confirm_overwrite": True}) prefix, folder, options = (pkgname, "temp",
{"confirm_overwrite": True})
else: else:
prefix, folder, options = properties(pkgname) prefix, folder, options = properties(pkgname)
path_target = args.aports + "/" + folder + "/" + pkgname path_target = args.aports + "/" + folder + "/" + pkgname
# Confirm overwrite # Confirm overwrite
if options["confirm_overwrite"] and os.path.exists(path_target): if options["confirm_overwrite"] and os.path.exists(path_target):
logging.warning("WARNING: Target folder already exists: " + path_target) logging.warning("WARNING: Target folder already exists: "
f"{path_target}")
if not pmb.helpers.cli.confirm(args, "Continue and overwrite?"): if not pmb.helpers.cli.confirm(args, "Continue and overwrite?"):
raise RuntimeError("Aborted.") raise RuntimeError("Aborted.")
@ -52,8 +54,10 @@ def generate(args, pkgname):
pmb.helpers.run.user(args, ["rm", "-r", args.work + "/aportgen"]) pmb.helpers.run.user(args, ["rm", "-r", args.work + "/aportgen"])
if args.fork_alpine: if args.fork_alpine:
upstream = pmb.aportgen.core.get_upstream_aport(args, pkgname) upstream = pmb.aportgen.core.get_upstream_aport(args, pkgname)
pmb.helpers.run.user(args, ["cp", "-r", upstream, args.work + "/aportgen"]) pmb.helpers.run.user(args, ["cp", "-r", upstream,
pmb.aportgen.core.rewrite(args, pkgname, replace_simple={"# Contributor:*": None, "# Maintainer:*": None}) f"{args.work}/aportgen"])
pmb.aportgen.core.rewrite(args, pkgname, replace_simple={
"# Contributor:*": None, "# Maintainer:*": None})
else: else:
# Run pmb.aportgen.PREFIX.generate() # Run pmb.aportgen.PREFIX.generate()
getattr(pmb.aportgen, prefix.replace("-", "_")).generate(args, pkgname) getattr(pmb.aportgen, prefix.replace("-", "_")).generate(args, pkgname)

View File

@ -14,7 +14,7 @@ def generate(args, pkgname):
# Rewrite APKBUILD # Rewrite APKBUILD
fields = { fields = {
"pkgname": pkgname, "pkgname": pkgname,
"pkgdesc": "Tools necessary to build programs for " + arch + " targets", "pkgdesc": f"Tools necessary to build programs for {arch} targets",
"arch": args.arch_native, "arch": args.arch_native,
"makedepends_build": "", "makedepends_build": "",
"makedepends_host": "", "makedepends_host": "",

View File

@ -54,19 +54,20 @@ def rewrite(args, pkgname, path_original="", fields={}, replace_pkgname=None,
lines (so they won't be bugged with issues regarding our generated aports), lines (so they won't be bugged with issues regarding our generated aports),
and add reference to the original aport. and add reference to the original aport.
:param path_original: The original path of the automatically generated aport :param path_original: The original path of the automatically generated
aport.
:param fields: key-value pairs of fields, that shall be changed in the :param fields: key-value pairs of fields, that shall be changed in the
APKBUILD. For example: {"pkgdesc": "my new package", "subpkgs": ""} APKBUILD. For example: {"pkgdesc": "my new package", "subpkgs": ""}
:param replace_pkgname: When set, $pkgname gets replaced with that string in :param replace_pkgname: When set, $pkgname gets replaced with that string
every line. in every line.
:param replace_functions: Function names and new bodies, for example: :param replace_functions: Function names and new bodies, for example:
{"build": "return 0"} {"build": "return 0"}
The body can also be None (deletes the function) The body can also be None (deletes the function)
:param replace_simple: Lines, that fnmatch the pattern, get :param replace_simple: Lines, that fnmatch the pattern, get
replaced/deleted. Example: {"*test*": "# test", "*mv test.bin*": None} replaced/deleted. Example: {"*test*": "# test", "*mv test.bin*": None}
:param below_header: String, that gets directly placed below the header. :param below_header: String, that gets directly placed below the header.
:param remove_indent: Number of spaces to remove from function body provided :param remove_indent: Number of spaces to remove from function body
to replace_functions. provided to replace_functions.
""" """
# Header # Header
@ -109,8 +110,8 @@ def rewrite(args, pkgname, path_original="", fields={}, replace_pkgname=None,
if line.startswith(func + "() {"): if line.startswith(func + "() {"):
skip_in_func = True skip_in_func = True
if body: if body:
lines_new += format_function(func, body, lines_new += format_function(
remove_indent=remove_indent) func, body, remove_indent=remove_indent)
break break
if skip_in_func: if skip_in_func:
continue continue

View File

@ -19,7 +19,7 @@ def generate(args, pkgname):
upstream = args.aports + "/main/gcc6" upstream = args.aports + "/main/gcc6"
based_on = "main/gcc6 (from postmarketOS)" based_on = "main/gcc6 (from postmarketOS)"
else: else:
raise ValueError("Invalid prefix '" + prefix + "', expected gcc, gcc4 or" raise ValueError(f"Invalid prefix '{prefix}', expected gcc, gcc4 or"
" gcc6.") " gcc6.")
pmb.helpers.run.user(args, ["cp", "-r", upstream, args.work + "/aportgen"]) pmb.helpers.run.user(args, ["cp", "-r", upstream, args.work + "/aportgen"])
@ -30,8 +30,10 @@ def generate(args, pkgname):
"pkgdesc": "Stage2 cross-compiler for " + arch, "pkgdesc": "Stage2 cross-compiler for " + arch,
"arch": args.arch_native, "arch": args.arch_native,
"depends": "isl binutils-" + arch + " mpc1", "depends": "isl binutils-" + arch + " mpc1",
"makedepends_build": "gcc g++ paxmark bison flex texinfo gawk zip gmp-dev mpfr-dev mpc1-dev zlib-dev", "makedepends_build": "gcc g++ paxmark bison flex texinfo gawk zip"
"makedepends_host": "linux-headers gmp-dev mpfr-dev mpc1-dev isl-dev zlib-dev musl-dev-" + arch + " binutils-" + arch, " gmp-dev mpfr-dev mpc1-dev zlib-dev",
"makedepends_host": "linux-headers gmp-dev mpfr-dev mpc1-dev isl-dev"
f" zlib-dev musl-dev-{arch} binutils-{arch}",
"subpackages": "g++-" + arch + ":gpp" if prefix == "gcc" else "", "subpackages": "g++-" + arch + ":gpp" if prefix == "gcc" else "",
# gcc6: options is already there, so we need to replace it and not only # gcc6: options is already there, so we need to replace it and not only

View File

@ -10,8 +10,8 @@ def generate_apkbuild(args, pkgname, deviceinfo, patches):
device = "-".join(pkgname.split("-")[1:]) device = "-".join(pkgname.split("-")[1:])
carch = pmb.parse.arch.alpine_to_kernel(deviceinfo["arch"]) carch = pmb.parse.arch.alpine_to_kernel(deviceinfo["arch"])
makedepends = ["bash", "bc", "bison", "devicepkg-dev", "flex", "openssl-dev", makedepends = ["bash", "bc", "bison", "devicepkg-dev", "flex",
"perl"] "openssl-dev", "perl"]
build = """ build = """
unset LDFLAGS unset LDFLAGS
@ -96,9 +96,9 @@ def generate_apkbuild(args, pkgname, deviceinfo, patches):
""" """
# Write the file # Write the file
with open(args.work + "/aportgen/APKBUILD", "w", encoding="utf-8") as handle: with open(f"{args.work}/aportgen/APKBUILD", "w", encoding="utf-8") as hndl:
for line in content.rstrip().split("\n"): for line in content.rstrip().split("\n"):
handle.write(line[8:].replace(" " * 4, "\t") + "\n") hndl.write(line[8:].replace(" " * 4, "\t") + "\n")
def generate(args, pkgname): def generate(args, pkgname):