Enforce E501: Limit the line length to 79 for files in pmb/parse - part 1 (MR 2019)
Made changes to limit the line length in following files, - pmb/parse/_apkbuild.py - pmb/parse/apkindex.py - pmb/parse/binfmt_info.py - pmb/parse/deviceinfo.py - test/test_parse_apkbuild.py Added the above files in E501 flake8 command list. Substitute f-string for string concatenation.
This commit is contained in:
parent
4474927141
commit
d1fadba5b4
|
@ -25,6 +25,10 @@ revar4 = re.compile(r"\${([a-zA-Z_]+[a-zA-Z0-9_]*)#(.*)}")
|
||||||
|
|
||||||
|
|
||||||
def replace_variable(apkbuild, value: str) -> str:
|
def replace_variable(apkbuild, value: str) -> str:
|
||||||
|
def log_key_not_found(match):
|
||||||
|
logging.verbose(f"{apkbuild['pkgname']}: key '{match.group(1)}' for"
|
||||||
|
f" replacing '{match.group(0)}' not found, ignoring")
|
||||||
|
|
||||||
# ${foo}
|
# ${foo}
|
||||||
for match in revar.finditer(value):
|
for match in revar.finditer(value):
|
||||||
try:
|
try:
|
||||||
|
@ -33,9 +37,7 @@ def replace_variable(apkbuild, value: str) -> str:
|
||||||
apkbuild[match.group(1)]))
|
apkbuild[match.group(1)]))
|
||||||
value = value.replace(match.group(0), apkbuild[match.group(1)], 1)
|
value = value.replace(match.group(0), apkbuild[match.group(1)], 1)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.verbose("{}: key '{}' for replacing '{}' not found, ignoring"
|
log_key_not_found(match)
|
||||||
"".format(apkbuild["pkgname"], match.group(1),
|
|
||||||
match.group(0)))
|
|
||||||
|
|
||||||
# $foo
|
# $foo
|
||||||
for match in revar2.finditer(value):
|
for match in revar2.finditer(value):
|
||||||
|
@ -46,9 +48,7 @@ def replace_variable(apkbuild, value: str) -> str:
|
||||||
newvalue))
|
newvalue))
|
||||||
value = value.replace(match.group(0), newvalue, 1)
|
value = value.replace(match.group(0), newvalue, 1)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.verbose("{}: key '{}' for replacing '{}' not found, ignoring"
|
log_key_not_found(match)
|
||||||
"".format(apkbuild["pkgname"], match.group(1),
|
|
||||||
match.group(0)))
|
|
||||||
|
|
||||||
# ${var/foo/bar}, ${var/foo/}, ${var/foo}
|
# ${var/foo/bar}, ${var/foo/}, ${var/foo}
|
||||||
for match in revar3.finditer(value):
|
for match in revar3.finditer(value):
|
||||||
|
@ -63,9 +63,7 @@ def replace_variable(apkbuild, value: str) -> str:
|
||||||
apkbuild["pkgname"], match.group(0), newvalue))
|
apkbuild["pkgname"], match.group(0), newvalue))
|
||||||
value = value.replace(match.group(0), newvalue, 1)
|
value = value.replace(match.group(0), newvalue, 1)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.verbose("{}: key '{}' for replacing '{}' not found, ignoring"
|
log_key_not_found(match)
|
||||||
"".format(apkbuild["pkgname"], match.group(1),
|
|
||||||
match.group(0)))
|
|
||||||
|
|
||||||
# ${foo#bar}
|
# ${foo#bar}
|
||||||
rematch4 = revar4.finditer(value)
|
rematch4 = revar4.finditer(value)
|
||||||
|
@ -79,9 +77,7 @@ def replace_variable(apkbuild, value: str) -> str:
|
||||||
apkbuild["pkgname"], match.group(0), newvalue))
|
apkbuild["pkgname"], match.group(0), newvalue))
|
||||||
value = value.replace(match.group(0), newvalue, 1)
|
value = value.replace(match.group(0), newvalue, 1)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.verbose("{}: key '{}' for replacing '{}' not found, ignoring"
|
log_key_not_found(match)
|
||||||
"".format(apkbuild["pkgname"], match.group(1),
|
|
||||||
match.group(0)))
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -121,7 +117,7 @@ def read_file(path):
|
||||||
with open(path, encoding="utf-8") as handle:
|
with open(path, encoding="utf-8") as handle:
|
||||||
lines = handle.readlines()
|
lines = handle.readlines()
|
||||||
if handle.newlines != '\n':
|
if handle.newlines != '\n':
|
||||||
raise RuntimeError("Wrong line endings in APKBUILD: " + path)
|
raise RuntimeError(f"Wrong line endings in APKBUILD: {path}")
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,14 +175,15 @@ def parse_attribute(attribute, lines, i, path):
|
||||||
value += line.strip()
|
value += line.strip()
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
raise RuntimeError("Can't find closing quote sign (" + end_char + ") for"
|
raise RuntimeError(f"Can't find closing quote sign ({end_char}) for"
|
||||||
" attribute '" + attribute + "' in: " + path)
|
f" attribute '{attribute}' in: {path}")
|
||||||
|
|
||||||
|
|
||||||
def _parse_attributes(path, lines, apkbuild_attributes, ret):
|
def _parse_attributes(path, lines, apkbuild_attributes, ret):
|
||||||
"""
|
"""
|
||||||
Parse attributes from a list of lines. Variables are replaced with values
|
Parse attributes from a list of lines. Variables are replaced with values
|
||||||
from ret (if found) and split into the format configured in apkbuild_attributes.
|
from ret (if found) and split into the format configured in
|
||||||
|
apkbuild_attributes.
|
||||||
|
|
||||||
:param lines: the lines to parse
|
:param lines: the lines to parse
|
||||||
:param apkbuild_attributes: the attributes to parse
|
:param apkbuild_attributes: the attributes to parse
|
||||||
|
@ -245,19 +242,21 @@ def _parse_subpackage(path, lines, apkbuild, subpackages, subpkg):
|
||||||
|
|
||||||
if not start:
|
if not start:
|
||||||
# Unable to find subpackage function in the APKBUILD.
|
# Unable to find subpackage function in the APKBUILD.
|
||||||
# The subpackage function could be actually missing, or this is a problem
|
# The subpackage function could be actually missing, or this is a
|
||||||
# in the parser. For now we also don't handle subpackages with default
|
# problem in the parser. For now we also don't handle subpackages with
|
||||||
# functions (e.g. -dev or -doc).
|
# default functions (e.g. -dev or -doc).
|
||||||
# In the future we may want to specifically handle these, and throw
|
# In the future we may want to specifically handle these, and throw
|
||||||
# an exception here for all other missing subpackage functions.
|
# an exception here for all other missing subpackage functions.
|
||||||
subpackages[subpkgname] = None
|
subpackages[subpkgname] = None
|
||||||
logging.verbose("{}: subpackage function '{}' for subpackage '{}' not found, ignoring"
|
logging.verbose(
|
||||||
"".format(apkbuild["pkgname"], subpkgsplit, subpkgname))
|
f"{apkbuild['pkgname']}: subpackage function '{subpkgsplit}' for "
|
||||||
|
f"subpackage '{subpkgname}' not found, ignoring")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not end:
|
if not end:
|
||||||
raise RuntimeError("Could not find end of subpackage function, no line starts"
|
raise RuntimeError(
|
||||||
" with '}' after '" + prefix + "' in " + path)
|
f"Could not find end of subpackage function, no line starts with "
|
||||||
|
f"'}}' after '{prefix}' in {path}")
|
||||||
|
|
||||||
lines = lines[start:end]
|
lines = lines[start:end]
|
||||||
# Strip tabs before lines in function
|
# Strip tabs before lines in function
|
||||||
|
@ -268,7 +267,8 @@ def _parse_subpackage(path, lines, apkbuild, subpackages, subpkg):
|
||||||
apkbuild["subpkgname"] = subpkgname
|
apkbuild["subpkgname"] = subpkgname
|
||||||
|
|
||||||
# Parse relevant attributes for the subpackage
|
# Parse relevant attributes for the subpackage
|
||||||
_parse_attributes(path, lines, pmb.config.apkbuild_package_attributes, apkbuild)
|
_parse_attributes(
|
||||||
|
path, lines, pmb.config.apkbuild_package_attributes, apkbuild)
|
||||||
|
|
||||||
# Return only properties interesting for subpackages
|
# Return only properties interesting for subpackages
|
||||||
ret = {}
|
ret = {}
|
||||||
|
@ -304,21 +304,23 @@ def apkbuild(args, path, check_pkgver=True, check_pkgname=True):
|
||||||
_parse_attributes(path, lines, pmb.config.apkbuild_attributes, ret)
|
_parse_attributes(path, lines, pmb.config.apkbuild_attributes, ret)
|
||||||
|
|
||||||
# Sanity check: pkgname
|
# Sanity check: pkgname
|
||||||
suffix = "/" + ret["pkgname"] + "/APKBUILD"
|
suffix = f"/{ret['pkgname']}/APKBUILD"
|
||||||
if check_pkgname:
|
if check_pkgname:
|
||||||
if not os.path.realpath(path).endswith(suffix):
|
if not os.path.realpath(path).endswith(suffix):
|
||||||
logging.info("Folder: '" + os.path.dirname(path) + "'")
|
logging.info(f"Folder: '{os.path.dirname(path)}'")
|
||||||
logging.info("Pkgname: '" + ret["pkgname"] + "'")
|
logging.info(f"Pkgname: '{ret['pkgname']}'")
|
||||||
raise RuntimeError("The pkgname must be equal to the name of"
|
raise RuntimeError("The pkgname must be equal to the name of"
|
||||||
" the folder, that contains the APKBUILD!")
|
" the folder, that contains the APKBUILD!")
|
||||||
|
|
||||||
# Sanity check: pkgver
|
# Sanity check: pkgver
|
||||||
if check_pkgver:
|
if check_pkgver:
|
||||||
if "-r" in ret["pkgver"] or not pmb.parse.version.validate(ret["pkgver"]):
|
if ("-r" in ret["pkgver"] or not
|
||||||
logging.info("NOTE: Valid pkgvers are described here:")
|
pmb.parse.version.validate(ret["pkgver"])):
|
||||||
logging.info("<https://wiki.alpinelinux.org/wiki/APKBUILD_Reference#pkgver>")
|
logging.info(
|
||||||
raise RuntimeError("Invalid pkgver '" + ret["pkgver"] +
|
"NOTE: Valid pkgvers are described here: "
|
||||||
"' in APKBUILD: " + path)
|
"https://wiki.alpinelinux.org/wiki/APKBUILD_Reference#pkgver")
|
||||||
|
raise RuntimeError(f"Invalid pkgver '{ret['pkgver']}' in"
|
||||||
|
f" APKBUILD: {path}")
|
||||||
|
|
||||||
# Fill cache
|
# Fill cache
|
||||||
args.cache["apkbuild"][path] = ret
|
args.cache["apkbuild"][path] = ret
|
||||||
|
@ -344,12 +346,13 @@ def kernels(args, device):
|
||||||
|
|
||||||
# Read kernels from subpackages
|
# Read kernels from subpackages
|
||||||
ret = {}
|
ret = {}
|
||||||
subpackage_prefix = "device-" + device + "-kernel-"
|
subpackage_prefix = f"device-{device}-kernel-"
|
||||||
for subpkgname, subpkg in subpackages.items():
|
for subpkgname, subpkg in subpackages.items():
|
||||||
if not subpkgname.startswith(subpackage_prefix):
|
if not subpkgname.startswith(subpackage_prefix):
|
||||||
continue
|
continue
|
||||||
if subpkg is None:
|
if subpkg is None:
|
||||||
raise RuntimeError("Cannot find subpackage function for: " + subpkgname)
|
raise RuntimeError(
|
||||||
|
f"Cannot find subpackage function for: {subpkgname}")
|
||||||
name = subpkgname[len(subpackage_prefix):]
|
name = subpkgname[len(subpackage_prefix):]
|
||||||
ret[name] = subpkg["pkgdesc"]
|
ret[name] = subpkg["pkgdesc"]
|
||||||
|
|
||||||
|
|
|
@ -71,8 +71,8 @@ def parse_next_block(args, path, lines, start):
|
||||||
# Check for required keys
|
# Check for required keys
|
||||||
for key in ["arch", "pkgname", "version"]:
|
for key in ["arch", "pkgname", "version"]:
|
||||||
if key not in ret:
|
if key not in ret:
|
||||||
raise RuntimeError("Missing required key '" + key +
|
raise RuntimeError(f"Missing required key '{key}' in block "
|
||||||
"' in block " + str(ret) + ", file: " + path)
|
f"{ret}, file: {path}")
|
||||||
|
|
||||||
# Format optional lists
|
# Format optional lists
|
||||||
for key in ["provides", "depends"]:
|
for key in ["provides", "depends"]:
|
||||||
|
@ -340,8 +340,9 @@ def provider_highest_priority(providers, pkgname):
|
||||||
priority_providers[provider_name] = provider
|
priority_providers[provider_name] = provider
|
||||||
|
|
||||||
if priority_providers:
|
if priority_providers:
|
||||||
logging.debug(f"{pkgname}: picked provider(s) with higest priority {max_priority}: " +
|
logging.debug(
|
||||||
", ".join(priority_providers.keys()))
|
f"{pkgname}: picked provider(s) with higest priority "
|
||||||
|
f"{max_priority}: {', '.join(priority_providers.keys())}")
|
||||||
return priority_providers
|
return priority_providers
|
||||||
|
|
||||||
# None of the providers seems to have a provider_priority defined
|
# None of the providers seems to have a provider_priority defined
|
||||||
|
@ -359,8 +360,9 @@ def provider_shortest(providers, pkgname):
|
||||||
"""
|
"""
|
||||||
ret = min(list(providers.keys()), key=len)
|
ret = min(list(providers.keys()), key=len)
|
||||||
if len(providers) != 1:
|
if len(providers) != 1:
|
||||||
logging.debug(pkgname + ": has multiple providers (" +
|
logging.debug(
|
||||||
", ".join(providers.keys()) + "), picked shortest: " + ret)
|
f"{pkgname}: has multiple providers ("
|
||||||
|
f"{', '.join(providers.keys())}), picked shortest: {ret}")
|
||||||
return providers[ret]
|
return providers[ret]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ def binfmt_info(args, arch_qemu):
|
||||||
for type in ["mask", "magic"]:
|
for type in ["mask", "magic"]:
|
||||||
key = arch_qemu + "_" + type
|
key = arch_qemu + "_" + type
|
||||||
if key not in full:
|
if key not in full:
|
||||||
raise RuntimeError("Could not find key " + key + " in binfmt info file: " +
|
raise RuntimeError(
|
||||||
info)
|
f"Could not find key {key} in binfmt info file: {info}")
|
||||||
ret[type] = full[key]
|
ret[type] = full[key]
|
||||||
logging.verbose("=> " + str(ret))
|
logging.verbose("=> " + str(ret))
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -48,8 +48,8 @@ def sanity_check(info, path):
|
||||||
if codename.startswith("device-"):
|
if codename.startswith("device-"):
|
||||||
codename = codename[7:]
|
codename = codename[7:]
|
||||||
if "codename" not in info or info["codename"] != codename:
|
if "codename" not in info or info["codename"] != codename:
|
||||||
raise RuntimeError("Please add 'deviceinfo_codename=\"" + codename +
|
raise RuntimeError(f"Please add 'deviceinfo_codename=\"{codename}\"' "
|
||||||
"\"' to: " + path)
|
f"to: {path}")
|
||||||
|
|
||||||
# "chassis" is required
|
# "chassis" is required
|
||||||
chassis_types = pmb.config.deviceinfo_chassis_types
|
chassis_types = pmb.config.deviceinfo_chassis_types
|
||||||
|
@ -118,8 +118,9 @@ def deviceinfo(args, device=None, kernel=None):
|
||||||
kernel = args.kernel
|
kernel = args.kernel
|
||||||
|
|
||||||
if not os.path.exists(args.aports):
|
if not os.path.exists(args.aports):
|
||||||
logging.fatal("Aports directory is missing, expected: " + args.aports)
|
logging.fatal(f"Aports directory is missing, expected: {args.aports}")
|
||||||
logging.fatal("Please provide a path to the aports directory using the -p flag")
|
logging.fatal("Please provide a path to the aports directory using the"
|
||||||
|
" -p flag")
|
||||||
raise RuntimeError("Aports directory missing")
|
raise RuntimeError("Aports directory missing")
|
||||||
|
|
||||||
path = pmb.helpers.devices.find_path(args, device, 'deviceinfo')
|
path = pmb.helpers.devices.find_path(args, device, 'deviceinfo')
|
||||||
|
@ -135,7 +136,7 @@ def deviceinfo(args, device=None, kernel=None):
|
||||||
if not line.startswith("deviceinfo_"):
|
if not line.startswith("deviceinfo_"):
|
||||||
continue
|
continue
|
||||||
if "=" not in line:
|
if "=" not in line:
|
||||||
raise SyntaxError(path + ": No '=' found:\n\t" + line)
|
raise SyntaxError(f"{path}: No '=' found:\n\t{line}")
|
||||||
split = line.split("=", 1)
|
split = line.split("=", 1)
|
||||||
key = split[0][len("deviceinfo_"):]
|
key = split[0][len("deviceinfo_"):]
|
||||||
value = split[1].replace("\"", "").replace("\n", "")
|
value = split[1].replace("\"", "").replace("\n", "")
|
||||||
|
|
|
@ -92,9 +92,13 @@ py_files="
|
||||||
pmb/install/recovery.py
|
pmb/install/recovery.py
|
||||||
pmb/install/ui.py
|
pmb/install/ui.py
|
||||||
pmb/parse/__init__.py
|
pmb/parse/__init__.py
|
||||||
|
pmb/parse/_apkbuild.py
|
||||||
|
pmb/parse/apkindex.py
|
||||||
pmb/parse/arch.py
|
pmb/parse/arch.py
|
||||||
pmb/parse/arguments.py
|
pmb/parse/arguments.py
|
||||||
|
pmb/parse/binfmt_info.py
|
||||||
pmb/parse/cpuinfo.py
|
pmb/parse/cpuinfo.py
|
||||||
|
pmb/parse/deviceinfo.py
|
||||||
pmb/parse/version.py
|
pmb/parse/version.py
|
||||||
pmb/qemu/__init__.py
|
pmb/qemu/__init__.py
|
||||||
pmb/sideload/__init__.py
|
pmb/sideload/__init__.py
|
||||||
|
@ -126,6 +130,7 @@ py_files="
|
||||||
test/test_keys.py
|
test/test_keys.py
|
||||||
test/test_mount.py
|
test/test_mount.py
|
||||||
test/test_newapkbuild.py
|
test/test_newapkbuild.py
|
||||||
|
test/test_parse_apkbuild.py
|
||||||
test/test_parse_apkindex.py
|
test/test_parse_apkindex.py
|
||||||
test/test_parse_deviceinfo.py
|
test/test_parse_deviceinfo.py
|
||||||
test/test_questions.py
|
test/test_questions.py
|
||||||
|
|
|
@ -37,13 +37,15 @@ def test_subpackages(args):
|
||||||
path = (testdata + "/init_questions_device/aports/device/testing/"
|
path = (testdata + "/init_questions_device/aports/device/testing/"
|
||||||
"device-nonfree-firmware/APKBUILD")
|
"device-nonfree-firmware/APKBUILD")
|
||||||
apkbuild = pmb.parse.apkbuild(args, path)
|
apkbuild = pmb.parse.apkbuild(args, path)
|
||||||
subpkg = apkbuild["subpackages"]["device-nonfree-firmware-nonfree-firmware"]
|
subpkg = (apkbuild["subpackages"]
|
||||||
|
["device-nonfree-firmware-nonfree-firmware"])
|
||||||
assert subpkg["pkgdesc"] == "firmware description"
|
assert subpkg["pkgdesc"] == "firmware description"
|
||||||
|
|
||||||
# Can't find the pkgdesc in the function
|
# Can't find the pkgdesc in the function
|
||||||
path = testdata + "/apkbuild/APKBUILD.missing-pkgdesc-in-subpackage"
|
path = testdata + "/apkbuild/APKBUILD.missing-pkgdesc-in-subpackage"
|
||||||
apkbuild = pmb.parse.apkbuild(args, path, check_pkgname=False)
|
apkbuild = pmb.parse.apkbuild(args, path, check_pkgname=False)
|
||||||
subpkg = apkbuild["subpackages"]["missing-pkgdesc-in-subpackage-subpackage"]
|
subpkg = (apkbuild["subpackages"]
|
||||||
|
["missing-pkgdesc-in-subpackage-subpackage"])
|
||||||
assert subpkg["pkgdesc"] == ""
|
assert subpkg["pkgdesc"] == ""
|
||||||
|
|
||||||
# Can't find the function
|
# Can't find the function
|
||||||
|
@ -131,4 +133,5 @@ def test_variable_replacements(args):
|
||||||
|
|
||||||
assert apkbuild["subpackages"]["replacements"] is None
|
assert apkbuild["subpackages"]["replacements"] is None
|
||||||
test_subpkg = apkbuild["subpackages"]["test"]
|
test_subpkg = apkbuild["subpackages"]["test"]
|
||||||
assert test_subpkg["pkgdesc"] == "this should not affect variable replacement"
|
assert test_subpkg["pkgdesc"] == ("this should not affect variable "
|
||||||
|
"replacement")
|
||||||
|
|
Loading…
Reference in New Issue