Skip to content

Commit

Permalink
Run ruff fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed May 10, 2023
1 parent b8b4e5f commit 574e529
Show file tree
Hide file tree
Showing 74 changed files with 1,072 additions and 621 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ coverage-html: coverage

apidocs:
pydoctor --intersphinx http://urllib3.readthedocs.org/en/latest/objects.inv --intersphinx http://docs.python.org/3/objects.inv --docformat=google dulwich --project-url=https://www.dulwich.io/ --project-name=dulwich

fix:
ruff check --fix .
6 changes: 2 additions & 4 deletions dulwich/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
# License, Version 2.0.
#

"""Generates tarballs for Git trees.
"""
"""Generates tarballs for Git trees."""

import posixpath
import stat
Expand All @@ -43,7 +41,7 @@ class ChunkedBytesIO:
list_of_bytestrings)
"""

def __init__(self, contents):
def __init__(self, contents) -> None:
self.contents = contents
self.pos = (0, 0)

Expand Down
5 changes: 2 additions & 3 deletions dulwich/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
# License, Version 2.0.
#

"""Bundle format support.
"""
"""Bundle format support."""

from typing import Dict, List, Optional, Sequence, Tuple, Union

Expand All @@ -35,7 +34,7 @@ class Bundle:
references: Dict[str, bytes] = {}
pack_data: Union[PackData, Sequence[bytes]] = []

def __repr__(self):
def __repr__(self) -> str:
return (f"<{type(self).__name__}(version={self.version}, "
f"capabilities={self.capabilities}, "
f"prerequisites={self.prerequisites}, "
Expand Down
2 changes: 1 addition & 1 deletion dulwich/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# License, Version 2.0.
#

"""Simple command-line interface to Dulwich>
"""Simple command-line interface to Dulwich>.
This is a very simple command-line wrapper for Dulwich. It is by
no means intended to be a full-blown Git command-line interface but just
Expand Down
128 changes: 82 additions & 46 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,20 @@
import sys
from contextlib import closing
from io import BufferedReader, BytesIO
from typing import (IO, TYPE_CHECKING, Any, Callable, Dict, Iterable, Iterator,
List, Optional, Set, Tuple, Union)
from typing import (
IO,
TYPE_CHECKING,
Any,
Callable,
Dict,
Iterable,
Iterator,
List,
Optional,
Set,
Tuple,
Union,
)
from urllib.parse import quote as urlquote
from urllib.parse import unquote as urlunquote
from urllib.parse import urljoin, urlparse, urlunparse, urlunsplit
Expand All @@ -59,23 +71,50 @@

from .config import Config, apply_instead_of, get_xdg_config_home_path
from .errors import GitProtocolError, NotGitRepository, SendPackError
from .pack import (PACK_SPOOL_FILE_MAX_SIZE, PackChunkGenerator,
UnpackedObject, write_pack_from_container)
from .protocol import (_RBUFSIZE, CAPABILITIES_REF, CAPABILITY_AGENT,
CAPABILITY_DELETE_REFS, CAPABILITY_INCLUDE_TAG,
CAPABILITY_MULTI_ACK, CAPABILITY_MULTI_ACK_DETAILED,
CAPABILITY_OFS_DELTA, CAPABILITY_QUIET,
CAPABILITY_REPORT_STATUS, CAPABILITY_SHALLOW,
CAPABILITY_SIDE_BAND_64K, CAPABILITY_SYMREF,
CAPABILITY_THIN_PACK, COMMAND_DEEPEN, COMMAND_DONE,
COMMAND_HAVE, COMMAND_SHALLOW, COMMAND_UNSHALLOW,
COMMAND_WANT, KNOWN_RECEIVE_CAPABILITIES,
KNOWN_UPLOAD_CAPABILITIES, SIDE_BAND_CHANNEL_DATA,
SIDE_BAND_CHANNEL_FATAL, SIDE_BAND_CHANNEL_PROGRESS,
TCP_GIT_PORT, ZERO_SHA, HangupException, PktLineParser,
Protocol, agent_string, capability_agent,
extract_capabilities, extract_capability_names,
parse_capability, pkt_line)
from .pack import (
PACK_SPOOL_FILE_MAX_SIZE,
PackChunkGenerator,
UnpackedObject,
write_pack_from_container,
)
from .protocol import (
_RBUFSIZE,
CAPABILITIES_REF,
CAPABILITY_AGENT,
CAPABILITY_DELETE_REFS,
CAPABILITY_INCLUDE_TAG,
CAPABILITY_MULTI_ACK,
CAPABILITY_MULTI_ACK_DETAILED,
CAPABILITY_OFS_DELTA,
CAPABILITY_QUIET,
CAPABILITY_REPORT_STATUS,
CAPABILITY_SHALLOW,
CAPABILITY_SIDE_BAND_64K,
CAPABILITY_SYMREF,
CAPABILITY_THIN_PACK,
COMMAND_DEEPEN,
COMMAND_DONE,
COMMAND_HAVE,
COMMAND_SHALLOW,
COMMAND_UNSHALLOW,
COMMAND_WANT,
KNOWN_RECEIVE_CAPABILITIES,
KNOWN_UPLOAD_CAPABILITIES,
SIDE_BAND_CHANNEL_DATA,
SIDE_BAND_CHANNEL_FATAL,
SIDE_BAND_CHANNEL_PROGRESS,
TCP_GIT_PORT,
ZERO_SHA,
HangupException,
PktLineParser,
Protocol,
agent_string,
capability_agent,
extract_capabilities,
extract_capability_names,
parse_capability,
pkt_line,
)
from .refs import PEELED_TAG_SUFFIX, _import_remote_refs, read_info_refs
from .repo import Repo

Expand All @@ -89,7 +128,7 @@
class InvalidWants(Exception):
"""Invalid wants."""

def __init__(self, wants):
def __init__(self, wants) -> None:
Exception.__init__(
self, "requested wants not in server provided refs: %r" % wants
)
Expand All @@ -98,7 +137,7 @@ def __init__(self, wants):
class HTTPUnauthorized(Exception):
"""Raised when authentication fails."""

def __init__(self, www_authenticate, url):
def __init__(self, www_authenticate, url) -> None:
Exception.__init__(self, "No valid credentials provided")
self.www_authenticate = www_authenticate
self.url = url
Expand All @@ -107,7 +146,7 @@ def __init__(self, www_authenticate, url):
class HTTPProxyUnauthorized(Exception):
"""Raised when proxy authentication fails."""

def __init__(self, proxy_authenticate, url):
def __init__(self, proxy_authenticate, url) -> None:
Exception.__init__(self, "No valid proxy credentials provided")
self.proxy_authenticate = proxy_authenticate
self.url = url
Expand Down Expand Up @@ -148,7 +187,7 @@ def _win32_peek_avail(handle):
class ReportStatusParser:
"""Handle status as reported by servers with 'report-status' capability."""

def __init__(self):
def __init__(self) -> None:
self._done = False
self._pack_status = None
self._ref_statuses = []
Expand Down Expand Up @@ -241,7 +280,7 @@ class FetchPackResult:
"viewvalues",
]

def __init__(self, refs, symrefs, agent, new_shallow=None, new_unshallow=None):
def __init__(self, refs, symrefs, agent, new_shallow=None, new_unshallow=None) -> None:
self.refs = refs
self.symrefs = symrefs
self.agent = agent
Expand All @@ -267,15 +306,15 @@ def __eq__(self, other):
and self.agent == other.agent
)

def __contains__(self, name):
def __contains__(self, name) -> bool:
self._warn_deprecated()
return name in self.refs

def __getitem__(self, name):
self._warn_deprecated()
return self.refs[name]

def __len__(self):
def __len__(self) -> int:
self._warn_deprecated()
return len(self.refs)

Expand All @@ -289,7 +328,7 @@ def __getattribute__(self, name):
return getattr(self.refs, name)
return super().__getattribute__(name)

def __repr__(self):
def __repr__(self) -> str:
return "{}({!r}, {!r}, {!r})".format(
self.__class__.__name__,
self.refs,
Expand Down Expand Up @@ -325,7 +364,7 @@ class SendPackResult:
"viewvalues",
]

def __init__(self, refs, agent=None, ref_status=None):
def __init__(self, refs, agent=None, ref_status=None) -> None:
self.refs = refs
self.agent = agent
self.ref_status = ref_status
Expand All @@ -345,15 +384,15 @@ def __eq__(self, other):
return self.refs == other
return self.refs == other.refs and self.agent == other.agent

def __contains__(self, name):
def __contains__(self, name) -> bool:
self._warn_deprecated()
return name in self.refs

def __getitem__(self, name):
self._warn_deprecated()
return self.refs[name]

def __len__(self):
def __len__(self) -> int:
self._warn_deprecated()
return len(self.refs)

Expand All @@ -367,7 +406,7 @@ def __getattribute__(self, name):
return getattr(self.refs, name)
return super().__getattribute__(name)

def __repr__(self):
def __repr__(self) -> str:
return "{}({!r}, {!r})".format(self.__class__.__name__, self.refs, self.agent)


Expand All @@ -387,7 +426,7 @@ def _read_shallow_updates(pkt_seq):

class _v1ReceivePackHeader:

def __init__(self, capabilities, old_refs, new_refs):
def __init__(self, capabilities, old_refs, new_refs) -> None:
self.want = []
self.have = []
self._it = self._handle_receive_pack_head(capabilities, old_refs, new_refs)
Expand Down Expand Up @@ -596,7 +635,7 @@ def __init__(
report_activity=None,
quiet=False,
include_tags=False,
):
) -> None:
"""Create a new GitClient instance.
Args:
Expand Down Expand Up @@ -924,8 +963,7 @@ def archive(
subdirs=None,
prefix=None,
):
"""Retrieve an archive of the specified tree.
"""
"""Retrieve an archive of the specified tree."""
raise NotImplementedError(self.archive)


