From b32ccbb66bb16965ecb8b4e266c4e45186636c1b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 29 Sep 2023 11:04:49 -0400 Subject: cleanup: Update codebase to expect Python 3.6 - Bump minimum version to Python 3.6. - Use f-strings in a lot of places. Change-Id: I2aa70197230fcec2eff8e7c8eb754f20c08075bb Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/389034 Tested-by: Jason R. Coombs Reviewed-by: Mike Frysinger Commit-Queue: Jason R. Coombs --- subcmds/__init__.py | 4 +--- subcmds/abandon.py | 4 ++-- subcmds/branches.py | 2 +- subcmds/checkout.py | 2 +- subcmds/diffmanifests.py | 24 ++++++------------------ subcmds/help.py | 2 +- subcmds/info.py | 2 +- subcmds/init.py | 2 +- subcmds/list.py | 2 +- subcmds/prune.py | 4 +--- subcmds/start.py | 2 +- subcmds/sync.py | 2 +- subcmds/version.py | 35 ++++++++++++++--------------------- 13 files changed, 32 insertions(+), 55 deletions(-) (limited to 'subcmds') diff --git a/subcmds/__init__.py b/subcmds/__init__.py index 965ad0bb..83ec8470 100644 --- a/subcmds/__init__.py +++ b/subcmds/__init__.py @@ -37,9 +37,7 @@ for py in os.listdir(my_dir): try: cmd = getattr(mod, clsn) except AttributeError: - raise SyntaxError( - "%s/%s does not define class %s" % (__name__, py, clsn) - ) + raise SyntaxError(f"{__name__}/{py} does not define class {clsn}") name = name.replace("_", "-") cmd.NAME = name diff --git a/subcmds/abandon.py b/subcmds/abandon.py index f6c0c66c..e280d69e 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py @@ -117,7 +117,7 @@ It is equivalent to "git branch -D ". all_projects, callback=_ProcessResults, output=Progress( - "Abandon %s" % (nb,), len(all_projects), quiet=opt.quiet + f"Abandon {nb}", len(all_projects), quiet=opt.quiet ), ) @@ -152,4 +152,4 @@ It is equivalent to "git branch -D ". _RelPath(p) for p in success[br] ) ) - print("%s%s| %s\n" % (br, " " * (width - len(br)), result)) + print(f"{br}{' ' * (width - len(br))}| {result}\n") diff --git a/subcmds/branches.py b/subcmds/branches.py index d9a190be..59b5cb28 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py @@ -174,7 +174,7 @@ is shown, then the branch appears in all projects. if _RelPath(p) not in have: paths.append(_RelPath(p)) - s = " %s %s" % (in_type, ", ".join(paths)) + s = f" {in_type} {', '.join(paths)}" if not i.IsSplitCurrent and (width + 7 + len(s) < 80): fmt = out.current if i.IsCurrent else fmt fmt(s) diff --git a/subcmds/checkout.py b/subcmds/checkout.py index ea48263e..379bfa18 100644 --- a/subcmds/checkout.py +++ b/subcmds/checkout.py @@ -96,7 +96,7 @@ The command is equivalent to: all_projects, callback=_ProcessResults, output=Progress( - "Checkout %s" % (nb,), len(all_projects), quiet=opt.quiet + f"Checkout {nb}", len(all_projects), quiet=opt.quiet ), ) diff --git a/subcmds/diffmanifests.py b/subcmds/diffmanifests.py index b446dbd8..88b697b6 100644 --- a/subcmds/diffmanifests.py +++ b/subcmds/diffmanifests.py @@ -87,25 +87,17 @@ synced and their revisions won't be found. def _printRawDiff(self, diff, pretty_format=None, local=False): _RelPath = lambda p: p.RelPath(local=local) for project in diff["added"]: - self.printText( - "A %s %s" % (_RelPath(project), project.revisionExpr) - ) + self.printText(f"A {_RelPath(project)} {project.revisionExpr}") self.out.nl() for project in diff["removed"]: - self.printText( - "R %s %s" % (_RelPath(project), project.revisionExpr) - ) + self.printText(f"R {_RelPath(project)} {project.revisionExpr}") self.out.nl() for project, otherProject in diff["changed"]: self.printText( - "C %s %s %s" - % ( - _RelPath(project), - project.revisionExpr, - otherProject.revisionExpr, - ) + f"C {_RelPath(project)} {project.revisionExpr} " + f"{otherProject.revisionExpr}" ) self.out.nl() self._printLogs( @@ -118,12 +110,8 @@ synced and their revisions won't be found. for project, otherProject in diff["unreachable"]: self.printText( - "U %s %s %s" - % ( - _RelPath(project), - project.revisionExpr, - otherProject.revisionExpr, - ) + f"U {_RelPath(project)} {project.revisionExpr} " + f"{otherProject.revisionExpr}" ) self.out.nl() diff --git a/subcmds/help.py b/subcmds/help.py index a839131b..80040711 100644 --- a/subcmds/help.py +++ b/subcmds/help.py @@ -150,7 +150,7 @@ Displays detailed usage information about a command. def _PrintAllCommandHelp(self): for name in sorted(all_commands): cmd = all_commands[name](manifest=self.manifest) - self._PrintCommandHelp(cmd, header_prefix="[%s] " % (name,)) + self._PrintCommandHelp(cmd, header_prefix=f"[{name}] ") def _Options(self, p): p.add_option( diff --git a/subcmds/info.py b/subcmds/info.py index c24682c7..f637600e 100644 --- a/subcmds/info.py +++ b/subcmds/info.py @@ -248,7 +248,7 @@ class Info(PagedCommand): for commit in commits: split = commit.split() - self.text("{0:38}{1} ".format("", "-")) + self.text(f"{'':38}{'-'} ") self.sha(split[0] + " ") self.text(" ".join(split[1:])) self.out.nl() diff --git a/subcmds/init.py b/subcmds/init.py index 9ac42d8e..44517877 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -215,7 +215,7 @@ to update the working directory files. if not opt.quiet: print() - print("Your identity is: %s <%s>" % (name, email)) + print(f"Your identity is: {name} <{email}>") print("is this correct [y/N]? ", end="", flush=True) a = sys.stdin.readline().strip().lower() if a in ("yes", "y", "t", "true"): diff --git a/subcmds/list.py b/subcmds/list.py index fba6a4dc..4338e1c9 100644 --- a/subcmds/list.py +++ b/subcmds/list.py @@ -131,7 +131,7 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. elif opt.path_only and not opt.name_only: lines.append("%s" % (_getpath(project))) else: - lines.append("%s : %s" % (_getpath(project), project.name)) + lines.append(f"{_getpath(project)} : {project.name}") if lines: lines.sort() diff --git a/subcmds/prune.py b/subcmds/prune.py index f18471f3..f99082a4 100644 --- a/subcmds/prune.py +++ b/subcmds/prune.py @@ -83,9 +83,7 @@ class Prune(PagedCommand): ) if not branch.base_exists: - print( - "(ignoring: tracking branch is gone: %s)" % (branch.base,) - ) + print(f"(ignoring: tracking branch is gone: {branch.base})") else: commits = branch.commits date = branch.date diff --git a/subcmds/start.py b/subcmds/start.py index fd177f9e..56008f42 100644 --- a/subcmds/start.py +++ b/subcmds/start.py @@ -130,7 +130,7 @@ revision specified in the manifest. all_projects, callback=_ProcessResults, output=Progress( - "Starting %s" % (nb,), len(all_projects), quiet=opt.quiet + f"Starting {nb}", len(all_projects), quiet=opt.quiet ), ) diff --git a/subcmds/sync.py b/subcmds/sync.py index a0a0be9a..02c1d3ae 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -1394,7 +1394,7 @@ later is required to fix a server side protocol bug. if username and password: manifest_server = manifest_server.replace( - "://", "://%s:%s@" % (username, password), 1 + "://", f"://{username}:{password}@", 1 ) transport = PersistentTransport(manifest_server) diff --git a/subcmds/version.py b/subcmds/version.py index 71a03608..5c817f17 100644 --- a/subcmds/version.py +++ b/subcmds/version.py @@ -42,35 +42,28 @@ class Version(Command, MirrorSafeCommand): # These might not be the same. Report them both. src_ver = RepoSourceVersion() rp_ver = rp.bare_git.describe(HEAD) - print("repo version %s" % rp_ver) - print(" (from %s)" % rem.url) - print(" (tracking %s)" % branch.merge) - print(" (%s)" % rp.bare_git.log("-1", "--format=%cD", HEAD)) + print(f"repo version {rp_ver}") + print(f" (from {rem.url})") + print(f" (tracking {branch.merge})") + print(f" ({rp.bare_git.log('-1', '--format=%cD', HEAD)})") if self.wrapper_path is not None: - print("repo launcher version %s" % self.wrapper_version) - print(" (from %s)" % self.wrapper_path) + print(f"repo launcher version {self.wrapper_version}") + print(f" (from {self.wrapper_path})") if src_ver != rp_ver: - print(" (currently at %s)" % src_ver) + print(f" (currently at {src_ver})") - print("repo User-Agent %s" % user_agent.repo) - print("git %s" % git.version_tuple().full) - print("git User-Agent %s" % user_agent.git) - print("Python %s" % sys.version) + print(f"repo User-Agent {user_agent.repo}") + print(f"git {git.version_tuple().full}") + print(f"git User-Agent {user_agent.git}") + print(f"Python {sys.version}") uname = platform.uname() if sys.version_info.major < 3: # Python 3 returns a named tuple, but Python 2 is simpler. print(uname) else: - print( - "OS %s %s (%s)" % (uname.system, uname.release, uname.version) - ) - print( - "CPU %s (%s)" - % ( - uname.machine, - uname.processor if uname.processor else "unknown", - ) - ) + print(f"OS {uname.system} {uname.release} ({uname.version})") + processor = uname.processor if uname.processor else "unknown" + print(f"CPU {uname.machine} ({processor})") print("Bug reports:", Wrapper().BUG_URL) -- cgit v1.2.3-54-g00ecf