diff --git a/dulwich/client.py b/dulwich/client.py index 0011d0225..ddbbb2608 100644 --- a/dulwich/client.py +++ b/dulwich/client.py @@ -172,8 +172,18 @@ def _win32_peek_avail(handle): COMMON_CAPABILITIES = [CAPABILITY_OFS_DELTA, CAPABILITY_SIDE_BAND_64K] -UPLOAD_CAPABILITIES = [CAPABILITY_THIN_PACK, CAPABILITY_MULTI_ACK, CAPABILITY_MULTI_ACK_DETAILED, CAPABILITY_SHALLOW, *COMMON_CAPABILITIES] -RECEIVE_CAPABILITIES = [CAPABILITY_REPORT_STATUS, CAPABILITY_DELETE_REFS, *COMMON_CAPABILITIES] +UPLOAD_CAPABILITIES = [ + CAPABILITY_THIN_PACK, + CAPABILITY_MULTI_ACK, + CAPABILITY_MULTI_ACK_DETAILED, + CAPABILITY_SHALLOW, + *COMMON_CAPABILITIES, +] +RECEIVE_CAPABILITIES = [ + CAPABILITY_REPORT_STATUS, + CAPABILITY_DELETE_REFS, + *COMMON_CAPABILITIES, +] class ReportStatusParser: @@ -888,9 +898,7 @@ def _negotiate_receive_pack_capabilities(self, server_capabilities): k, v = parse_capability(capability) if k == CAPABILITY_AGENT: agent = v - unknown_capabilities = ( # noqa: F841 - extract_capability_names(server_capabilities) - KNOWN_RECEIVE_CAPABILITIES - ) + (extract_capability_names(server_capabilities) - KNOWN_RECEIVE_CAPABILITIES) # TODO(jelmer): warn about unknown capabilities return negotiated_capabilities, agent @@ -940,9 +948,7 @@ def progress(x): return None def _negotiate_upload_pack_capabilities(self, server_capabilities): - unknown_capabilities = ( # noqa: F841 - extract_capability_names(server_capabilities) - KNOWN_UPLOAD_CAPABILITIES - ) + (extract_capability_names(server_capabilities) - KNOWN_UPLOAD_CAPABILITIES) # TODO(jelmer): warn about unknown capabilities symrefs = {} agent = None @@ -1018,7 +1024,7 @@ async def _connect(self, cmd, path): cmd: The git service name to which we should connect. path: The path we should pass to the service. (as bytestirng) """ - raise NotImplementedError() + raise NotImplementedError def send_pack(self, path, update_refs, generate_pack_data, progress=None): """Upload a pack to a remote repository. @@ -1618,6 +1624,7 @@ def run_command( if ssh_command: import shlex + args = [*shlex.split(ssh_command, posix=sys.platform != "win32"), "-x"] else: args = ["ssh", "-x"] @@ -1659,6 +1666,7 @@ def run_command( ): if ssh_command: import shlex + args = [*shlex.split(ssh_command, posix=sys.platform != "win32"), "-ssh"] elif sys.platform == "win32": args = ["plink.exe", "-ssh"] @@ -2268,7 +2276,7 @@ def _http_request(self, url, headers=None, data=None): raise GitProtocolError(str(e)) from e if resp.status == 404: - raise NotGitRepository() + raise NotGitRepository if resp.status == 401: raise HTTPUnauthorized(resp.headers.get("WWW-Authenticate"), url) if resp.status == 407: diff --git a/dulwich/config.py b/dulwich/config.py index 57af89915..19f35ce31 100644 --- a/dulwich/config.py +++ b/dulwich/config.py @@ -364,11 +364,9 @@ def sections(self) -> Iterator[Section]: def _format_string(value: bytes) -> bytes: if ( - value.startswith(b" ") - or value.startswith(b"\t") - or value.endswith(b" ") + value.startswith((b" ", b"\t")) + or value.endswith((b" ", b"\t")) or b"#" in value - or value.endswith(b"\t") ): return b'"' + _escape_value(value) + b'"' else: diff --git a/dulwich/contrib/requests_vendor.py b/dulwich/contrib/requests_vendor.py index bd3e0767d..89012677c 100644 --- a/dulwich/contrib/requests_vendor.py +++ b/dulwich/contrib/requests_vendor.py @@ -72,7 +72,7 @@ def _http_request(self, url, headers=None, data=None, allow_compression=False): resp = self.session.get(url, headers=req_headers) if resp.status_code == 404: - raise NotGitRepository() + raise NotGitRepository if resp.status_code == 401: raise HTTPUnauthorized(resp.headers.get("WWW-Authenticate"), url) if resp.status_code == 407: diff --git a/dulwich/contrib/swift.py b/dulwich/contrib/swift.py index 9280bd026..588e4e244 100644 --- a/dulwich/contrib/swift.py +++ b/dulwich/contrib/swift.py @@ -305,7 +305,9 @@ def swift_auth_v2(self): o_store for o_store in catalogs if o_store["type"] == "object-store" ) endpoints = object_store["endpoints"] - endpoint = next(endp for endp in endpoints if endp["region"] == self.region_name) + endpoint = next( + endp for endp in endpoints if endp["region"] == self.region_name + ) return endpoint[self.endpoint_type], token def test_root_exists(self): diff --git a/dulwich/contrib/test_release_robot.py b/dulwich/contrib/test_release_robot.py index 1f8756f4c..7e8ed261b 100644 --- a/dulwich/contrib/test_release_robot.py +++ b/dulwich/contrib/test_release_robot.py @@ -70,7 +70,9 @@ class GetRecentTagsTest(unittest.TestCase): test_repo = os.path.join(BASEDIR, "dulwich_test_repo.zip") committer = b"Mark Mikofski " test_tags: ClassVar[List[bytes]] = [b"v0.1a", b"v0.1"] - tag_test_data: ClassVar[Dict[bytes, Tuple[int, bytes, Optional[Tuple[int, bytes]]]]] = { + tag_test_data: ClassVar[ + Dict[bytes, Tuple[int, bytes, Optional[Tuple[int, bytes]]]] + ] = { test_tags[0]: (1484788003, b"3" * 40, None), test_tags[1]: (1484788314, b"1" * 40, (1484788401, b"2" * 40)), } diff --git a/dulwich/contrib/test_swift.py b/dulwich/contrib/test_swift.py index ff1352138..32015c225 100644 --- a/dulwich/contrib/test_swift.py +++ b/dulwich/contrib/test_swift.py @@ -36,12 +36,12 @@ missing_libs = [] try: - import gevent # noqa:F401 + import gevent # noqa: F401 except ModuleNotFoundError: missing_libs.append("gevent") try: - import geventhttpclient # noqa:F401 + import geventhttpclient # noqa: F401 except ModuleNotFoundError: missing_libs.append("geventhttpclient") @@ -170,7 +170,7 @@ def create_commit(data, marker=b"Default", blob=None): def create_commits(length=1, marker=b"Default"): data = [] - for i in range(0, length): + for i in range(length): _marker = (f"{marker}_{i}").encode() blob, tree, tag, cmt = create_commit(data, _marker) data.extend([blob, tree, tag, cmt]) diff --git a/dulwich/contrib/test_swift_smoke.py b/dulwich/contrib/test_swift_smoke.py index 3c520c62c..2a19f6df2 100644 --- a/dulwich/contrib/test_swift_smoke.py +++ b/dulwich/contrib/test_swift_smoke.py @@ -43,8 +43,8 @@ monkey.patch_all() -from dulwich import client, index, objects, repo, server # noqa:E402 -from dulwich.contrib import swift # noqa:E402 +from dulwich import client, index, objects, repo, server # noqa: E402 +from dulwich.contrib import swift # noqa: E402 class DulwichServer: diff --git a/dulwich/fastexport.py b/dulwich/fastexport.py index c5a367196..4263d0d96 100644 --- a/dulwich/fastexport.py +++ b/dulwich/fastexport.py @@ -148,7 +148,6 @@ def blob_handler(self, cmd): def checkpoint_handler(self, cmd): """Process a CheckpointCommand.""" - pass def commit_handler(self, cmd): """Process a CommitCommand.""" @@ -211,7 +210,6 @@ def commit_handler(self, cmd): def progress_handler(self, cmd): """Process a ProgressCommand.""" - pass def _reset_base(self, commit_id): if self.last_commit == commit_id: diff --git a/dulwich/hooks.py b/dulwich/hooks.py index 16a4b49a9..b1f56fc57 100644 --- a/dulwich/hooks.py +++ b/dulwich/hooks.py @@ -98,8 +98,8 @@ def execute(self, *args): try: ret = subprocess.call( - [os.path.relpath(self.filepath, self.cwd), *list(args)], - cwd=self.cwd) + [os.path.relpath(self.filepath, self.cwd), *list(args)], cwd=self.cwd + ) if ret != 0: if self.post_exec_callback is not None: self.post_exec_callback(0, *args) diff --git a/dulwich/index.py b/dulwich/index.py index 739f5c4f6..f7b9adbc7 100644 --- a/dulwich/index.py +++ b/dulwich/index.py @@ -481,14 +481,14 @@ def get_sha1(self, path: bytes) -> bytes: """Return the (git object) SHA1 for the object at a path.""" value = self[path] if isinstance(value, ConflictedIndexEntry): - raise UnmergedEntries() + raise UnmergedEntries return value.sha def get_mode(self, path: bytes) -> int: """Return the POSIX file mode for the object at a path.""" value = self[path] if isinstance(value, ConflictedIndexEntry): - raise UnmergedEntries() + raise UnmergedEntries return value.mode def iterobjects(self) -> Iterable[Tuple[bytes, bytes, int]]: @@ -496,7 +496,7 @@ def iterobjects(self) -> Iterable[Tuple[bytes, bytes, int]]: for path in self: entry = self[path] if isinstance(entry, ConflictedIndexEntry): - raise UnmergedEntries() + raise UnmergedEntries yield path, entry.sha, cleanup_mode(entry.mode) def has_conflicts(self) -> bool: diff --git a/dulwich/pack.py b/dulwich/pack.py index d7c042179..282117654 100644 --- a/dulwich/pack.py +++ b/dulwich/pack.py @@ -1914,7 +1914,9 @@ def pack_objects_to_data( return ( count, deltify_pack_objects( - iter(objects), window_size=delta_window_size, progress=progress # type: ignore + iter(objects), # type: ignore + window_size=delta_window_size, + progress=progress, ), ) else: diff --git a/dulwich/porcelain.py b/dulwich/porcelain.py index b15ef08e6..aa6ae410a 100644 --- a/dulwich/porcelain.py +++ b/dulwich/porcelain.py @@ -624,9 +624,7 @@ def clean(repo=".", target_dir=None): raise Error("target_dir must be in the repo's working dir") config = r.get_config_stack() - require_force = config.get_boolean( # noqa: F841 - (b"clean",), b"requireForce", True - ) + config.get_boolean((b"clean",), b"requireForce", True) # TODO(jelmer): if require_force is set, then make sure that -f, -i or # -n is specified. diff --git a/dulwich/protocol.py b/dulwich/protocol.py index 2725795e7..de2618779 100644 --- a/dulwich/protocol.py +++ b/dulwich/protocol.py @@ -77,10 +77,29 @@ CAPABILITY_NO_PROGRESS, ] KNOWN_UPLOAD_CAPABILITIES = set( - [*COMMON_CAPABILITIES, CAPABILITY_THIN_PACK, CAPABILITY_MULTI_ACK, CAPABILITY_MULTI_ACK_DETAILED, CAPABILITY_INCLUDE_TAG, CAPABILITY_DEEPEN_SINCE, CAPABILITY_SYMREF, CAPABILITY_SHALLOW, CAPABILITY_DEEPEN_NOT, CAPABILITY_DEEPEN_RELATIVE, CAPABILITY_ALLOW_TIP_SHA1_IN_WANT, CAPABILITY_ALLOW_REACHABLE_SHA1_IN_WANT] + [ + *COMMON_CAPABILITIES, + CAPABILITY_THIN_PACK, + CAPABILITY_MULTI_ACK, + CAPABILITY_MULTI_ACK_DETAILED, + CAPABILITY_INCLUDE_TAG, + CAPABILITY_DEEPEN_SINCE, + CAPABILITY_SYMREF, + CAPABILITY_SHALLOW, + CAPABILITY_DEEPEN_NOT, + CAPABILITY_DEEPEN_RELATIVE, + CAPABILITY_ALLOW_TIP_SHA1_IN_WANT, + CAPABILITY_ALLOW_REACHABLE_SHA1_IN_WANT, + ] ) KNOWN_RECEIVE_CAPABILITIES = set( - [*COMMON_CAPABILITIES, CAPABILITY_REPORT_STATUS, CAPABILITY_DELETE_REFS, CAPABILITY_QUIET, CAPABILITY_ATOMIC] + [ + *COMMON_CAPABILITIES, + CAPABILITY_REPORT_STATUS, + CAPABILITY_DELETE_REFS, + CAPABILITY_QUIET, + CAPABILITY_ATOMIC, + ] ) DEPTH_INFINITE = 0x7FFFFFFF @@ -193,7 +212,7 @@ def read_pkt_line(self): try: sizestr = read(4) if not sizestr: - raise HangupException() + raise HangupException size = int(sizestr, 16) if size == 0 or size == 1: # flush-pkt or delim-pkt if self.report_activity: @@ -203,7 +222,7 @@ def read_pkt_line(self): self.report_activity(size, "read") pkt_contents = read(size - 4) except ConnectionResetError as exc: - raise HangupException() from exc + raise HangupException from exc except OSError as exc: raise GitProtocolError(str(exc)) from exc else: diff --git a/dulwich/repo.py b/dulwich/repo.py index 745ba78d4..d87c93382 100644 --- a/dulwich/repo.py +++ b/dulwich/repo.py @@ -95,24 +95,24 @@ valid_hexsha, ) from .pack import generate_unpacked_objects -from .refs import ( # noqa: F401 - ANNOTATED_TAG_SUFFIX, +from .refs import ( + ANNOTATED_TAG_SUFFIX, # noqa: F401 LOCAL_BRANCH_PREFIX, - LOCAL_TAG_PREFIX, - SYMREF, + LOCAL_TAG_PREFIX, # noqa: F401 + SYMREF, # noqa: F401 DictRefsContainer, DiskRefsContainer, - InfoRefsContainer, + InfoRefsContainer, # noqa: F401 Ref, RefsContainer, _set_default_branch, _set_head, _set_origin_head, - check_ref_format, - read_packed_refs, - read_packed_refs_with_peeled, + check_ref_format, # noqa: F401 + read_packed_refs, # noqa: F401 + read_packed_refs_with_peeled, # noqa: F401 serialize_refs, - write_packed_refs, + write_packed_refs, # noqa: F401 ) CONTROLDIR = ".git" @@ -1366,7 +1366,7 @@ def open_index(self) -> "Index": from .index import Index if not self.has_index(): - raise NoIndexPresent() + raise NoIndexPresent return Index(self.index_path()) def has_index(self): @@ -1915,7 +1915,7 @@ def open_index(self): Raises: NoIndexPresent: Raised when no index is present """ - raise NoIndexPresent() + raise NoIndexPresent def get_config(self): """Retrieve the config object. diff --git a/dulwich/tests/__init__.py b/dulwich/tests/__init__.py index e9e5ffb92..7fe34f7a9 100644 --- a/dulwich/tests/__init__.py +++ b/dulwich/tests/__init__.py @@ -156,11 +156,6 @@ def self_test_suite(): def tutorial_test_suite(): - import dulwich.client - import dulwich.config - import dulwich.index - import dulwich.patch # noqa: F401 - tutorial = [ "introduction", "file-format", diff --git a/dulwich/tests/compat/test_client.py b/dulwich/tests/compat/test_client.py index 353813f4c..cdc7dd993 100644 --- a/dulwich/tests/compat/test_client.py +++ b/dulwich/tests/compat/test_client.py @@ -73,10 +73,10 @@ def assertDestEqualsSrc(self): self.assertReposEqual(src, dest) def _client(self): - raise NotImplementedError() + raise NotImplementedError def _build_path(self): - raise NotImplementedError() + raise NotImplementedError def _do_send_pack(self): c = self._client() diff --git a/dulwich/tests/compat/test_pack.py b/dulwich/tests/compat/test_pack.py index c75b07f90..993603a95 100644 --- a/dulwich/tests/compat/test_pack.py +++ b/dulwich/tests/compat/test_pack.py @@ -101,7 +101,11 @@ def test_delta_medium_object(self): new_blob.data = orig_blob.data + (b"x" * 2**20) new_blob_2 = Blob() new_blob_2.data = new_blob.data + b"y" - all_to_pack = [*list(orig_pack.pack_tuples()), (new_blob, None), (new_blob_2, None)] + all_to_pack = [ + *list(orig_pack.pack_tuples()), + (new_blob, None), + (new_blob_2, None), + ] pack_path = os.path.join(self._tempdir, "pack_with_deltas") write_pack(pack_path, all_to_pack, deltify=True) output = run_git_or_fail(["verify-pack", "-v", pack_path]) @@ -137,7 +141,11 @@ def test_delta_large_object(self): new_blob.data = "big blob" + ("x" * 2**25) new_blob_2 = Blob() new_blob_2.data = new_blob.data + "y" - all_to_pack = [*list(orig_pack.pack_tuples()), (new_blob, None), (new_blob_2, None)] + all_to_pack = [ + *list(orig_pack.pack_tuples()), + (new_blob, None), + (new_blob_2, None), + ] pack_path = os.path.join(self._tempdir, "pack_with_deltas") write_pack(pack_path, all_to_pack, deltify=True) output = run_git_or_fail(["verify-pack", "-v", pack_path]) diff --git a/dulwich/tests/test_client.py b/dulwich/tests/test_client.py index c92e69fec..6b79de15f 100644 --- a/dulwich/tests/test_client.py +++ b/dulwich/tests/test_client.py @@ -726,10 +726,10 @@ def run_command( class Subprocess: pass - setattr(Subprocess, "read", lambda: None) - setattr(Subprocess, "write", lambda: None) - setattr(Subprocess, "close", lambda: None) - setattr(Subprocess, "can_read", lambda: None) + Subprocess.read = lambda: None + Subprocess.write = lambda: None + Subprocess.close = lambda: None + Subprocess.can_read = lambda: None return Subprocess() @@ -1571,7 +1571,15 @@ def test_run_command_password_and_privkey(self): binary = ["plink.exe", "-ssh"] else: binary = ["plink", "-ssh"] - expected = [*binary, "-pw", "12345", "-i", "/tmp/id_rsa", "host", "git-clone-url"] + expected = [ + *binary, + "-pw", + "12345", + "-i", + "/tmp/id_rsa", + "host", + "git-clone-url", + ] self.assertListEqual(expected, args[0]) def test_run_command_password(self): @@ -1612,7 +1620,15 @@ def test_run_command_with_port_username_and_privkey(self): binary = ["plink.exe", "-ssh"] else: binary = ["plink", "-ssh"] - expected = [*binary, "-P", "2200", "-i", "/tmp/id_rsa", "user@host", "git-clone-url"] + expected = [ + *binary, + "-P", + "2200", + "-i", + "/tmp/id_rsa", + "user@host", + "git-clone-url", + ] vendor = PLinkSSHVendor() command = vendor.run_command( diff --git a/dulwich/tests/test_greenthreads.py b/dulwich/tests/test_greenthreads.py index d18c3d8a9..3581f2b53 100644 --- a/dulwich/tests/test_greenthreads.py +++ b/dulwich/tests/test_greenthreads.py @@ -56,7 +56,7 @@ def create_commit(marker=None): def init_store(store, count=1): ret = [] - for i in range(0, count): + for i in range(count): objs = create_commit(marker=("%d" % i).encode("ascii")) for obj in objs: ret.append(obj) diff --git a/dulwich/tests/test_porcelain.py b/dulwich/tests/test_porcelain.py index 5dbae9c57..a05ea8556 100644 --- a/dulwich/tests/test_porcelain.py +++ b/dulwich/tests/test_porcelain.py @@ -2088,11 +2088,15 @@ def test_simple(self): # Get the change in the target repo corresponding to the add # this will be in the foo branch. - change = next(iter(tree_changes( - self.repo, - self.repo[b"HEAD"].tree, - self.repo[b"refs/heads/foo"].tree, - ))) + change = next( + iter( + tree_changes( + self.repo, + self.repo[b"HEAD"].tree, + self.repo[b"refs/heads/foo"].tree, + ) + ) + ) self.assertEqual( os.path.basename(fullpath), change.new.path.decode("ascii") ) diff --git a/dulwich/tests/test_repository.py b/dulwich/tests/test_repository.py index cb55f4adc..a2d11802a 100644 --- a/dulwich/tests/test_repository.py +++ b/dulwich/tests/test_repository.py @@ -736,7 +736,8 @@ def test_shell_hook_pre_commit_add_files(self): r.stage(['foo']) """.format( executable=sys.executable, - path=[os.path.join(os.path.dirname(__file__), "..", ".."), *sys.path]) + path=[os.path.join(os.path.dirname(__file__), "..", ".."), *sys.path], + ) repo_dir = os.path.join(self.mkdtemp()) self.addCleanup(shutil.rmtree, repo_dir) diff --git a/dulwich/tests/test_server.py b/dulwich/tests/test_server.py index f285b10e5..ccbe09029 100644 --- a/dulwich/tests/test_server.py +++ b/dulwich/tests/test_server.py @@ -82,7 +82,7 @@ def read_pkt_line(self): # flush-pkt ('0000'). return None else: - raise HangupException() + raise HangupException def write_sideband(self, band, data): self._received[band].append(data) diff --git a/dulwich/tests/test_web.py b/dulwich/tests/test_web.py index 5791100d7..223537c9d 100644 --- a/dulwich/tests/test_web.py +++ b/dulwich/tests/test_web.py @@ -160,7 +160,7 @@ def __init__(self, exc_class) -> None: self._exc_class = exc_class def read(self, size=-1): - raise self._exc_class() + raise self._exc_class def close(self): self.closed = True diff --git a/dulwich/tests/utils.py b/dulwich/tests/utils.py index ca9ccb5f5..cdd235bea 100644 --- a/dulwich/tests/utils.py +++ b/dulwich/tests/utils.py @@ -29,7 +29,7 @@ import types import warnings -from dulwich.tests import SkipTest, skipIf # noqa: F401 +from dulwich.tests import SkipTest from ..index import commit_tree from ..objects import Commit, FixedSha, Tag, object_class @@ -100,8 +100,6 @@ class TestObject(cls): with a __dict__ instead of __slots__. """ - pass - TestObject.__name__ = "TestObject_" + cls.__name__ obj = TestObject() diff --git a/dulwich/web.py b/dulwich/web.py index 19da34ee7..076141611 100644 --- a/dulwich/web.py +++ b/dulwich/web.py @@ -393,7 +393,12 @@ class HTTPGitApplication: backend: the Backend object backing this application """ - services: ClassVar[Dict[Tuple[str, re.Pattern], Callable[[HTTPGitRequest, Backend, re.Match], Iterator[bytes]]]] = { + services: ClassVar[ + Dict[ + Tuple[str, re.Pattern], + Callable[[HTTPGitRequest, Backend, re.Match], Iterator[bytes]], + ] + ] = { ("GET", re.compile("/HEAD$")): get_text_file, ("GET", re.compile("/info/refs$")): get_info_refs, ("GET", re.compile("/objects/info/alternates$")): get_text_file, diff --git a/pyproject.toml b/pyproject.toml index 8bd3c7a72..e853ef457 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,7 +74,9 @@ select = [ "E", "F", "I", + "PIE", "UP", + "RSE", "RUF", ] ignore = [