Expand Down Expand Up @@ -961,7 +999,7 @@ class TraditionalGitClient(GitClient):

DEFAULT_ENCODING = "utf-8"

def __init__(self, path_encoding=DEFAULT_ENCODING, **kwargs):
def __init__(self, path_encoding=DEFAULT_ENCODING, **kwargs) -> None:
self._remote_path_encoding = path_encoding
super().__init__(**kwargs)

Expand Down Expand Up @@ -1203,7 +1241,7 @@ def archive(
class TCPGitClient(TraditionalGitClient):
"""A Git Client that works over TCP directly (i.e. git://)."""

def __init__(self, host, port=None, **kwargs):
def __init__(self, host, port=None, **kwargs) -> None:
if port is None:
port = TCP_GIT_PORT
self._host = host
Expand Down Expand Up @@ -1269,7 +1307,7 @@ def close():
class SubprocessWrapper:
"""A socket-like object that talks to a subprocess via pipes."""

def __init__(self, proc):
def __init__(self, proc) -> None:
self.proc = proc
self.read = BufferedReader(proc.stdout).read
self.write = proc.stdin.write
Expand Down Expand Up @@ -1350,7 +1388,7 @@ class LocalGitClient(GitClient):
"""Git Client that just uses a local Repo."""

def __init__(self, thin_packs=True, report_activity=None,
config: Optional[Config] = None):
config: Optional[Config] = None) -> None:
"""Create a new LocalGitClient instance.
Args:
Expand Down Expand Up @@ -1503,7 +1541,6 @@ def fetch_pack(

def get_refs(self, path):
"""Retrieve the current refs from a git smart server."""

with self._open_repo(path) as target:
return target.get_refs()

Expand Down Expand Up @@ -1548,7 +1585,7 @@ def run_command(
class StrangeHostname(Exception):
"""Refusing to connect to strange SSH hostname."""

def __init__(self, hostname):
def __init__(self, hostname) -> None:
super().__init__(hostname)


Expand Down Expand Up @@ -1682,7 +1719,7 @@ def __init__(
key_filename=None,
ssh_command=None,
**kwargs
):
) -> None:
self.host = host
self.port = port
self.username = username
Expand Down Expand Up @@ -1907,7 +1944,7 @@ class AbstractHttpGitClient(GitClient):
_http_request method.
"""

def __init__(self, base_url, dumb=False, **kwargs):
def __init__(self, base_url, dumb=False, **kwargs) -> None:
self._base_url = base_url.rstrip("/") + "/"
self.dumb = dumb
GitClient.__init__(self, **kwargs)
Expand All @@ -1927,7 +1964,6 @@ def _http_request(self, url, headers=None, data=None):
method for the response data.
"""

raise NotImplementedError(self._http_request)

def _discover_references(self, service, base_url):
Expand Down Expand Up @@ -2150,7 +2186,7 @@ def from_parsedurl(cls, parsedurl, **kwargs):
kwargs["username"] = urlunquote(username)
return cls(urlunparse(parsedurl), **kwargs)

def __repr__(self):
def __repr__(self) -> str:
return "{}({!r}, dumb={!r})".format(
type(self).__name__,
self._base_url,
Expand All @@ -2168,7 +2204,7 @@ def __init__(
username=None,
password=None,
**kwargs
):
) -> None:
self._username = username
self._password = password

Expand Down
Loading

0 comments on commit 574e529

Please sign in to comment.