From 0b21a5a392bd84c07b94373991f59108fbe98516 Mon Sep 17 00:00:00 2001 From: Oskari Pirhonen Date: Tue, 21 Mar 2023 20:56:23 -0500 Subject: [PATCH] Convert %-formats to fstrings Files under lib/_emerge Signed-off-by: Oskari Pirhonen Closes: https://github.com/gentoo/portage/pull/1013 Signed-off-by: Sam James --- lib/_emerge/AbstractEbuildProcess.py | 64 +++---- lib/_emerge/AsynchronousLock.py | 5 +- lib/_emerge/BinpkgEnvExtractor.py | 5 +- lib/_emerge/BinpkgExtractorAsync.py | 60 +++---- lib/_emerge/BinpkgFetcher.py | 3 +- lib/_emerge/BinpkgVerifier.py | 17 +- lib/_emerge/EbuildMerge.py | 8 +- lib/_emerge/JobStatusDisplay.py | 8 +- lib/_emerge/MergeListItem.py | 4 +- lib/_emerge/Package.py | 8 +- lib/_emerge/Scheduler.py | 6 +- lib/_emerge/SpawnProcess.py | 11 +- lib/_emerge/SubProcess.py | 2 +- lib/_emerge/Task.py | 5 +- lib/_emerge/UserQuery.py | 5 +- lib/_emerge/actions.py | 128 ++++++-------- lib/_emerge/chk_updated_cfg_files.py | 6 +- lib/_emerge/countdown.py | 6 +- lib/_emerge/depgraph.py | 236 +++++++++---------------- lib/_emerge/resolver/output.py | 3 +- lib/_emerge/resolver/output_helpers.py | 10 +- lib/_emerge/resolver/slot_collision.py | 65 ++----- lib/_emerge/search.py | 3 +- lib/_emerge/unmerge.py | 28 ++- 24 files changed, 271 insertions(+), 425 deletions(-) diff --git a/lib/_emerge/AbstractEbuildProcess.py b/lib/_emerge/AbstractEbuildProcess.py index fe2ef426a7..be257a6202 100644 --- a/lib/_emerge/AbstractEbuildProcess.py +++ b/lib/_emerge/AbstractEbuildProcess.py @@ -13,7 +13,6 @@ from _emerge.EbuildIpcDaemon import EbuildIpcDaemon import portage from portage.elog import messages as elog_messages -from portage.localization import _ from portage.package.ebuild._ipc.ExitCommand import ExitCommand from portage.package.ebuild._ipc.QueryCommand import QueryCommand from portage import os @@ -72,10 +71,10 @@ def _start(self): # die_hooks for some reason, and PORTAGE_BUILDDIR # doesn't exist yet. if need_builddir and not os.path.isdir(self.settings["PORTAGE_BUILDDIR"]): - msg = _( - "The ebuild phase '%s' has been aborted " - "since PORTAGE_BUILDDIR does not exist: '%s'" - ) % (self.phase, self.settings["PORTAGE_BUILDDIR"]) + msg = ( + f"The ebuild phase '{self.phase}' has been aborted since " + f"PORTAGE_BUILDDIR does not exist: '{self.settings['PORTAGE_BUILDDIR']}'" + ) self._eerror(textwrap.wrap(msg, 72)) self.returncode = 1 self._async_wait() @@ -326,11 +325,10 @@ def _cancel_timeout_cb(self): def _orphan_process_warn(self): phase = self.phase - msg = _( - "The ebuild phase '%s' with pid %s appears " - "to have left an orphan process running in the " - "background." - ) % (phase, self.pid) + msg = ( + f"The ebuild phase '{phase}' with pid {self.pid} appears " + "to have left an orphan process running in the background." + ) self._eerror(textwrap.wrap(msg, 72)) @@ -346,38 +344,32 @@ def _can_log(self, slave_fd): ) or os.isatty(slave_fd) def _killed_by_signal(self, signum): - msg = _("The ebuild phase '%s' has been " "killed by signal %s.") % ( - self.phase, - signum, - ) + msg = f"The ebuild phase '{self.phase}' has been killed by signal {signum}." self._eerror(textwrap.wrap(msg, 72)) def _unexpected_exit(self): phase = self.phase msg = ( - _( - "The ebuild phase '%s' has exited " - "unexpectedly. This type of behavior " - "is known to be triggered " - "by things such as failed variable " - "assignments (bug #190128) or bad substitution " - "errors (bug #200313). Normally, before exiting, bash should " - "have displayed an error message above. If bash did not " - "produce an error message above, it's possible " - "that the ebuild has called `exit` when it " - "should have called `die` instead. This behavior may also " - "be triggered by a corrupt bash binary or a hardware " - "problem such as memory or cpu malfunction. If the problem is not " - "reproducible or it appears to occur randomly, then it is likely " - "to be triggered by a hardware problem. " - "If you suspect a hardware problem then you should " - "try some basic hardware diagnostics such as memtest. " - "Please do not report this as a bug unless it is consistently " - "reproducible and you are sure that your bash binary and hardware " - "are functioning properly." - ) - % phase + f"The ebuild phase '{phase}' has exited " + "unexpectedly. This type of behavior " + "is known to be triggered " + "by things such as failed variable " + "assignments (bug #190128) or bad substitution " + "errors (bug #200313). Normally, before exiting, bash should " + "have displayed an error message above. If bash did not " + "produce an error message above, it's possible " + "that the ebuild has called `exit` when it " + "should have called `die` instead. This behavior may also " + "be triggered by a corrupt bash binary or a hardware " + "problem such as memory or cpu malfunction. If the problem is not " + "reproducible or it appears to occur randomly, then it is likely " + "to be triggered by a hardware problem. " + "If you suspect a hardware problem then you should " + "try some basic hardware diagnostics such as memtest. " + "Please do not report this as a bug unless it is consistently " + "reproducible and you are sure that your bash binary and hardware " + "are functioning properly." ) self._eerror(textwrap.wrap(msg, 72)) diff --git a/lib/_emerge/AsynchronousLock.py b/lib/_emerge/AsynchronousLock.py index 329ce6bbe6..1a69d0847e 100644 --- a/lib/_emerge/AsynchronousLock.py +++ b/lib/_emerge/AsynchronousLock.py @@ -18,7 +18,6 @@ import portage from portage import os from portage.exception import TryAgain -from portage.localization import _ from portage.locks import lockfile, unlockfile from portage.util import writemsg_level from _emerge.AbstractPollTask import AbstractPollTask @@ -244,9 +243,7 @@ def _proc_exit(self, proc): # this failure appropriately. if not (self.cancelled or self._kill_test): writemsg_level( - "_LockProcess: %s\n" - % _("failed to acquire lock on '%s'") - % (self.path,), + "_LockProcess: failed to acquire lock on '{self.path}'\n", level=logging.ERROR, noiselevel=-1, ) diff --git a/lib/_emerge/BinpkgEnvExtractor.py b/lib/_emerge/BinpkgEnvExtractor.py index d25a2a8a78..7ce30548ad 100644 --- a/lib/_emerge/BinpkgEnvExtractor.py +++ b/lib/_emerge/BinpkgEnvExtractor.py @@ -31,10 +31,7 @@ def _get_dest_env_path(self): def _start(self): saved_env_path = self._get_saved_env_path() dest_env_path = self._get_dest_env_path() - shell_cmd = ( - "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- %s > %s" - % (_shell_quote(saved_env_path), _shell_quote(dest_env_path)) - ) + shell_cmd = f"${{PORTAGE_BUNZIP2_COMMAND:-${{PORTAGE_BZIP2_COMMAND}} -d}} -c -- {_shell_quote(saved_env_path)} > {_shell_quote(dest_env_path)}" logfile = None if self.settings.get("PORTAGE_BACKGROUND") != "subprocess": diff --git a/lib/_emerge/BinpkgExtractorAsync.py b/lib/_emerge/BinpkgExtractorAsync.py index f20b7707ab..be7a653f91 100644 --- a/lib/_emerge/BinpkgExtractorAsync.py +++ b/lib/_emerge/BinpkgExtractorAsync.py @@ -5,7 +5,6 @@ from _emerge.SpawnProcess import SpawnProcess import portage -from portage.localization import _ from portage.util.compression_probe import ( compression_probe, _compressors, @@ -21,6 +20,7 @@ import signal import subprocess import tarfile +import textwrap class BinpkgExtractorAsync(SpawnProcess): @@ -72,9 +72,7 @@ def _xpak_start(self): decomp_cmd = None if decomp_cmd is None: self.scheduler.output( - "!!! %s\n" - % _("File compression header unrecognized: %s") - % self.pkg_path, + f"!!! File compression header unrecognized: {self.pkg_path}\n", log_path=self.logfile, background=self.background, level=logging.ERROR, @@ -104,15 +102,9 @@ def _xpak_start(self): if find_binary(decompression_binary) is None: missing_package = decomp.get("package") self.scheduler.output( - "!!! %s\n" - % _( - "File compression unsupported %s.\n Command was: %s.\n Maybe missing package: %s" - ) - % ( - self.pkg_path, - varexpand(decomp_cmd, mydict=self.env), - missing_package, - ), + f"!!! File compression unsupported {self.pkg_path}.\n" + f" Command was: {varexpand(decomp_cmd, mydict=self.env)}.\n" + f" Missing package: {missing_package}\n", log_path=self.logfile, background=self.background, level=logging.ERROR, @@ -129,26 +121,30 @@ def _xpak_start(self): self.args = [ self._shell_binary, "-c", - ( - "cmd0=(head -c %d -- %s) cmd1=(%s) cmd2=(tar -xp %s -C %s -f -); " - + '"${cmd0[@]}" | "${cmd1[@]}" | "${cmd2[@]}"; ' - + "p=(${PIPESTATUS[@]}) ; for i in {0..2}; do " - + "if [[ ${p[$i]} != 0 && ${p[$i]} != %d ]] ; then " - + 'echo command $(eval "echo \\"\'\\${cmd$i[*]}\'\\"") ' - + "failed with status ${p[$i]} ; exit ${p[$i]} ; fi ; done; " - + "if [ ${p[$i]} != 0 ] ; then " - + 'echo command $(eval "echo \\"\'\\${cmd$i[*]}\'\\"") ' - + "failed with status ${p[$i]} ; exit ${p[$i]} ; fi ; " - + "exit 0 ;" + textwrap.dedent( + f""" + cmd0=(head -c {pkg_xpak.filestat.st_size - pkg_xpak.xpaksize} -- {portage._shell_quote(self.pkg_path)}) + cmd1=({decomp_cmd}) + cmd2=(tar -xp {tar_options} -C {portage._shell_quote(self.image_dir)} -f -); + """ + """ + "${cmd0[@]}" | "${cmd1[@]}" | "${cmd2[@]}"; + p=(${PIPESTATUS[@]}) ; for i in {0..2}; do + """ + f""" + if [[ ${{p[$i]}} != 0 && ${{p[$i]}} != {128 + signal.SIGPIPE} ]] ; then + """ + """ + echo command $(eval "echo \\"'\\${cmd$i[*]}'\\"") failed with status ${p[$i]} ; + exit ${p[$i]} ; fi ; done; + if [ ${p[$i]} != 0 ] ; then + echo command $(eval "echo \\"'\\${cmd$i[*]}'\\"") failed with status ${p[$i]} ; + exit ${p[$i]} ; fi ; + exit 0 ; + """ ) - % ( - pkg_xpak.filestat.st_size - pkg_xpak.xpaksize, - portage._shell_quote(self.pkg_path), - decomp_cmd, - tar_options, - portage._shell_quote(self.image_dir), - 128 + signal.SIGPIPE, - ), + .replace("\n", " ") + .strip(), ] SpawnProcess._start(self) diff --git a/lib/_emerge/BinpkgFetcher.py b/lib/_emerge/BinpkgFetcher.py index a18bed759e..10f9b6e427 100644 --- a/lib/_emerge/BinpkgFetcher.py +++ b/lib/_emerge/BinpkgFetcher.py @@ -244,8 +244,7 @@ def acquired_lock(async_lock): else: result.set_exception( AssertionError( - "AsynchronousLock failed with returncode %s" - % (async_lock.returncode,) + f"AsynchronousLock failed with returncode {async_lock.returncode}" ) ) diff --git a/lib/_emerge/BinpkgVerifier.py b/lib/_emerge/BinpkgVerifier.py index 4923331c33..58691e68b6 100644 --- a/lib/_emerge/BinpkgVerifier.py +++ b/lib/_emerge/BinpkgVerifier.py @@ -42,7 +42,7 @@ def _start(self): if e.errno not in (errno.ENOENT, errno.ESTALE): raise self.scheduler.output( - ("!!! Fetching Binary failed " "for '%s'\n") % self.pkg.cpv, + f"!!! Fetching Binary failed for '{self.pkg.cpv}'\n", log_path=self.logfile, background=self.background, ) @@ -123,15 +123,12 @@ def _digest_exception(self, name, value, expected): ) self.scheduler.output( - ( - "\n!!! Digest verification failed:\n" - "!!! %s\n" - "!!! Reason: Failed on %s verification\n" - "!!! Got: %s\n" - "!!! Expected: %s\n" - "File renamed to '%s'\n" - ) - % (self._pkg_path, name, value, expected, temp_filename), + "\n!!! Digest verification failed:\n" + f"!!! {self._pkg_path}\n" + f"!!! Reason: Failed on {name} verification\n" + f"!!! Got: {value}\n" + f"!!! Expected: {expected}\n" + f"File renamed to '{temp_filename}'\n", log_path=self.logfile, background=self.background, ) diff --git a/lib/_emerge/EbuildMerge.py b/lib/_emerge/EbuildMerge.py index f91beff5a2..7508c4a97a 100644 --- a/lib/_emerge/EbuildMerge.py +++ b/lib/_emerge/EbuildMerge.py @@ -75,13 +75,13 @@ def _merge_exit(self, merge_task): pkg.cpv, ) logger.log( - (" === (%s of %s) " + "Post-Build Cleaning (%s::%s)") - % (pkg_count.curval, pkg_count.maxval, pkg.cpv, pkg_path), + f" === ({pkg_count.curval} of {pkg_count.maxval}) " + f"Post-Build Cleaning ({pkg.cpv}::{pkg_path})", short_msg=short_msg, ) logger.log( - " ::: completed emerge (%s of %s) %s to %s" - % (pkg_count.curval, pkg_count.maxval, pkg.cpv, pkg.root) + f" ::: completed emerge ({pkg_count.curval} of {pkg_count.maxval}) " + f"{pkg.cpv} to {pkg.root}" ) self._start_exit_hook(self.returncode) diff --git a/lib/_emerge/JobStatusDisplay.py b/lib/_emerge/JobStatusDisplay.py index dfdd37c27d..9cf3c41db4 100644 --- a/lib/_emerge/JobStatusDisplay.py +++ b/lib/_emerge/JobStatusDisplay.py @@ -191,13 +191,11 @@ def _load_avg_str(self): max_avg = max(avg) if max_avg < 10: - digits = 2 + return ", ".join(f"{x:.2f}" for x in avg) elif max_avg < 100: - digits = 1 + return ", ".join(f"{x:.1f}" for x in avg) else: - digits = 0 - - return ", ".join(("%%.%df" % digits) % x for x in avg) + return ", ".join(f"{x:.0f}" for x in avg) def display(self): """ diff --git a/lib/_emerge/MergeListItem.py b/lib/_emerge/MergeListItem.py index fb3a0687a7..efe485c2e0 100644 --- a/lib/_emerge/MergeListItem.py +++ b/lib/_emerge/MergeListItem.py @@ -80,8 +80,8 @@ def _start(self): if not build_opts.pretend: self.statusMessage(msg) logger.log( - " >>> emerge (%s of %s) %s to %s" - % (pkg_count.curval, pkg_count.maxval, pkg.cpv, pkg.root) + f" >>> emerge ({pkg_count.curval} of {pkg_count.maxval}) " + f"{pkg.cpv} to {pkg.root}" ) if pkg.type_name == "ebuild": diff --git a/lib/_emerge/Package.py b/lib/_emerge/Package.py index 13ef5cabd0..873edbf81d 100644 --- a/lib/_emerge/Package.py +++ b/lib/_emerge/Package.py @@ -19,7 +19,6 @@ from portage.versions import _pkg_str, _unknown_repo from portage.eapi import _get_eapi_attrs from portage.exception import InvalidData, InvalidDependString -from portage.localization import _ from _emerge.Task import Task @@ -344,11 +343,8 @@ def _validate_deps(self): continue if atom.slot_operator_built: e = InvalidDependString( - _( - "Improper context for slot-operator " - '"built" atom syntax: %s' - ) - % (atom.unevaluated_atom,) + 'Improper context for slot-operator "built" ' + f"atom syntax: {atom.unevaluated_atom}" ) self._metadata_exception(k, e) diff --git a/lib/_emerge/Scheduler.py b/lib/_emerge/Scheduler.py index d2b1b59999..ece3f27f7c 100644 --- a/lib/_emerge/Scheduler.py +++ b/lib/_emerge/Scheduler.py @@ -2218,11 +2218,11 @@ def _world_atom(self, pkg): if atom is not None: if hasattr(world_set, "add"): self._status_msg( - ('Recording %s in "world" ' + "favorites file...") % atom + f'Recording {atom} in "world" favorites file...' ) logger.log( - " === (%s of %s) Updating world file (%s)" - % (pkg_count.curval, pkg_count.maxval, pkg.cpv) + f" === ({pkg_count.curval} of {pkg_count.maxval}) " + f"Updating world file ({pkg.cpv})" ) world_set.add(atom) else: diff --git a/lib/_emerge/SpawnProcess.py b/lib/_emerge/SpawnProcess.py index c00f86d0ec..db812a790a 100644 --- a/lib/_emerge/SpawnProcess.py +++ b/lib/_emerge/SpawnProcess.py @@ -11,7 +11,6 @@ import portage from portage import os from portage.const import BASH_BINARY -from portage.localization import _ from portage.output import EOutput from portage.util import writemsg_level from portage.util._async.BuildLogger import BuildLogger @@ -271,7 +270,7 @@ def kill_all(pids, sig): if e.errno == errno.EPERM: # Reported with hardened kernel (bug #358211). writemsg_level( - "!!! kill: (%i) - Operation not permitted\n" % (p,), + f"!!! kill: ({p}) - Operation not permitted\n", level=logging.ERROR, noiselevel=-1, ) @@ -291,11 +290,9 @@ def kill_all(pids, sig): if pids: msg = [] msg.append( - _("Failed to kill pid(s) in '%(cgroup)s': %(pids)s") - % dict( - cgroup=os.path.join(self.cgroup, "cgroup.procs"), - pids=" ".join(str(pid) for pid in pids), - ) + "Failed to kill pid(s) in " + f"'{os.path.join(self.cgroup, 'cgroup.procs')}': " + f"{' '.join(str(pid) for pid in pids)}" ) self._elog("eerror", msg) diff --git a/lib/_emerge/SubProcess.py b/lib/_emerge/SubProcess.py index ba783241c5..b734591d11 100644 --- a/lib/_emerge/SubProcess.py +++ b/lib/_emerge/SubProcess.py @@ -30,7 +30,7 @@ def _cancel(self): if e.errno == errno.EPERM: # Reported with hardened kernel (bug #358211). writemsg_level( - "!!! kill: (%i) - Operation not permitted\n" % (self.pid,), + f"!!! kill: ({self.pid}) - Operation not permitted\n", level=logging.ERROR, noiselevel=-1, ) diff --git a/lib/_emerge/Task.py b/lib/_emerge/Task.py index e3faec0878..de57d27e6a 100644 --- a/lib/_emerge/Task.py +++ b/lib/_emerge/Task.py @@ -41,7 +41,8 @@ def __str__(self): Emulate tuple.__repr__, but don't show 'foo' as u'foo' for unicode strings. """ - return "(%s)" % ", ".join("'%s'" % x for x in self._hash_key) + strings = (f"'{x}'" for x in self._hash_key) + return f"({', '.join(strings)})" def __repr__(self): if self._hash_key is None: @@ -49,5 +50,5 @@ def __repr__(self): return SlotObject.__repr__(self) return "<{} ({})>".format( self.__class__.__name__, - ", ".join("'%s'" % x for x in self._hash_key), + ", ".join(f"'{x}'" for x in self._hash_key), ) diff --git a/lib/_emerge/UserQuery.py b/lib/_emerge/UserQuery.py index c304a82cb2..73ebd3ca47 100644 --- a/lib/_emerge/UserQuery.py +++ b/lib/_emerge/UserQuery.py @@ -54,10 +54,7 @@ def query(self, prompt, enter_invalid, responses=None, colours=None): while True: try: response = input( - "[%s] " - % "/".join( - [colours[i](responses[i]) for i in range(len(responses))] - ) + f"[{'/'.join([colours[i](responses[i]) for i in range(len(responses))])}] " ) except UnicodeDecodeError as e: response = _unicode_decode(e.object).rstrip("\n") diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py index 6017579c8f..0aceb2c446 100644 --- a/lib/_emerge/actions.py +++ b/lib/_emerge/actions.py @@ -582,9 +582,7 @@ def action_build( for eroot in eroots: if need_write_vardb and not trees[eroot]["vartree"].dbapi.writable: writemsg_level( - "!!! %s\n" - % _("Read-only file system: %s") - % trees[eroot]["vartree"].dbapi._dbroot, + f"!!! Read-only file system: {trees[eroot]['vartree'].dbapi._dbroot}\n", level=logging.ERROR, noiselevel=-1, ) @@ -601,9 +599,7 @@ def action_build( and not trees[eroot]["bintree"].dbapi.writable ): writemsg_level( - "!!! %s\n" - % _("Read-only file system: %s") - % trees[eroot]["bintree"].pkgdir, + f"!!! Read-only file system: {trees[eroot]['bintree'].pkgdir}\n", level=logging.ERROR, noiselevel=-1, ) @@ -943,8 +939,7 @@ def _calc_depclean(settings, trees, ldpath_mtimes, myopts, action, args_set, spi # A nested set could not be resolved, so ignore nested sets. set_atoms[k] = root_config.sets[k].getAtoms() writemsg_level( - _("!!! The set '%s' " "contains a non-existent set named '%s'.\n") - % (k, e), + f"!!! The set '{k}' contains a non-existent set named '{e}'.\n", level=logging.ERROR, noiselevel=-1, ) @@ -967,8 +962,7 @@ def _calc_depclean(settings, trees, ldpath_mtimes, myopts, action, args_set, spi world_atoms = bool(root_config.setconfig.getSetAtoms("world")) except portage.exception.PackageSetNotFound as e: writemsg_level( - _("!!! The set '%s' " "contains a non-existent set named '%s'.\n") - % ("world", e), + f"!!! The set 'world' contains a non-existent set named '{e}'.\n", level=logging.ERROR, noiselevel=-1, ) @@ -1052,8 +1046,8 @@ def _calc_depclean(settings, trees, ldpath_mtimes, myopts, action, args_set, spi if not pkgs_for_cp or pkg not in pkgs_for_cp: raise AssertionError( "package expected in matches: " - + "cp = %s, cpv = %s matches = %s" - % (pkg.cp, pkg.cpv, [str(x) for x in pkgs_for_cp]) + f"cp = {pkg.cp}, cpv = {pkg.cpv}, " + f"matches = {[str(x) for x in pkgs_for_cp]}" ) highest_version = pkgs_for_cp[-1] @@ -1065,8 +1059,8 @@ def _calc_depclean(settings, trees, ldpath_mtimes, myopts, action, args_set, spi if len(pkgs_for_cp) <= 1: raise AssertionError( "more packages expected: " - + "cp = %s, cpv = %s matches = %s" - % (pkg.cp, pkg.cpv, [str(x) for x in pkgs_for_cp]) + f"cp = {pkg.cp}, cpv = {pkg.cpv}, " + f"matches = {[str(x) for x in pkgs_for_cp]}" ) try: @@ -1256,11 +1250,8 @@ def show_parents(child_node): # atoms in separate groups. atoms = sorted(atoms, reverse=True, key=operator.attrgetter("package")) parent_strs.append( - "%s requires %s" - % ( - getattr(parent, "cpv", parent), - ", ".join(str(atom) for atom in atoms), - ) + f"{getattr(parent, 'cpv', parent)} requires " + f"{', '.join(str(atom) for atom in atoms)}" ) parent_strs.sort() msg = [] @@ -1777,8 +1768,8 @@ def action_deselect(settings, trees, opts, atoms): filename = "world" writemsg_stdout( - '>>> %s %s from "%s" favorites file...\n' - % (action_desc, colorize("INFORM", str(atom)), filename), + f">>> {action_desc} {colorize('INFORM', str(atom))} " + f'from "{filename}" favorites file...\n', noiselevel=-1, ) @@ -1874,8 +1865,7 @@ def action_info(settings, trees, myopts, myfiles): if settings["ROOT"] != "/": xinfo = f"{xinfo} for {eroot}" writemsg( - "\nemerge: there are no ebuilds to satisfy %s.\n" - % colorize("INFORM", xinfo), + f"\nemerge: there are no ebuilds to satisfy {colorize('INFORM', xinfo)}.\n", noiselevel=-1, ) @@ -1897,8 +1887,7 @@ def action_info(settings, trees, myopts, myfiles): ) elif len(matches) > 1: writemsg( - "\nemerge: Maybe you meant any of these: %s?\n" - % (", ".join(matches),), + f"\nemerge: Maybe you meant any of these: {', '.join(matches)}?\n", noiselevel=-1, ) else: @@ -1933,14 +1922,14 @@ def action_info(settings, trees, myopts, myfiles): vm_info = get_vm_info() if "ram.total" in vm_info: - line = "%-9s %10d total" % ("KiB Mem:", vm_info["ram.total"] // 1024) + line = f"KiB Mem: {vm_info['ram.total'] // 1024:10d} total" if "ram.free" in vm_info: - line += ",%10d free" % (vm_info["ram.free"] // 1024,) + line += f",{vm_info['ram.free'] // 1024:10d} free" append(line) if "swap.total" in vm_info: - line = "%-9s %10d total" % ("KiB Swap:", vm_info["swap.total"] // 1024) + line = f"KiB Swap: {vm_info['swap.total'] // 1024:10d} total" if "swap.free" in vm_info: - line += ",%10d free" % (vm_info["swap.free"] // 1024,) + line += f",{vm_info['swap.free'] // 1024:10d} free" append(line) for repo in repos: @@ -2068,7 +2057,7 @@ def action_info(settings, trees, myopts, myfiles): try: x = Atom(x) except InvalidAtom: - append("%-20s %s" % (x + ":", "[NOT VALID]")) + append(f"{x + ':':<20s} [NOT VALID]") else: for atom in expand_new_virt(vardb, x): if not atom.blocker: @@ -2262,18 +2251,18 @@ def action_info(settings, trees, myopts, myfiles): if pkg_type == "installed": append( - "\n%s was built with the following:" - % colorize("INFORM", str(pkg.cpv + _repo_separator + pkg.repo)) + f"\n{colorize('INFORM', str(pkg.cpv + _repo_separator + pkg.repo))} " + "was built with the following:" ) elif pkg_type == "ebuild": append( - "\n%s would be built with the following:" - % colorize("INFORM", str(pkg.cpv + _repo_separator + pkg.repo)) + f"\n{colorize('INFORM', str(pkg.cpv + _repo_separator + pkg.repo))} " + "would be built with the following:" ) elif pkg_type == "binary": append( - "\n%s (non-installed binary) was built with the following:" - % colorize("INFORM", str(pkg.cpv + _repo_separator + pkg.repo)) + f"\n{colorize('INFORM', str(pkg.cpv + _repo_separator + pkg.repo))} " + "(non-installed binary) was built with the following:" ) append(f"{pkg_use_display(pkg, myopts)}") @@ -2474,11 +2463,7 @@ def action_uninstall(settings, trees, ldpath_mtimes, opts, action, files, spinne else: if atom.use and atom.use.conditional: writemsg_level( - ( - "\n\n!!! '%s' contains a conditional " - + "which is not allowed.\n" - ) - % (x,), + f"\n\n!!! '{x}' contains a conditional which is not allowed.\n", level=logging.ERROR, noiselevel=-1, ) @@ -2492,7 +2477,7 @@ def action_uninstall(settings, trees, ldpath_mtimes, opts, action, files, spinne elif x.startswith(os.sep): if not x.startswith(eroot): writemsg_level( - ("!!! '%s' does not start with" + " $EROOT.\n") % x, + f"!!! '{x}' does not start with $EROOT.\n", level=logging.ERROR, noiselevel=-1, ) @@ -2577,7 +2562,7 @@ def action_uninstall(settings, trees, ldpath_mtimes, opts, action, files, spinne valid_atoms.append(portage.dep.Atom(atom)) else: writemsg_level( - ("!!! '%s' is not claimed " + "by any package.\n") % lookup_owners[0], + f"!!! '{lookup_owners[0]}' is not claimed by any package.\n", level=logging.WARNING, noiselevel=-1, ) @@ -2708,8 +2693,8 @@ def adjust_config(myopts, settings): except ValueError as e: portage.writemsg(f"!!! {str(e)}\n", noiselevel=-1) portage.writemsg( - "!!! Unable to parse integer: EMERGE_WARNING_DELAY='%s'\n" - % settings["EMERGE_WARNING_DELAY"], + "!!! Unable to parse integer: " + f"EMERGE_WARNING_DELAY='{settings['EMERGE_WARNING_DELAY']}'\n", noiselevel=-1, ) settings["EMERGE_WARNING_DELAY"] = str(EMERGE_WARNING_DELAY) @@ -2740,15 +2725,15 @@ def adjust_config(myopts, settings): PORTAGE_DEBUG = int(settings.get("PORTAGE_DEBUG", str(PORTAGE_DEBUG))) if PORTAGE_DEBUG not in (0, 1): portage.writemsg( - "!!! Invalid value: PORTAGE_DEBUG='%i'\n" % PORTAGE_DEBUG, noiselevel=-1 + f"!!! Invalid value: PORTAGE_DEBUG='{PORTAGE_DEBUG}'\n", + noiselevel=-1, ) portage.writemsg("!!! PORTAGE_DEBUG must be either 0 or 1\n", noiselevel=-1) PORTAGE_DEBUG = 0 except ValueError as e: portage.writemsg(f"!!! {str(e)}\n", noiselevel=-1) portage.writemsg( - "!!! Unable to parse integer: PORTAGE_DEBUG='%s'\n" - % settings["PORTAGE_DEBUG"], + f"!!! Unable to parse integer: PORTAGE_DEBUG='{settings['PORTAGE_DEBUG']}'\n", noiselevel=-1, ) del e @@ -2783,8 +2768,8 @@ def adjust_config(myopts, settings): def display_missing_pkg_set(root_config, set_name): msg = [] msg.append( - ("emerge: There are no sets to satisfy '%s'. " + "The following sets exist:") - % colorize("INFORM", set_name) + f"emerge: There are no sets to satisfy '{colorize('INFORM', set_name)}'. " + "The following sets exist:" ) msg.append("") @@ -2806,7 +2791,14 @@ def relative_profile_path(portdir, abs_profile): def getportageversion(portdir, _unused, profile, chost, vardb): - pythonver = "python %d.%d.%d-%s-%d" % sys.version_info[:] + pythonver = ( + "python" + f" {sys.version_info[0]}" + f".{sys.version_info[1]}" + f".{sys.version_info[2]}" + f"-{sys.version_info[3]}" + f"-{sys.version_info[4]}" + ) profilever = None repositories = vardb.settings.repositories if profile: @@ -3078,7 +3070,7 @@ def ionice(settings): if rval != os.EX_OK: out = portage.output.EOutput() - out.eerror("PORTAGE_IONICE_COMMAND returned %d" % (rval,)) + out.eerror(f"PORTAGE_IONICE_COMMAND returned {rval}") out.eerror( "See the make.conf(5) man page for PORTAGE_IONICE_COMMAND usage instructions." ) @@ -3157,7 +3149,7 @@ def missing_sets_warning(root_config, missing_sets): missing_sets_str = ", ".join(f'"{s}"' for s in missing_sets[:-1]) missing_sets_str += f', and "{missing_sets[-1]}"' elif len(missing_sets) == 2: - missing_sets_str = '"%s" and "%s"' % tuple(missing_sets) + missing_sets_str = f'"{missing_sets[0]}" and "{missing_sets[1]}"' else: missing_sets_str = f'"{missing_sets[-1]}"' msg = [ @@ -3171,8 +3163,8 @@ def missing_sets_warning(root_config, missing_sets): portage.const.EPREFIX, portage.const.GLOBAL_CONFIG_PATH.lstrip(os.sep) ) msg.append( - " This usually means that '%s'" - % (os.path.join(global_config_path, "sets/portage.conf"),) + " This usually means that " + f"'{os.path.join(global_config_path, 'sets/portage.conf')}'" ) msg.append(" is missing or corrupt.") msg.append(" Falling back to default world and system set configuration!!!") @@ -3283,11 +3275,7 @@ def expand_set_arguments(myfiles, myaction, root_config): set_atoms = setconfig.getSetAtoms(s) except portage.exception.PackageSetNotFound as e: writemsg_level( - ( - "emerge: the given set '%s' " - + "contains a non-existent set named '%s'.\n" - ) - % (s, e), + f"emerge: the given set '{s}' contains a non-existent set named '{e}'.\n", level=logging.ERROR, noiselevel=-1, ) @@ -3297,12 +3285,8 @@ def expand_set_arguments(myfiles, myaction, root_config): ): writemsg_level( ( - "Use `emerge --deselect %s%s` to " + f"Use `emerge --deselect {SETPREFIX}{e}` to " "remove this set from world_sets.\n" - ) - % ( - SETPREFIX, - e, ), level=logging.ERROR, noiselevel=-1, @@ -3519,11 +3503,7 @@ def run_action(emerge_config): problematic = "PORTAGE_BINPKG_FORMAT" writemsg_level( - ( - "emerge: %s is not set correctly. Format " - + "'%s' is not supported.\n" - ) - % (problematic, fmt), + f"emerge: {problematic} is not set correctly. Format '{fmt}' is not supported.\n", level=logging.ERROR, noiselevel=-1, ) @@ -3598,8 +3578,7 @@ def run_action(emerge_config): and emerge_config.args ): writemsg( - "emerge: unexpected argument(s) for --resume: %s\n" - % " ".join(emerge_config.args), + f"emerge: unexpected argument(s) for --resume: {' '.join(emerge_config.args)}\n", noiselevel=-1, ) return 1 @@ -3741,7 +3720,7 @@ def run_action(emerge_config): emerge_config.opts["--pretend"] = True emerge_config.opts.pop("--ask") else: - sys.stderr.write(("emerge: %s access is required\n") % access_desc) + sys.stderr.write(f"emerge: {access_desc} access is required\n") if portage.data.secpass < 1 and not need_superuser: portage.data.portage_group_warning() return 1 @@ -3853,8 +3832,7 @@ def emergeexit(): if emerge_config.action in ("config", "metadata", "regen", "sync"): if "--pretend" in emerge_config.opts: sys.stderr.write( - ("emerge: The '%s' action does " + "not support '--pretend'.\n") - % emerge_config.action + f"emerge: The '{emerge_config.action}' action does not support '--pretend'.\n" ) return 1 diff --git a/lib/_emerge/chk_updated_cfg_files.py b/lib/_emerge/chk_updated_cfg_files.py index a924756012..db8b6e266b 100644 --- a/lib/_emerge/chk_updated_cfg_files.py +++ b/lib/_emerge/chk_updated_cfg_files.py @@ -22,7 +22,7 @@ def chk_updated_cfg_files(eroot, config_protect): ) if not x[1]: # it's a protected file writemsg_level( - _("config file '%s' needs updating.\n") % x[0], + f"config file '{x[0]}' needs updating.\n", level=logging.INFO, noiselevel=-1, ) @@ -32,13 +32,13 @@ def chk_updated_cfg_files(eroot, config_protect): tail = tail[len("._cfg0000_") :] fpath = os.path.join(head, tail) writemsg_level( - _("config file '%s' needs updating.\n") % fpath, + f"config file '{fpath}' needs updating.\n", level=logging.INFO, noiselevel=-1, ) else: writemsg_level( - _("%d config files in '%s' need updating.\n") % (len(x[1]), x[0]), + f"{len(x[1])} config files in '{x[0]}' need updating.\n", level=logging.INFO, noiselevel=-1, ) diff --git a/lib/_emerge/countdown.py b/lib/_emerge/countdown.py index 9d506c3c77..cd27e59a50 100644 --- a/lib/_emerge/countdown.py +++ b/lib/_emerge/countdown.py @@ -10,13 +10,13 @@ def countdown(secs=5, doing="Starting"): if secs: print( - ">>> Waiting %s seconds before starting...\n" + f">>> Waiting {secs} seconds before starting...\n" ">>> (Control-C to abort)...\n" - "%s in:" % (secs, doing), + f"{doing} in:", end="", ) for sec in range(secs, 0, -1): - sys.stdout.write(colorize("UNMERGE_WARN", " %i" % sec)) + sys.stdout.write(colorize("UNMERGE_WARN", f" {sec}")) sys.stdout.flush() time.sleep(1) print() diff --git a/lib/_emerge/depgraph.py b/lib/_emerge/depgraph.py index 412dc7b6f2..2c9820da1c 100644 --- a/lib/_emerge/depgraph.py +++ b/lib/_emerge/depgraph.py @@ -46,7 +46,6 @@ PackageNotFound, PortageException, ) -from portage.localization import _ from portage.output import colorize, create_color_func, darkgreen, green bad = create_color_func("BAD") @@ -1131,11 +1130,7 @@ def _changed_deps_report(self): return writemsg( - "\n%s\n\n" - % colorize( - "WARN", - "!!! Detected ebuild dependency change(s) without revision bump:", - ), + f"\n{colorize('WARN','!!! Detected ebuild dependency change(s) without revision bump:')}\n\n", noiselevel=-1, ) @@ -1411,14 +1406,13 @@ def _show_missed_update_slot_conflicts(self, missed_updates): msg.append(indent) msg.append( - "%s %s" - % ( - pkg, + f"{pkg} " + + str( pkg_use_display( pkg, self._frozen_config.myopts, modified_use=self._pkg_use_enabled(pkg), - ), + ) ) ) msg.append(" conflicts with\n") @@ -1646,8 +1640,7 @@ def __str__(self): noiselevel=-1, ) writemsg_level( - " arg, non-conflict: %s, %s\n" - % (is_arg_parent, is_non_conflict_parent), + f" arg, non-conflict: {is_arg_parent}, {is_non_conflict_parent}\n", level=logging.DEBUG, noiselevel=-1, ) @@ -1906,8 +1899,8 @@ def _process_slot_conflict(self, conflict): ): if debug: writemsg_level( - "!!! backtracking loop detected: %s %s\n" - % (pkg, self._dynamic_config._runtime_pkg_mask[pkg]), + f"!!! backtracking loop detected: {pkg} " + f"{self._dynamic_config._runtime_pkg_mask[pkg]}\n", level=logging.DEBUG, noiselevel=-1, ) @@ -2310,8 +2303,7 @@ def _slot_operator_check_reverse_dependencies( "", "", "_slot_operator_check_reverse_dependencies:", - " candidate package does not match atom '%s': %s" - % (atom, candidate_pkg), + f" candidate package does not match atom '{atom}': {candidate_pkg}", f" parent: {parent}", f" parent atoms: {' '.join(parent_atoms)}", "", @@ -2553,8 +2545,8 @@ def _slot_operator_update_probe( "slot_operator_update_probe:", f" existing child package: {dep.child}", f" existing parent package: {dep.parent}", - " new child package: %s" % None, - " new parent package: %s" % None, + " new child package: None", + " new parent package: None", "", ) writemsg_level("\n".join(msg), noiselevel=-1, level=logging.DEBUG) @@ -2617,8 +2609,8 @@ def _slot_operator_unsatisfied_probe(self, dep): "slot_operator_unsatisfied_probe:", f" existing parent package: {dep.parent}", f" existing parent atom: {dep.atom}", - " new parent package: %s" % None, - " new child package: %s" % None, + " new parent package: None", + " new child package: None", "", ) writemsg_level("\n".join(msg), noiselevel=-1, level=logging.DEBUG) @@ -3291,16 +3283,15 @@ def _add_pkg(self, pkg, dep): if debug: writemsg_level( - "\n%s%s %s\n" - % ( - "Child:".ljust(15), - pkg, + f"\n{'Child:':15}{pkg} " + + str( pkg_use_display( pkg, self._frozen_config.myopts, modified_use=self._pkg_use_enabled(pkg), - ), - ), + ) + ) + + "\n", level=logging.DEBUG, noiselevel=-1, ) @@ -3323,8 +3314,7 @@ def _add_pkg(self, pkg, dep): ): uneval = f" ({dep.atom.unevaluated_atom})" writemsg_level( - "%s%s%s required by %s\n" - % ("Parent Dep:".ljust(15), dep.atom, uneval, myparent), + f"{'Parent Dep:':15}{dep.atom}{uneval} required by {myparent}\n", level=logging.DEBUG, noiselevel=-1, ) @@ -3403,16 +3393,15 @@ def _add_pkg(self, pkg, dep): if debug: writemsg_level( - "%s%s %s\n" - % ( - "Re-used Child:".ljust(15), - pkg, + f"{'Re-used Child:':15}{pkg} " + + str( pkg_use_display( pkg, self._frozen_config.myopts, modified_use=self._pkg_use_enabled(pkg), - ), - ), + ) + ) + + "\n", level=logging.DEBUG, noiselevel=-1, ) @@ -3429,16 +3418,15 @@ def _add_pkg(self, pkg, dep): # missing dependencies, as discussed in bug 199856. if debug: writemsg_level( - "%s%s %s\n" - % ( - "Replace Child:".ljust(15), - pkg, + f"{'Replace Child:':15}{pkg} " + + str( pkg_use_display( pkg, self._frozen_config.myopts, modified_use=self._pkg_use_enabled(pkg), - ), - ), + ) + ) + + "\n", level=logging.DEBUG, noiselevel=-1, ) @@ -3447,16 +3435,15 @@ def _add_pkg(self, pkg, dep): else: if debug: writemsg_level( - "%s%s %s\n" - % ( - "Slot Conflict:".ljust(15), - existing_node, + f"{'Slot Conflict:':15}{existing_node} " + + str( pkg_use_display( existing_node, self._frozen_config.myopts, modified_use=self._pkg_use_enabled(existing_node), - ), - ), + ) + ) + + "\n", level=logging.DEBUG, noiselevel=-1, ) @@ -4542,7 +4529,7 @@ def _select_files(self, myfiles): writemsg( colorize( "BAD", - "\n{e}\n" % x, + f"\n{e}\n", ), noiselevel=-1, ) @@ -4589,16 +4576,12 @@ def _select_files(self, myfiles): break else: writemsg( - "\n%s\n\n" - % colorize( + "\n" + + colorize( "BAD", - "*** " - + _( - "You need to adjust PKGDIR to emerge " - "this package: %s" - ) - % x, - ), + f"*** You need to adjust PKGDIR to emerge this package: {x}", + ) + + "\n\n", noiselevel=-1, ) self._dynamic_config._skip_restart = True @@ -4611,9 +4594,9 @@ def _select_files(self, myfiles): tree_root = os.path.dirname(os.path.dirname(pkgdir)) cp = pkgdir[len(tree_root) + 1 :] error_msg = ( - "\n\n!!! '%s' is not in a valid ebuild repository " + f"\n\n!!! '{x}' is not in a valid ebuild repository " "hierarchy or does not exist\n" - ) % x + ) if not portage.isvalidatom(cp): writemsg(error_msg, noiselevel=-1) return 0, myfavorites @@ -4676,7 +4659,7 @@ def _select_files(self, myfiles): elif x.startswith(os.path.sep): if not x.startswith(eroot): portage.writemsg( - ("\n\n!!! '%s' does not start with" + " $EROOT.\n") % x, + f"\n\n!!! '{x}' does not start with $EROOT.\n", noiselevel=-1, ) self._dynamic_config._skip_restart = True @@ -4688,11 +4671,7 @@ def _select_files(self, myfiles): f = os.path.abspath(x) if not f.startswith(eroot): portage.writemsg( - ( - "\n\n!!! '%s' (resolved from '%s') does not start with" - + " $EROOT.\n" - ) - % (f, x), + f"\n\n!!! '{f}' (resolved from '{x}') does not start with $EROOT.\n", noiselevel=-1, ) self._dynamic_config._skip_restart = True @@ -4721,11 +4700,8 @@ def _select_files(self, myfiles): ) writemsg_level( - ( - "emerge: the given set '%s' " - "contains a non-existent set named '%s'.\n" - ) - % (s, e), + f"emerge: the given set '{s}' contains a non-existent set named " + f"'{e}'.\n", level=logging.ERROR, noiselevel=-1, ) @@ -4734,14 +4710,8 @@ def _select_files(self, myfiles): and SETPREFIX + e.value in sets["selected"] ): writemsg_level( - ( - "Use `emerge --deselect %s%s` to " - "remove this set from world_sets.\n" - ) - % ( - SETPREFIX, - e, - ), + f"Use `emerge --deselect {SETPREFIX}{e}` to remove this set from " + "world_sets.\n", level=logging.ERROR, noiselevel=-1, ) @@ -4835,11 +4805,7 @@ def _select_files(self, myfiles): if atom.use and atom.use.conditional: writemsg( - ( - "\n\n!!! '%s' contains a conditional " - + "which is not allowed.\n" - ) - % (x,), + f"\n\n!!! '{x}' contains a conditional which is not allowed.\n", noiselevel=-1, ) writemsg("!!! Please check ebuild(5) for full details.\n") @@ -4867,8 +4833,7 @@ def _select_files(self, myfiles): if not owners: portage.writemsg( - ("\n\n!!! '%s' is not claimed " + "by any package.\n") - % lookup_owners[0], + f"\n\n!!! '{lookup_owners[0]}' is not claimed by any package.\n", noiselevel=-1, ) self._dynamic_config._skip_restart = True @@ -5001,11 +4966,7 @@ def _resolve(self, myfavorites): ): if not self.need_restart(): writemsg( - ( - "\n\n!!! Problem " - + "resolving dependencies for %s\n" - ) - % arg.arg, + f"\n\n!!! Problem resolving dependencies for {arg.arg}\n", noiselevel=-1, ) return 0, myfavorites @@ -5117,17 +5078,13 @@ def _resolve(self, myfavorites): pass elif isinstance(arg, SetArg): writemsg( - ( - "\n\n!!! Problem resolving " - + "dependencies for %s from %s\n" - ) - % (atom, arg.arg), + f"\n\n!!! Problem resolving dependencies for {atom} from " + f"{arg.arg}\n", noiselevel=-1, ) else: writemsg( - ("\n\n!!! Problem resolving " + "dependencies for %s\n") - % (atom,), + f"\n\n!!! Problem resolving dependencies for {atom}\n", noiselevel=-1, ) return 0, myfavorites @@ -6209,8 +6166,8 @@ def _show_unsatisfied_dep( ): required_use_warning = ( ", this change violates use flag constraints " - + "defined by %s: '%s'" - % (pkg.cpv, human_readable_required_use(required_use)) + f"defined by {pkg.cpv}: " + f"'{human_readable_required_use(required_use)}'" ) if need_enable or need_disable: @@ -6280,11 +6237,8 @@ def _show_unsatisfied_dep( ): required_use_warning = ( ", this change violates use flag constraints " - + "defined by %s: '%s'" - % ( - myparent.cpv, - human_readable_required_use(required_use), - ) + f"defined by {myparent.cpv}: " + f"'{human_readable_required_use(required_use)}'" ) target_use = {} @@ -6467,10 +6421,10 @@ def _show_unsatisfied_dep( writemsg("\n", noiselevel=-1) msg = ( "The current version of portage supports " - + "EAPI '%s'. You must upgrade to a newer version" - + " of portage before EAPI masked packages can" - + " be installed." - ) % portage.const.EAPI + f"EAPI '{portage.const.EAPI}'. You must upgrade to a newer version" + " of portage before EAPI masked packages can" + " be installed." + ) writemsg("\n".join(textwrap.wrap(msg, 75)), noiselevel=-1) writemsg("\n", noiselevel=-1) mask_docs = True @@ -6481,17 +6435,16 @@ def _show_unsatisfied_dep( cp_exists = True break - writemsg( - "\nemerge: there are no %s to satisfy " - % ( - "binary packages" - if self._frozen_config.myopts.get("--usepkgonly", "y") == True - else "ebuilds" + if self._frozen_config.myopts.get("--usepkgonly", "y"): + writemsg( + f"\nemerge: there are no binary packages to satisfy {green(xinfo)}.\n", + noiselevel=-1, + ) + else: + writemsg( + f"\nemerge: there are no ebuilds to satisfy {green(xinfo)}.\n", + noiselevel=-1, ) - + green(xinfo) - + ".\n", - noiselevel=-1, - ) if ( isinstance(myparent, AtomArg) and not cp_exists @@ -6518,8 +6471,7 @@ def _show_unsatisfied_dep( ) elif len(matches) > 1: writemsg( - "\nemerge: Maybe you meant any of these: %s?\n" - % (", ".join(matches),), + f"\nemerge: Maybe you meant any of these: {', '.join(matches)}?\n", noiselevel=-1, ) else: @@ -6533,8 +6485,7 @@ def _show_unsatisfied_dep( dep_chain = self._get_dep_chain(myparent, atom) for node, node_type in dep_chain: msg.append( - '(dependency required by "%s" [%s])' - % (colorize("INFORM", "%s" % (node)), node_type) + f'(dependency required by "{colorize("INFORM", str(node))}" [{node_type}])' ) if msg: @@ -7750,13 +7701,7 @@ def _wrapped_select_pkg_highest_available_imp( if "--debug" in self._frozen_config.myopts: for pkg in matched_packages: portage.writemsg( - "%s %s%s%s\n" - % ( - (pkg.type_name + ":").rjust(10), - pkg.cpv, - _repo_separator, - pkg.repo, - ), + f"{pkg.type_name + ':':>10} {pkg.cpv}{_repo_separator}{pkg.repo}\n", noiselevel=-1, ) @@ -8962,8 +8907,7 @@ def get_nodes(**kwargs): except portage.exception.InvalidDependString as e: portage.writemsg( "!!! Invalid RDEPEND in " - + "'%svar/db/pkg/%s/RDEPEND': %s\n" - % (running_root, running_portage.cpv, e), + f"'{running_root}var/db/pkg/{running_portage.cpv}/RDEPEND': {e}\n", noiselevel=-1, ) del e @@ -9247,8 +9191,7 @@ def find_smallest_cycle(mergeable_nodes, local_priority_range): if debug: writemsg( - "\nruntime cycle digraph (%s nodes):\n\n" - % (len(selected_nodes),), + f"\nruntime cycle digraph ({len(selected_nodes)} nodes):\n\n", noiselevel=-1, ) cycle_digraph.debug_print() @@ -9695,8 +9638,9 @@ def find_smallest_cycle(mergeable_nodes, local_priority_range): for node in retlist: if isinstance(node, Package) and node.operation == "uninstall": msg.append(f"\t{node}") + temp_joined = "".join(f"{line}\n" for line in msg) writemsg_level( - "\n%s\n" % "".join("%s\n" % line for line in msg), + f"\n{temp_joined}\n", level=logging.DEBUG, noiselevel=-1, ) @@ -9912,8 +9856,8 @@ def _show_unsatisfied_blockers(self, blockers): # issues with conditional use-flags missing # from IUSE. msg.append( - "%s (%s) required by %s %s" - % (atom.unevaluated_atom, atom, parent, use_display) + f"{atom.unevaluated_atom} ({atom}) " + f"required by {parent} {use_display}" ) else: msg.append(f"{atom} required by {parent} {use_display}") @@ -10247,8 +10191,7 @@ def find_config_file(abs_user_config, file_name): for (abs_user_config, f), path in file_to_write_to.items(): if path is None: problems.append( - "!!! No file to write for '%s'\n" - % os.path.join(abs_user_config, f) + f"!!! No file to write for '{os.path.join(abs_user_config, f)}'\n" ) write_to_file = not problems @@ -10272,11 +10215,8 @@ def format_msg(lines): def _writemsg(reason, file): writemsg( - ( - "\nThe following %s are necessary to proceed:\n" - ' (see "%s" in the portage(5) man page for more details)\n' - ) - % (colorize("BAD", reason), file), + f"\nThe following {colorize('BAD', reason)} are necessary to proceed:\n" + f' (see "{file}" in the portage(5) man page for more details)\n', noiselevel=-1, ) @@ -10674,8 +10614,7 @@ def saveNomergeFavorites(self): noiselevel=-1, ) writemsg( - "!!! see '%s'\n\n" - % os.path.join(x.root, portage.VDB_PATH, x.cpv, "PROVIDE"), + f"!!! see '{os.path.join(x.root, portage.VDB_PATH, x.cpv, 'PROVIDE')}'\n\n", noiselevel=-1, ) del e @@ -10718,8 +10657,8 @@ def saveNomergeFavorites(self): else: filename = "world" writemsg_stdout( - '>>> Recording %s in "%s" favorites file...\n' - % (colorize("INFORM", str(a)), filename), + f">>> Recording {colorize('INFORM', str(a))} " + f'in "{filename}" favorites file...\n', noiselevel=-1, ) world_set.update(all_added) @@ -11762,10 +11701,7 @@ def show_masked_packages(masked_packages): l_path = portdb.findLicensePath(l) if l_path is None: continue - msg = ("A copy of the '%s' license" + " is located at '%s'.\n\n") % ( - l, - l_path, - ) + msg = f"A copy of the '{l}' license is located at '{l_path}'.\n\n" writemsg(msg, noiselevel=-1) shown_licenses.add(l) return have_eapi_mask diff --git a/lib/_emerge/resolver/output.py b/lib/_emerge/resolver/output.py index 4d4626c331..831076c8ae 100644 --- a/lib/_emerge/resolver/output.py +++ b/lib/_emerge/resolver/output.py @@ -112,8 +112,7 @@ def _blockers(self, blocker): if self.resolved != blocker.atom: addl += colorize( self.blocker_style, - ' ("%s" is %s %s)' - % (str(blocker.atom).lstrip("!"), blocking_desc, block_parents), + f' ("{str(blocker.atom).lstrip("!")}" is {blocking_desc} {block_parents})', ) else: addl += colorize( diff --git a/lib/_emerge/resolver/output_helpers.py b/lib/_emerge/resolver/output_helpers.py index fb9a030cae..3669f3b6c2 100644 --- a/lib/_emerge/resolver/output_helpers.py +++ b/lib/_emerge/resolver/output_helpers.py @@ -150,8 +150,9 @@ def __str__(self): myoutput.append("s") if self.restrict_fetch_satisfied < self.restrict_fetch: myoutput.append( - bad(" (%s unsatisfied)") - % (self.restrict_fetch - self.restrict_fetch_satisfied) + bad( + f" ({self.restrict_fetch - self.restrict_fetch_satisfied} unsatisfied)" + ) ) if self.blocks > 0: myoutput.append(f"\nConflict: {self.blocks} block") @@ -159,7 +160,7 @@ def __str__(self): myoutput.append("s") if self.blocks_satisfied < self.blocks: myoutput.append( - bad(" (%s unsatisfied)") % (self.blocks - self.blocks_satisfied) + bad(f" ({self.blocks - self.blocks_satisfied} unsatisfied)") ) else: myoutput.append(" (all satisfied)") @@ -205,8 +206,7 @@ def __init__(self, depgraph, mylist, favorites, verbosity): except ValueError as e: writemsg(f"!!! {str(e)}\n", noiselevel=-1) writemsg( - "!!! Unable to parse COLUMNWIDTH='%s'\n" - % frozen_config.settings["COLUMNWIDTH"], + f"!!! Unable to parse COLUMNWIDTH='{frozen_config.settings['COLUMNWIDTH']}'\n", noiselevel=-1, ) del e diff --git a/lib/_emerge/resolver/slot_collision.py b/lib/_emerge/resolver/slot_collision.py index 4ccd756b72..7e579f3944 100644 --- a/lib/_emerge/resolver/slot_collision.py +++ b/lib/_emerge/resolver/slot_collision.py @@ -266,14 +266,13 @@ def _prepare_conflict_msg_and_check_for_specificity(self): for pkg in pkgs: msg.append(indent) msg.append( - "%s %s" - % ( - pkg, + f"{pkg} " + + str( pkg_use_display( pkg, self.depgraph._frozen_config.myopts, modified_use=self.depgraph._pkg_use_enabled(pkg), - ), + ) ) ) parent_atoms = self.all_parents.get(pkg) @@ -368,19 +367,12 @@ def _prepare_conflict_msg_and_check_for_specificity(self): msg = ( "\n\n!!! BUG: Detected " "USE dep match inconsistency:\n" - "\tppkg: %s\n" - "\tviolated_atom: %s\n" - "\tatom: %s unevaluated: %s\n" - "\tother_pkg: %s IUSE: %s USE: %s\n" - % ( - ppkg, - violated_atom, - atom, - atom.unevaluated_atom, - other_pkg, - sorted(other_pkg.iuse.all), - sorted(_pkg_use_enabled(other_pkg)), - ) + f"\tppkg: {ppkg}\n" + f"\tviolated_atom: {violated_atom}\n" + f"\tatom: {atom} unevaluated: {atom.unevaluated_atom}\n" + f"\tother_pkg: {other_pkg} " + f"IUSE: {sorted(other_pkg.iuse.all)} " + f"USE: {sorted(_pkg_use_enabled(other_pkg))}\n" ) writemsg(msg, noiselevel=-2) raise AssertionError( @@ -703,13 +695,11 @@ def highlight_violations(atom, version, use, slot_violated): msg.append(2 * indent) if len(selected_for_display) > 1: msg.append( - "(and %d more with the same problems)\n" - % omitted_parents + f"(and {omitted_parents} more with the same problems)\n" ) else: msg.append( - "(and %d more with the same problem)\n" - % omitted_parents + f"(and {omitted_parents} more with the same problem)\n" ) else: msg.append(" (no parents)\n") @@ -824,11 +814,7 @@ def _check_configuration( ): if self.debug: writemsg( - ( - "%s has pending USE changes. " - "Rejecting configuration.\n" - ) - % (pkg,), + f"{pkg} has pending USE changes. Rejecting configuration.\n", noiselevel=-1, ) return False @@ -857,11 +843,8 @@ def _check_configuration( # Version range does not match. if self.debug: writemsg( - ( - "%s does not satify all version " - "requirements. Rejecting configuration.\n" - ) - % (pkg,), + f"{pkg} does not satify all version " + "requirements. Rejecting configuration.\n", noiselevel=-1, ) return False @@ -871,11 +854,7 @@ def _check_configuration( # FIXME: This needs to support use dep defaults. if self.debug: writemsg( - ( - "%s misses needed flags from IUSE." - " Rejecting configuration.\n" - ) - % (pkg,), + f"{pkg} misses needed flags from IUSE. Rejecting configuration.\n", noiselevel=-1, ) return False @@ -909,11 +888,8 @@ def _check_configuration( # part of the conflict, isn't it?) if self.debug: writemsg( - ( - "%s: installed package would need USE" - " changes. Rejecting configuration.\n" - ) - % (pkg,), + f"{pkg}: installed package would need USE changes. " + "Rejecting configuration.\n", noiselevel=-1, ) return False @@ -1185,11 +1161,8 @@ def _check_solution( is_valid_solution = False if self.debug: writemsg( - ( - "new conflict introduced: %s" - " does not match %s from %s\n" - ) - % (pkg, new_atom, ppkg), + f"new conflict introduced: {pkg} does not match " + f"{new_atom} from {ppkg}\n", noiselevel=-1, ) break diff --git a/lib/_emerge/search.py b/lib/_emerge/search.py index eace589c24..e422434a72 100644 --- a/lib/_emerge/search.py +++ b/lib/_emerge/search.py @@ -502,8 +502,7 @@ def append(msg): if self.verbose: if available: msg.append( - " %s %s\n" - % (darkgreen("Latest version available:"), myversion) + f" {darkgreen('Latest version available:')} {myversion}\n" ) msg.append( f" {self.getInstallationStatus(mycat + '/' + mypkg)}\n" diff --git a/lib/_emerge/unmerge.py b/lib/_emerge/unmerge.py index e8fabb85f2..398674c575 100644 --- a/lib/_emerge/unmerge.py +++ b/lib/_emerge/unmerge.py @@ -8,7 +8,6 @@ import portage from portage import os from portage.dbapi._expand_new_virt import expand_new_virt -from portage.localization import _ from portage.output import bold, colorize, darkgreen, green from portage._sets import SETPREFIX from portage._sets.base import EditablePackageSet @@ -228,8 +227,7 @@ def _pkg(cpv): mymatch = vartree.dep_match(x) if not mymatch: portage.writemsg( - "\n--- Couldn't find '%s' to %s.\n" - % (x.replace("null/", ""), unmerge_action), + f"\n--- Couldn't find '{x.replace('null/', '')}' to {unmerge_action}.\n", noiselevel=-1, ) continue @@ -369,17 +367,17 @@ def _pkg(cpv): skip_pkg = False if portage.match_from_list(portage.const.PORTAGE_PACKAGE_ATOM, [pkg]): msg = ( - "Not unmerging package %s " + f"Not unmerging package {pkg.cpv} " "since there is no valid reason for Portage to " - "%s itself." - ) % (pkg.cpv, unmerge_action) + f"{unmerge_action} itself." + ) skip_pkg = True elif vartree.dbapi._dblink(cpv).isowner(portage._python_interpreter): msg = ( - "Not unmerging package %s since there is no valid " - "reason for Portage to %s currently used Python " + f"Not unmerging package {pkg.cpv} since there is no valid " + f"reason for Portage to {unmerge_action} currently used Python " "interpreter." - ) % (pkg.cpv, unmerge_action) + ) skip_pkg = True if skip_pkg: for line in textwrap.wrap(msg, 75): @@ -404,12 +402,8 @@ def _pkg(cpv): unknown_sets.add(s) out = portage.output.EOutput() out.eerror( - ("Unknown set '@%s' in %s%s") - % ( - s, - root_config.settings["EROOT"], - portage.const.WORLD_SETS_FILE, - ) + f"Unknown set '@{s}' in " + f"{root_config.settings['EROOT']}{portage.const.WORLD_SETS_FILE}" ) continue @@ -555,7 +549,7 @@ def _pkg(cpv): writemsg_level("\n", noiselevel=-1) writemsg_level( - "\nAll selected packages: %s\n" % " ".join("=%s" % x for x in all_selected), + f"\nAll selected packages: {' '.join(f'={x}' for x in all_selected)}\n", noiselevel=-1, ) @@ -632,7 +626,7 @@ def unmerge( if not vartree.dbapi.writable: writemsg_level( - "!!! %s\n" % _("Read-only file system: %s") % vartree.dbapi._dbroot, + f"!!! Read-only file system: {vartree.dbapi._dbroot}\n", level=logging.ERROR, noiselevel=-1, )