From 6c0b816e732fb0dba3fce06906684879d84f6236 Mon Sep 17 00:00:00 2001 From: Alfred Wingate Date: Thu, 16 Nov 2023 05:56:40 +0200 Subject: [PATCH] Use f-strings or .format() over percent style https://docs.astral.sh/ruff/rules/printf-string-formatting/ Signed-off-by: Alfred Wingate --- bin/euscan | 4 ++-- bin/euscan_patch_metadata | 21 ++++++--------------- src/euscan/ebuild.py | 2 +- src/euscan/handlers/__init__.py | 2 +- src/euscan/handlers/cpan.py | 10 ++-------- src/euscan/handlers/freecode.py | 2 +- src/euscan/handlers/generic.py | 16 ++++++++-------- src/euscan/handlers/github.py | 5 ++--- src/euscan/handlers/php.py | 4 ++-- src/euscan/handlers/rubygems.py | 4 ++-- src/euscan/helpers.py | 8 ++++---- src/euscan/out.py | 18 ++++++++---------- src/euscan/scan.py | 2 +- 13 files changed, 40 insertions(+), 58 deletions(-) diff --git a/bin/euscan b/bin/euscan index 2477b6e..a78b9b2 100755 --- a/bin/euscan +++ b/bin/euscan @@ -362,7 +362,7 @@ def main(): exit_helper(1) except GentoolkitException as err: - output.eerror("%s: %s" % (query, str(err))) + output.eerror(f"{query}: {str(err)}") exit_helper(1) except Exception as err: @@ -372,7 +372,7 @@ def main(): traceback.print_exc(file=sys.stderr) print("-" * 60) - output.eerror("%s: %s" % (query, str(err))) + output.eerror(f"{query}: {str(err)}") exit_helper(1) if not ret and not CONFIG["quiet"]: diff --git a/bin/euscan_patch_metadata b/bin/euscan_patch_metadata index 449b253..98009a9 100755 --- a/bin/euscan_patch_metadata +++ b/bin/euscan_patch_metadata @@ -30,10 +30,10 @@ def guess_indent_values(before): def guess_for_tags(tags): for tag in tags: for i in [0, 2, 4, 6, 8, 12, 16]: - if "\n%s<%s" % (" " * i, tag) in before: + if f"\n{' ' * i}<{tag}" in before: return i, False for i in [0, 1, 2]: - if "\n%s<%s" % ("\t" * i, tag) in before: + if f"\n{'\t' * i}<{tag}" in before: return i, True return -1, False @@ -180,7 +180,7 @@ def patch_metadata(package, watch_data, diff=False): if opt_name in valid: if opt_name == "uversionmangle": opt_name = "versionmangle" - cleaned_opts.append('%s="%s"' % (opt_name, opt_value)) + cleaned_opts.append(f'{opt_name}="{opt_value}"') opts = " ".join(cleaned_opts) # clean url from useless stuff. Just keep [] @@ -188,14 +188,9 @@ def patch_metadata(package, watch_data, diff=False): url = " ".join([x for x in url_search.groups() if x is not None]) if opts: - watch_tag = '%s%s' % ( - indent, - version, - opts, - url, - ) + watch_tag = f'{indent}{url}' else: - watch_tag = '%s%s' % (indent, version, url) + watch_tag = f'{indent}{url}' watch_tags.append(watch_tag) watch_tags = "\n".join(watch_tags) @@ -203,11 +198,7 @@ def patch_metadata(package, watch_data, diff=False): if "" in data: data = data.replace("", "\n%s" % watch_tags, 1) else: - rep = "%s\n%s\n%s\n" % ( - rindent, - watch_tags, - rindent, - ) + rep = f"{rindent}\n{watch_tags}\n{rindent}\n" data = data.replace("", rep, 1) if not diff: diff --git a/src/euscan/ebuild.py b/src/euscan/ebuild.py index 2dae1f3..774a929 100644 --- a/src/euscan/ebuild.py +++ b/src/euscan/ebuild.py @@ -71,7 +71,7 @@ def package_from_ebuild(ebuild): return False ebuild_split = ebuild.split("/") - cpv = "%s/%s" % (ebuild_split[-3], pf) + cpv = f"{ebuild_split[-3]}/{pf}" if not portage.catpkgsplit(cpv): return False diff --git a/src/euscan/handlers/__init__.py b/src/euscan/handlers/__init__.py index 4e426c4..e7a40fe 100644 --- a/src/euscan/handlers/__init__.py +++ b/src/euscan/handlers/__init__.py @@ -157,7 +157,7 @@ def scan_url(pkg, urls, options, on_progress=None): else: output.eerror("Can't find a suitable handler!") except Exception as e: - output.ewarn("Handler failed: [%s] %s" % (e.__class__.__name__, str(e))) + output.ewarn(f"Handler failed: [{e.__class__.__name__}] {str(e)}") if versions and CONFIG["oneshot"]: break diff --git a/src/euscan/handlers/cpan.py b/src/euscan/handlers/cpan.py index 4b44351..d88d355 100644 --- a/src/euscan/handlers/cpan.py +++ b/src/euscan/handlers/cpan.py @@ -81,7 +81,7 @@ def mangle_version(up_pv): pv = ".".join(groups) if rc_part: - pv = "%s_rc%s" % (pv, rc_part) + pv = f"{pv}_rc{rc_part}" return pv @@ -157,13 +157,7 @@ def scan_pkg(pkg, options): if helpers.version_filtered(cp, m_ver, m_pv, cpan_vercmp): continue - url = "mirror://cpan/authors/id/%s/%s/%s/%s" % ( - version["cpanid"][0], - version["cpanid"][0:1], - version["cpanid"], - version["archive"], - ) - + url = f"mirror://cpan/authors/id/{version['cpanid'][0]}/{version['cpanid'][0:1]}/{version['cpanid']}/{version['archive']}" url = mangling.mangle_url(url, options) ret.append((url, pv, HANDLER_NAME, CONFIDENCE)) diff --git a/src/euscan/handlers/freecode.py b/src/euscan/handlers/freecode.py index ad96d64..ab83fee 100644 --- a/src/euscan/handlers/freecode.py +++ b/src/euscan/handlers/freecode.py @@ -40,7 +40,7 @@ def scan_pkg(pkg, options): if helpers.version_filtered(cp, ver, pv): continue fp = urllib.request.urlopen( - "http://freecode.com/projects/%s/releases/%s" % (package, release_id) + f"http://freecode.com/projects/{package}/releases/{release_id}" ) content = str(fp.read()) download_page = re.findall(r'