From 64b4ff0a84a49cdaebb28c931596e835fcc2a9bc Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Thu, 20 Aug 2026 10:51:44 +0200 Subject: [PATCH 01/14] pyupgrade --- src/mr/developer/bazaar.py | 8 ++-- src/mr/developer/commands.py | 21 ++++---- src/mr/developer/common.py | 23 ++++----- src/mr/developer/compat.py | 16 ++----- src/mr/developer/cvs.py | 8 ++-- src/mr/developer/darcs.py | 10 ++-- src/mr/developer/develop.py | 8 ++-- src/mr/developer/extension.py | 8 ++-- src/mr/developer/git.py | 30 ++++++------ src/mr/developer/gitsvn.py | 12 ++--- src/mr/developer/mercurial.py | 16 +++---- src/mr/developer/svn.py | 20 ++++---- src/mr/developer/tests/test_commands.py | 26 +++++----- src/mr/developer/tests/test_extension.py | 6 +-- src/mr/developer/tests/test_git.py | 24 +++++----- src/mr/developer/tests/test_git_submodules.py | 48 +++++++++---------- src/mr/developer/tests/test_mercurial.py | 14 +++--- src/mr/developer/tests/test_svn.py | 14 +++--- src/mr/developer/tests/utils.py | 18 +++---- 19 files changed, 158 insertions(+), 172 deletions(-) diff --git a/src/mr/developer/bazaar.py b/src/mr/developer/bazaar.py index b0a85426..1bf7dc1a 100644 --- a/src/mr/developer/bazaar.py +++ b/src/mr/developer/bazaar.py @@ -12,7 +12,7 @@ class BazaarError(common.WCError): class BazaarWorkingCopy(common.BaseWorkingCopy): def __init__(self, source): - super(BazaarWorkingCopy, self).__init__(source) + super().__init__(source) self.bzr_executable = common.which('bzr') def bzr_branch(self, **kwargs): @@ -32,7 +32,7 @@ def bzr_branch(self, **kwargs): stdout, stderr = cmd.communicate() if cmd.returncode != 0: raise BazaarError( - 'bzr branch for %r failed.\n%s' % (name, stderr)) + 'bzr branch for {!r} failed.\n{}'.format(name, stderr)) if kwargs.get('verbose', False): return stdout @@ -49,7 +49,7 @@ def bzr_pull(self, **kwargs): stdout, stderr = cmd.communicate() if cmd.returncode != 0: raise BazaarError( - 'bzr pull for %r failed.\n%s' % (name, stderr)) + 'bzr pull for {!r} failed.\n{}'.format(name, stderr)) if kwargs.get('verbose', False): return stdout @@ -81,7 +81,7 @@ def matches(self): stdout, stderr = cmd.communicate() if cmd.returncode != 0: raise BazaarError( - 'bzr info for %r failed.\n%s' % (name, stderr)) + 'bzr info for {!r} failed.\n{}'.format(name, stderr)) return (self.source['url'] in stdout.split()) def status(self, **kwargs): diff --git a/src/mr/developer/commands.py b/src/mr/developer/commands.py index ec70db31..fc2d1ae8 100644 --- a/src/mr/developer/commands.py +++ b/src/mr/developer/commands.py @@ -1,4 +1,3 @@ -from __future__ import print_function from mr.developer.common import logger, memoize, WorkingCopies, yesno import argparse import errno @@ -15,7 +14,7 @@ class ChoicesPseudoAction(argparse.Action): def __init__(self, *args, **kwargs): - sup = super(ChoicesPseudoAction, self) + sup = super() sup.__init__(dest=args[0], option_strings=list(args), help=kwargs.get('help'), nargs=0) @@ -36,11 +35,11 @@ def _fill_text(self, text, width, indent): result = [] for line in text.split("\n"): for line2 in textwrap.fill(line, width).split("\n"): - result.append("%s%s" % (indent, line2)) + result.append("{}{}".format(indent, line2)) return "\n".join(result) -class Command(object): +class Command: def __init__(self, develop): self.develop = develop @@ -71,7 +70,7 @@ def get_packages(self, args, auto_checkout=False, if len(result) == 0: if len(args) > 1: - regexps = "%s or '%s'" % (", ".join("'%s'" % x for x in args[:-1]), args[-1]) + regexps = "{} or '{}'".format(", ".join("'%s'" % x for x in args[:-1]), args[-1]) else: regexps = "'%s'" % args[0] logger.error("No package matched %s." % regexps) @@ -302,7 +301,7 @@ def __call__(self, args): for name in sorted(cmds): cmd = cmds[name] if len(cmd['aliases']): - header = "%s (%s)" % (name, ", ".join(cmd['aliases'])) + header = "{} ({})".format(name, ", ".join(cmd['aliases'])) else: header = name print(header) @@ -319,7 +318,7 @@ def __call__(self, args): for name in sorted(cmds): cmd = cmds[name] if len(cmd['aliases']): - print(" %s (%s)" % (name, ", ".join(cmd['aliases']))) + print(" {} ({})".format(name, ", ".join(cmd['aliases']))) else: print(" %s" % name) @@ -464,7 +463,7 @@ def __call__(self, args): else: info.append("#") if args.long: - info.append("(%s) %s %s" % (source['kind'], name, source['url'])) + info.append("({}) {} {}".format(source['kind'], name, source['url'])) else: info.append(name) print(" ".join(info)) @@ -560,7 +559,7 @@ def __call__(self, args): need_force = False if source['kind'] != 'svn': need_force = True - logger.warn("The directory of package '%s' at '%s' might contain unrecoverable files and will not be removed without --force." % (name, path)) + logger.warn("The directory of package '{}' at '{}' might contain unrecoverable files and will not be removed without --force.".format(name, path)) if workingcopies.status(source) != 'clean': need_force = True logger.warn("The package '%s' is dirty and will not be removed without --force." % name) @@ -578,7 +577,7 @@ def __call__(self, args): if answer == 'all': force_all = True - logger.info("Removing package '%s' at '%s'." % (name, path)) + logger.info("Removing package '{}' at '{}'.".format(name, path)) if not args.dry_run: shutil.rmtree(source['path'], ignore_errors=False, @@ -756,7 +755,7 @@ def __call__(self, args): info.append(name) print(" ".join(info)) if args.verbose: - if six.PY3 and isinstance(output, six.binary_type): + if six.PY3 and isinstance(output, bytes): output = output.decode('utf8') output = output.strip() if output: diff --git a/src/mr/developer/common.py b/src/mr/developer/common.py index 08d7d499..5a907bf1 100644 --- a/src/mr/developer/common.py +++ b/src/mr/developer/common.py @@ -11,10 +11,7 @@ import six import sys import threading -if sys.version_info < (3, ): - from ConfigParser import RawConfigParser -else: - from configparser import RawConfigParser +from configparser import RawConfigParser logger = logging.getLogger("mr.developer") @@ -105,7 +102,7 @@ class WCError(Exception): """ A working copy error. """ -class BaseWorkingCopy(object): +class BaseWorkingCopy: def __init__(self, source): self._output = [] self.output = self._output.append @@ -193,7 +190,7 @@ def worker(working_copies, the_queue): lvl(msg) if kwargs.get('verbose', False) and output is not None and output.strip(): - if six.PY3 and isinstance(output, six.binary_type): + if six.PY3 and isinstance(output, bytes): output = output.decode('utf8') print(output) output_lock.release() @@ -244,7 +241,7 @@ def get_commands(): return commands.values() -class WorkingCopies(object): +class WorkingCopies: def __init__(self, sources, threads=5): self.sources = sources self.threads = threads @@ -479,7 +476,7 @@ def parse_buildout_args(args): return options, settings, args -class Rewrite(object): +class Rewrite: _matcher = re.compile(r"(?P