From 039552f5b7b9ede491ee56ea443dc634a2813516 Mon Sep 17 00:00:00 2001 From: Caio Fontes Date: Wed, 19 May 2021 15:36:24 -0300 Subject: [PATCH] enforce E501 in pmb/helpers (MR 2058) --- pmb/helpers/cli.py | 12 ++++++++---- pmb/helpers/devices.py | 2 +- pmb/helpers/frontend.py | 22 ++++++++++++++-------- pmb/helpers/http.py | 7 ++++--- pmb/helpers/logging.py | 5 +++-- pmb/helpers/other.py | 6 ++++-- pmb/helpers/pkgrel_bump.py | 4 ++-- pmb/helpers/pmaports.py | 11 +++++++---- pmb/helpers/run_core.py | 3 ++- 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/pmb/helpers/cli.py b/pmb/helpers/cli.py index 5ec52d97..2917fbfb 100644 --- a/pmb/helpers/cli.py +++ b/pmb/helpers/cli.py @@ -27,7 +27,8 @@ class ReadlineTabCompleter: # First time: build match list if iteration == 0: if input_text: - self.matches = [s for s in self.options if s and s.startswith(input_text)] + self.matches = [s for s in self.options + if s and s.startswith(input_text)] else: self.matches = self.options[:] @@ -42,7 +43,8 @@ def ask(args, question="Continue?", choices=["y", "n"], default="n", """ Ask a question on the terminal. :param question: display prompt - :param choices: short list of possible answers, displayed after prompt if set + :param choices: short list of possible answers, + displayed after prompt if set :param default: default value to return if user doesn't input anything :param lowercase_answer: if True, convert return value to lower case :param validation_regex: if set, keep asking until regex matches @@ -62,7 +64,8 @@ def ask(args, question="Continue?", choices=["y", "n"], default="n", if '-' in delims: delims = delims.replace('-', '') readline.set_completer_delims(delims) - readline.set_completer(ReadlineTabCompleter(complete).completer_func) + readline.set_completer( + ReadlineTabCompleter(complete).completer_func) ret = input(question_full + ": ") @@ -95,7 +98,8 @@ def confirm(args, question="Continue?", default=False, no_assumptions=False): """ Convenience wrapper around ask for simple yes-no questions with validation. - :param no_assumptions: ask for confirmation, even if "pmbootstrap -y' is set + :param no_assumptions: ask for confirmation, even if "pmbootstrap -y' + is set :returns: True for "y", False for "n" """ default_str = "y" if default else "n" diff --git a/pmb/helpers/devices.py b/pmb/helpers/devices.py index d8c37c35..4d1c6dfa 100644 --- a/pmb/helpers/devices.py +++ b/pmb/helpers/devices.py @@ -58,7 +58,7 @@ def list_apkbuilds(args): """ ret = {} for device in list_codenames(args): - apkbuild_path = args.aports + "/device/*/device-" + device + "/APKBUILD" + apkbuild_path = f"{args.aports}/device/*/device-{device}/APKBUILD" ret[device] = pmb.parse.apkbuild(args, apkbuild_path) return ret diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index 07ca4004..a1ce1956 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -40,14 +40,16 @@ def _parse_flavor(args, autoinstall=True): """ # Install at least one kernel and get installed flavors suffix = "rootfs_" + args.device - flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix, autoinstall) + flavors = pmb.chroot.other.kernel_flavors_installed( + args, suffix, autoinstall) # Parse and verify the flavor argument flavor = args.flavor if flavor: if flavor not in flavors: - raise RuntimeError("No kernel installed with flavor " + flavor + "!" + - " Run 'pmbootstrap flasher list_flavors' to get a list.") + raise RuntimeError(f"No kernel installed with flavor {flavor}!" + + " Run 'pmbootstrap flasher list_flavors' to" + " get a list.") return flavor if not len(flavors): raise RuntimeError( @@ -104,7 +106,8 @@ def build(args): return # Set src and force - src = os.path.realpath(os.path.expanduser(args.src[0])) if args.src else None + src = os.path.realpath(os.path.expanduser(args.src[0])) \ + if args.src else None force = True if src else args.force if src and not os.path.exists(src): raise RuntimeError("Invalid path specified for --src: " + src) @@ -196,7 +199,7 @@ def config(args): raise RuntimeError("config --reset requires a name to be given.") value = pmb.config.defaults[args.name] cfg["pmbootstrap"][args.name] = value - logging.info("Config changed to default: " + args.name + "='" + value + "'") + logging.info(f"Config changed to default: {args.name}='{value}'") pmb.config.save(args, cfg) elif args.value is not None: cfg["pmbootstrap"][args.name] = args.value @@ -228,7 +231,8 @@ def initfs(args): def install(args): if args.no_fde: - logging.warning("WARNING: --no-fde is deprecated, as it is now the default.") + logging.warning("WARNING: --no-fde is deprecated," + " as it is now the default.") if args.rsync and args.full_disk_encryption: raise ValueError("Installation using rsync is not compatible with full" " disk encryption.") @@ -391,7 +395,8 @@ def kconfig(args): packages.sort() for package in packages: if not args.force: - pkgname = package if package.startswith("linux-") else "linux-" + package + pkgname = package if package.startswith("linux-") \ + else "linux-" + package aport = pmb.helpers.pmaports.find(args, pkgname) apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD") if "!pmb:kconfigcheck" in apkbuild["options"]: @@ -542,7 +547,8 @@ def zap(args): def bootimg_analyze(args): bootimg = pmb.parse.bootimg(args, args.path) tmp_output = "Put these variables in the deviceinfo file of your device:\n" - for line in pmb.aportgen.device.generate_deviceinfo_fastboot_content(args, bootimg).split("\n"): + for line in pmb.aportgen.device.\ + generate_deviceinfo_fastboot_content(args, bootimg).split("\n"): tmp_output += "\n" + line.lstrip() logging.info(tmp_output) diff --git a/pmb/helpers/http.py b/pmb/helpers/http.py index 805d17d7..e095f79a 100644 --- a/pmb/helpers/http.py +++ b/pmb/helpers/http.py @@ -40,7 +40,8 @@ def download(args, url, prefix, cache=True, loglevel=logging.INFO, # Offline and not cached if args.offline: - raise RuntimeError(f"File not found in cache and offline flag is enabled: {url}") + raise RuntimeError("File not found in cache and offline flag is" + f" enabled: {url}") # Download the file logging.log(loglevel, "Download " + url) @@ -87,6 +88,6 @@ def retrieve(url, headers=None, allow_404=False): def retrieve_json(*args, **kwargs): - """ Fetch the contents of a URL, parse it as JSON and return it. See retrieve() for the - list of all parameters. """ + """ Fetch the contents of a URL, parse it as JSON and return it. See + retrieve() for the list of all parameters. """ return json.loads(retrieve(*args, **kwargs)) diff --git a/pmb/helpers/logging.py b/pmb/helpers/logging.py index 4c5359f1..094bf824 100644 --- a/pmb/helpers/logging.py +++ b/pmb/helpers/logging.py @@ -49,8 +49,9 @@ def add_verbose_log_level(): logging.addLevelName(logging.VERBOSE, "VERBOSE") logging.Logger.verbose = lambda inst, msg, * \ args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs) - logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, msg, - *args, **kwargs) + logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, + msg, *args, + **kwargs) def init(args): diff --git a/pmb/helpers/other.py b/pmb/helpers/other.py index 58726756..eec5f6e6 100644 --- a/pmb/helpers/other.py +++ b/pmb/helpers/other.py @@ -56,7 +56,8 @@ def check_binfmt_misc(args): return pmb.helpers.run.root(args, ["modprobe", "binfmt_misc"], check=False) - pmb.helpers.run.root(args, ["mount", "-t", "binfmt_misc", "none", "/proc/sys/fs/binfmt_misc"]) + pmb.helpers.run.root(args, ["mount", "-t", "binfmt_misc", "none", + "/proc/sys/fs/binfmt_misc"]) if not os.path.exists(path): link = "https://postmarketos.org/binfmt_misc" @@ -271,6 +272,7 @@ def validate_hostname(hostname): # Check that doesn't begin or end with a minus sign if hostname[:1] == "-" or hostname[-1:] == "-": - logging.fatal("ERROR: Hostname must not begin or end with a minus sign") + logging.fatal("ERROR: Hostname must not begin or end with a minus" + " sign") return False return True diff --git a/pmb/helpers/pkgrel_bump.py b/pmb/helpers/pkgrel_bump.py index 2b8e35ae..a43f4f49 100644 --- a/pmb/helpers/pkgrel_bump.py +++ b/pmb/helpers/pkgrel_bump.py @@ -112,8 +112,8 @@ def auto(args, dry=False): origin = apk["origin"] # Only increase once! if origin in ret: - logging.verbose("{}: origin '{}' found again".format(pkgname, - origin)) + logging.verbose( + f"{pkgname}: origin '{origin}' found again") continue aport_path = pmb.helpers.pmaports.find(args, origin, False) if not aport_path: diff --git a/pmb/helpers/pmaports.py b/pmb/helpers/pmaports.py index f34616b6..b468b255 100644 --- a/pmb/helpers/pmaports.py +++ b/pmb/helpers/pmaports.py @@ -27,7 +27,8 @@ def _find_apkbuilds(args): "subfolders. Please put it only in one folder.") apkbuilds[package] = apkbuild - # Sort dictionary so we don't need to do it over and over again in get_list() + # Sort dictionary so we don't need to do it over and over again in + # get_list() apkbuilds = dict(sorted(apkbuilds.items())) # Save result in cache @@ -170,8 +171,9 @@ def get(args, pkgname, must_exist=True, subpackages=True): :param pkgname: the package name to find :param must_exist: raise an exception when it can't be found - :param subpackages: also search for subpackages with the specified names - (slow! might need to parse all APKBUILDs to find it) + :param subpackages: also search for subpackages with the specified + names (slow! might need to parse all APKBUILDs to + find it) :returns: relevant variables from the APKBUILD as dictionary, e.g.: { "pkgname": "hello-world", "arch": ["all"], @@ -189,7 +191,8 @@ def get(args, pkgname, must_exist=True, subpackages=True): if path: return pmb.parse.apkbuild(args, path) if must_exist: - raise RuntimeError(f"Could not find APKBUILD for package: {pkgname}") + raise RuntimeError("Could not find APKBUILD for package:" + f" {pkgname}") return None diff --git a/pmb/helpers/run_core.py b/pmb/helpers/run_core.py index 40d4add5..d2a6c479 100644 --- a/pmb/helpers/run_core.py +++ b/pmb/helpers/run_core.py @@ -20,7 +20,8 @@ def sanity_checks(output="log", output_return=False, check=None): Raise an exception if the parameters passed to core() don't make sense (all parameters are described in core() below). """ - if output not in ["log", "stdout", "interactive", "tui", "background", "pipe"]: + vals = ["log", "stdout", "interactive", "tui", "background", "pipe"] + if output not in vals: raise RuntimeError("Invalid output value: " + str(output)) # Prevent setting the check parameter with output="background".