Skip to content

Commit

Permalink
Bump ruff (#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer authored Nov 28, 2024
2 parents 4de310b + 3a051fc commit 3ffb1fc
Show file tree
Hide file tree
Showing 30 changed files with 111 additions and 149 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.22.7 UNRELEASED

* Fix serializing of commits with empty commit messages.
(Castedo Ellerman, #1429)

0.22.6 2024-11-16

* ``ObjectStore.iter_prefix``: fix handling of missing
Expand Down
2 changes: 1 addition & 1 deletion dulwich/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def write_bundle(f, bundle) -> None:
elif version == 3:
f.write(b"# v3 git bundle\n")
else:
raise AssertionError("unknown version %d" % version)
raise AssertionError(f"unknown version {version}")
if version == 3:
for key, value in bundle.capabilities.items():
f.write(b"@" + key.encode("utf-8"))
Expand Down
4 changes: 2 additions & 2 deletions dulwich/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def run(self, args) -> None:
print(f"Object names checksum: {x.name()}")
print(f"Checksum: {sha_to_hex(x.get_stored_checksum())}")
x.check()
print("Length: %d" % len(x))
print(f"Length: {len(x)}")
for name in x:
try:
print(f"\t{x[name]}")
Expand Down Expand Up @@ -729,7 +729,7 @@ def run(self, args) -> None:
parser = optparse.OptionParser()
options, args = parser.parse_args(args)
for i, entry in porcelain.stash_list("."):
print("stash@{%d}: %s" % (i, entry.message.rstrip("\n")))
print("stash@{{{}}}: {}".format(i, entry.message.rstrip("\n")))


class cmd_stash_push(Command):
Expand Down
42 changes: 17 additions & 25 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def progress(x) -> None:
elif chan == SIDE_BAND_CHANNEL_PROGRESS:
progress(data)
else:
raise AssertionError("Invalid sideband channel %d" % chan)
raise AssertionError(f"Invalid sideband channel {chan}")
else:
while True:
data = proto.read(rbufsize)
Expand Down Expand Up @@ -1099,7 +1099,7 @@ def progress(x) -> None:
elif chan == SIDE_BAND_CHANNEL_PROGRESS:
progress(data)
else:
raise AssertionError("Invalid sideband channel %d" % chan)
raise AssertionError(f"Invalid sideband channel {chan}")
else:
if CAPABILITY_REPORT_STATUS in capabilities:
assert self._report_status_parser
Expand Down Expand Up @@ -1351,17 +1351,16 @@ def fetch_pack(
protocol_version is not None
and protocol_version not in GIT_PROTOCOL_VERSIONS
):
raise ValueError("unknown Git protocol version %d" % protocol_version)
raise ValueError(f"unknown Git protocol version {protocol_version}")
proto, can_read, stderr = self._connect(b"upload-pack", path, protocol_version)
server_protocol_version = negotiate_protocol_version(proto)
if server_protocol_version not in GIT_PROTOCOL_VERSIONS:
raise ValueError(
"unknown Git protocol version %d used by server"
% server_protocol_version
f"unknown Git protocol version {server_protocol_version} used by server"
)
if protocol_version and server_protocol_version > protocol_version:
raise ValueError(
"bad Git protocol version %d used by server" % server_protocol_version
f"bad Git protocol version {server_protocol_version} used by server"
)
self.protocol_version = server_protocol_version
with proto:
Expand Down Expand Up @@ -1462,17 +1461,16 @@ def get_refs(
protocol_version is not None
and protocol_version not in GIT_PROTOCOL_VERSIONS
):
raise ValueError("unknown Git protocol version %d" % protocol_version)
raise ValueError(f"unknown Git protocol version {protocol_version}")
proto, _, stderr = self._connect(b"upload-pack", path, protocol_version)
server_protocol_version = negotiate_protocol_version(proto)
if server_protocol_version not in GIT_PROTOCOL_VERSIONS:
raise ValueError(
"unknown Git protocol version %d used by server"
% server_protocol_version
f"unknown Git protocol version {server_protocol_version} used by server"
)
if protocol_version and server_protocol_version > protocol_version:
raise ValueError(
"bad Git protocol version %d used by server" % server_protocol_version
f"bad Git protocol version {server_protocol_version} used by server"
)
self.protocol_version = server_protocol_version
if self.protocol_version == 2:
Expand Down Expand Up @@ -1552,7 +1550,7 @@ def archive(
elif chan == SIDE_BAND_CHANNEL_FATAL:
write_error(data)
else:
raise AssertionError("Invalid sideband channel %d" % chan)
raise AssertionError(f"Invalid sideband channel {chan}")


class TCPGitClient(TraditionalGitClient):
Expand All @@ -1572,7 +1570,7 @@ def from_parsedurl(cls, parsedurl, **kwargs):
def get_url(self, path):
netloc = self._host
if self._port is not None and self._port != TCP_GIT_PORT:
netloc += ":%d" % self._port
netloc += f":{self._port}"
return urlunsplit(("git", netloc, path, "", ""))

def _connect(
Expand Down Expand Up @@ -2142,7 +2140,7 @@ def __init__(
def get_url(self, path):
netloc = self.host
if self.port is not None:
netloc += ":%d" % self.port
netloc += f":{self.port}"

if self.username is not None:
netloc = urlquote(self.username, "@/:") + "@" + netloc
Expand Down Expand Up @@ -2414,7 +2412,7 @@ def _discover_references(
protocol_version is not None
and protocol_version not in GIT_PROTOCOL_VERSIONS
):
raise ValueError("unknown Git protocol version %d" % protocol_version)
raise ValueError(f"unknown Git protocol version {protocol_version}")
assert base_url[-1] == "/"
tail = "info/refs"
headers = {"Accept": "*/*"}
Expand Down Expand Up @@ -2478,13 +2476,11 @@ def begin_protocol_v2(proto):
server_protocol_version = negotiate_protocol_version(proto)
if server_protocol_version not in GIT_PROTOCOL_VERSIONS:
raise ValueError(
"unknown Git protocol version %d used by server"
% server_protocol_version
f"unknown Git protocol version {server_protocol_version} used by server"
)
if protocol_version and server_protocol_version > protocol_version:
raise ValueError(
"bad Git protocol version %d used by server"
% server_protocol_version
f"bad Git protocol version {server_protocol_version} used by server"
)
self.protocol_version = server_protocol_version
if self.protocol_version == 2:
Expand All @@ -2508,13 +2504,11 @@ def begin_protocol_v2(proto):
server_protocol_version = negotiate_protocol_version(proto)
if server_protocol_version not in GIT_PROTOCOL_VERSIONS:
raise ValueError(
"unknown Git protocol version %d used by server"
% server_protocol_version
f"unknown Git protocol version {server_protocol_version} used by server"
)
if protocol_version and server_protocol_version > protocol_version:
raise ValueError(
"bad Git protocol version %d used by server"
% server_protocol_version
f"bad Git protocol version {server_protocol_version} used by server"
)
self.protocol_version = server_protocol_version
if self.protocol_version == 2:
Expand Down Expand Up @@ -2852,9 +2846,7 @@ def _http_request(self, url, headers=None, data=None):
if resp.status == 407:
raise HTTPProxyUnauthorized(resp.headers.get("Proxy-Authenticate"), url)
if resp.status != 200:
raise GitProtocolError(
"unexpected http resp %d for %s" % (resp.status, url)
)
raise GitProtocolError(f"unexpected http resp {resp.status} for {url}")

resp.content_type = resp.headers.get("Content-Type")
# Check if geturl() is available (urllib3 version >= 1.23)
Expand Down
5 changes: 2 additions & 3 deletions dulwich/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,11 @@ def _parse_string(value: bytes) -> bytes:
v = _ESCAPE_TABLE[value[i]]
except IndexError as exc:
raise ValueError(
"escape character in %r at %d before end of string" % (value, i)
f"escape character in {value!r} at {i} before end of string"
) from exc
except KeyError as exc:
raise ValueError(
"escape character followed by unknown character "
"%s at %d in %r" % (value[i], i, value)
f"escape character followed by unknown character {value[i]!r} at {i} in {value!r}"
) from exc
if whitespace:
ret.extend(whitespace)
Expand Down
4 changes: 1 addition & 3 deletions dulwich/contrib/requests_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def _http_request(self, url, headers=None, data=None, allow_compression=False):
if resp.status_code == 407:
raise HTTPProxyUnauthorized(resp.headers.get("Proxy-Authenticate"), url)
if resp.status_code != 200:
raise GitProtocolError(
"unexpected http resp %d for %s" % (resp.status_code, url)
)
raise GitProtocolError(f"unexpected http resp {resp.status_code} for {url}")

# Add required fields as stated in AbstractHttpGitClient._http_request
resp.content_type = resp.headers.get("Content-Type")
Expand Down
2 changes: 1 addition & 1 deletion dulwich/contrib/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def next(self):
if sha in self._tagged:
self.add_todo([(self._tagged[sha], None, True)])
self.sha_done.add(sha)
self.progress("counting objects: %d\r" % len(self.sha_done))
self.progress(f"counting objects: {len(self.sha_done)}\r")
return (sha, name)


Expand Down
10 changes: 5 additions & 5 deletions dulwich/diff_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def walk_trees(store, tree1_id, tree2_id, prune_identical=False):
"""
# This could be fairly easily generalized to >2 trees if we find a use
# case.
mode1 = tree1_id and stat.S_IFDIR or None
mode2 = tree2_id and stat.S_IFDIR or None
mode1 = (tree1_id and stat.S_IFDIR) or None
mode2 = (tree2_id and stat.S_IFDIR) or None
todo = [(TreeEntry(b"", mode1, tree1_id), TreeEntry(b"", mode2, tree2_id))]
while todo:
entry1, entry2 = todo.pop()
Expand All @@ -149,8 +149,8 @@ def walk_trees(store, tree1_id, tree2_id, prune_identical=False):
if prune_identical and is_tree1 and is_tree2 and entry1 == entry2:
continue

tree1 = is_tree1 and store[entry1.sha] or None
tree2 = is_tree2 and store[entry2.sha] or None
tree1 = (is_tree1 and store[entry1.sha]) or None
tree2 = (is_tree2 and store[entry2.sha]) or None
path = entry1.path or entry2.path
todo.extend(reversed(_merge_entries(path, tree1, tree2)))
yield entry1, entry2
Expand Down Expand Up @@ -520,7 +520,7 @@ def _find_exact_renames(self) -> None:
if is_delete:
delete_paths.add(old.path)
add_paths.add(new.path)
new_type = is_delete and CHANGE_RENAME or CHANGE_COPY
new_type = (is_delete and CHANGE_RENAME) or CHANGE_COPY
self._changes.append(TreeChange(new_type, old, new))

num_extra_adds = len(sha_adds) - len(sha_deletes)
Expand Down
2 changes: 1 addition & 1 deletion dulwich/fastexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def print_cmd(self, cmd) -> None:

def _allocate_marker(self):
self._marker_idx += 1
return ("%d" % (self._marker_idx,)).encode("ascii")
return str(self._marker_idx).encode("ascii")

def _export_blob(self, blob):
marker = self._allocate_marker()
Expand Down
2 changes: 1 addition & 1 deletion dulwich/greenthreads.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ def collect_tree_sha(sha) -> None:
self.progress = lambda x: None
else:
self.progress = progress
self._tagged = get_tagged and get_tagged() or {}
self._tagged = (get_tagged and get_tagged()) or {}
8 changes: 2 additions & 6 deletions dulwich/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def execute(self, *args):
"""Execute the hook with given args."""
if len(args) != self.numparam:
raise HookError(
"Hook %s executed with wrong number of args. \
Expected %d. Saw %d. args: %s"
% (self.name, self.numparam, len(args), args)
f"Hook {self.name} executed with wrong number of args. Expected {self.numparam}. Saw {len(args)}. args: {args}"
)

if self.pre_exec_callback is not None:
Expand All @@ -104,9 +102,7 @@ def execute(self, *args):
if ret != 0:
if self.post_exec_callback is not None:
self.post_exec_callback(0, *args)
raise HookError(
"Hook %s exited with non-zero status %d" % (self.name, ret)
)
raise HookError(f"Hook {self.name} exited with non-zero status {ret}")
if self.post_exec_callback is not None:
return self.post_exec_callback(1, *args)
except OSError: # no file. silent failure.
Expand Down
2 changes: 1 addition & 1 deletion dulwich/lru_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class _LRUNode(Generic[K, V]):
"""This maintains the linked-list which is the lru internals."""

__slots__ = ("prev", "next_key", "key", "value", "cleanup", "size")
__slots__ = ("cleanup", "key", "next_key", "prev", "size", "value")

prev: Optional["_LRUNode[K, V]"]
next_key: K
Expand Down
14 changes: 4 additions & 10 deletions dulwich/object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,9 +897,7 @@ def _complete_pack(self, f, path, num_objects, indexer, progress=None):
entries = []
for i, entry in enumerate(indexer):
if progress is not None:
progress(
("generating index: %d/%d\r" % (i, num_objects)).encode("ascii")
)
progress(f"generating index: {i}/{num_objects}\r".encode("ascii"))
entries.append(entry)

pack_sha, extra_entries = extend_pack(
Expand Down Expand Up @@ -1366,7 +1364,7 @@ def __init__(
self.progress = lambda x: None
else:
self.progress = progress
self._tagged = get_tagged and get_tagged() or {}
self._tagged = (get_tagged and get_tagged()) or {}

def get_remote_has(self):
return self.remote_has
Expand All @@ -1380,9 +1378,7 @@ def __next__(self) -> tuple[bytes, Optional[PackHint]]:
while True:
if not self.objects_to_send:
self.progress(
("counting objects: %d, done.\n" % len(self.sha_done)).encode(
"ascii"
)
f"counting objects: {len(self.sha_done)}, done.\n".encode("ascii")
)
raise StopIteration
(sha, name, type_num, leaf) = self.objects_to_send.pop()
Expand Down Expand Up @@ -1411,9 +1407,7 @@ def __next__(self) -> tuple[bytes, Optional[PackHint]]:
self.add_todo([(self._tagged[sha], None, None, True)])
self.sha_done.add(sha)
if len(self.sha_done) % 1000 == 0:
self.progress(
("counting objects: %d\r" % len(self.sha_done)).encode("ascii")
)
self.progress(f"counting objects: {len(self.sha_done)}\r".encode("ascii"))
if type_num is None:
pack_hint = None
else:
Expand Down
Loading

0 comments on commit 3ffb1fc

Please sign in to comment.