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 --- manifest_xml.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'manifest_xml.py') diff --git a/manifest_xml.py b/manifest_xml.py index 97baed57..61b130cf 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -114,9 +114,7 @@ def XmlInt(node, attr, default=None): try: return int(value) except ValueError: - raise ManifestParseError( - 'manifest: invalid %s="%s" integer' % (attr, value) - ) + raise ManifestParseError(f'manifest: invalid {attr}="{value}" integer') class _Default: @@ -810,7 +808,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md ret.setdefault(child.nodeName, []).append(element) else: raise ManifestParseError( - 'Unhandled element "%s"' % (child.nodeName,) + f'Unhandled element "{child.nodeName}"' ) append_children(element, child) @@ -1258,12 +1256,10 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md try: root = xml.dom.minidom.parse(path) except (OSError, xml.parsers.expat.ExpatError) as e: - raise ManifestParseError( - "error parsing manifest %s: %s" % (path, e) - ) + raise ManifestParseError(f"error parsing manifest {path}: {e}") if not root or not root.childNodes: - raise ManifestParseError("no root node in %s" % (path,)) + raise ManifestParseError(f"no root node in {path}") for manifest in root.childNodes: if ( @@ -1272,7 +1268,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md ): break else: - raise ManifestParseError("no in %s" % (path,)) + raise ManifestParseError(f"no in {path}") nodes = [] for node in manifest.childNodes: @@ -1282,7 +1278,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md msg = self._CheckLocalPath(name) if msg: raise ManifestInvalidPathError( - ' invalid "name": %s: %s' % (name, msg) + f' invalid "name": {name}: {msg}' ) include_groups = "" if parent_groups: @@ -1314,7 +1310,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md raise except Exception as e: raise ManifestParseError( - "failed parsing included manifest %s: %s" % (name, e) + f"failed parsing included manifest {name}: {e}" ) else: if parent_groups and node.nodeName == "project": @@ -1765,13 +1761,13 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md msg = self._CheckLocalPath(name) if msg: raise ManifestInvalidPathError( - ' invalid "name": %s: %s' % (name, msg) + f' invalid "name": {name}: {msg}' ) else: msg = self._CheckLocalPath(path) if msg: raise ManifestInvalidPathError( - ' invalid "path": %s: %s' % (path, msg) + f' invalid "path": {path}: {msg}' ) submanifest = _XmlSubmanifest( @@ -1806,7 +1802,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md msg = self._CheckLocalPath(name, dir_ok=True) if msg: raise ManifestInvalidPathError( - ' invalid "name": %s: %s' % (name, msg) + f' invalid "name": {name}: {msg}' ) if parent: name = self._JoinName(parent.name, name) @@ -1816,7 +1812,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md remote = self._default.remote if remote is None: raise ManifestParseError( - "no remote for project %s within %s" % (name, self.manifestFile) + f"no remote for project {name} within {self.manifestFile}" ) revisionExpr = node.getAttribute("revision") or remote.revision @@ -1837,7 +1833,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md msg = self._CheckLocalPath(path, dir_ok=True, cwd_dot_ok=True) if msg: raise ManifestInvalidPathError( - ' invalid "path": %s: %s' % (path, msg) + f' invalid "path": {path}: {msg}' ) rebase = XmlBool(node, "rebase", True) @@ -2094,7 +2090,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md if not cwd_dot_ok or parts != ["."]: for part in set(parts): if part in {".", "..", ".git"} or part.startswith(".repo"): - return "bad component: %s" % (part,) + return f"bad component: {part}" if not dir_ok and resep.match(path[-1]): return "dirs not allowed" @@ -2130,7 +2126,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md msg = cls._CheckLocalPath(dest) if msg: raise ManifestInvalidPathError( - '<%s> invalid "dest": %s: %s' % (element, dest, msg) + f'<{element}> invalid "dest": {dest}: {msg}' ) # |src| is the file we read from or path we point to for symlinks. @@ -2141,7 +2137,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md ) if msg: raise ManifestInvalidPathError( - '<%s> invalid "src": %s: %s' % (element, src, msg) + f'<{element}> invalid "src": {src}: {msg}' ) def _ParseCopyFile(self, project, node): @@ -2185,7 +2181,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md v = self._remotes.get(name) if not v: raise ManifestParseError( - "remote %s not defined in %s" % (name, self.manifestFile) + f"remote {name} not defined in {self.manifestFile}" ) return v -- cgit v1.2.3-54-g00ecf