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 <jaraco@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Jason R. Coombs <jaraco@google.com>
This commit is contained in:
Jason R. Coombs
2023-09-29 11:04:49 -04:00
committed by LUCI
parent b99272c601
commit b32ccbb66b
33 changed files with 169 additions and 225 deletions

View File

@ -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

View File

@ -117,7 +117,7 @@ It is equivalent to "git branch -D <branchname>".
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 <branchname>".
_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")

View File

@ -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)

View File

@ -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
),
)

View File

@ -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()

View File

@ -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(

View File

@ -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()

View File

@ -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"):

View File

@ -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()

View File

@ -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

View File

@ -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
),
)

View File

@ -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)

View File

@ -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)