diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 000000000..bb9f19a48 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,12 @@ +version = 1 + +test_patterns = ["dulwich/**test_*.py"] + +exclude_patterns = ["examples/**"] + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" \ No newline at end of file diff --git a/dulwich/cli.py b/dulwich/cli.py index 6e2c5fdd1..cf1074a39 100755 --- a/dulwich/cli.py +++ b/dulwich/cli.py @@ -388,7 +388,6 @@ def run(self, args): gitdir = args[0] else: gitdir = "." - from dulwich import porcelain porcelain.daemon(gitdir, address=options.listen_address, port=options.port) @@ -420,7 +419,6 @@ def run(self, args): gitdir = args[0] else: gitdir = "." - from dulwich import porcelain porcelain.web_daemon(gitdir, address=options.listen_address, port=options.port) diff --git a/dulwich/client.py b/dulwich/client.py index 6e32d4117..ca03f2512 100644 --- a/dulwich/client.py +++ b/dulwich/client.py @@ -954,7 +954,7 @@ def send_pack(self, path, update_refs, generate_pack_data, progress=None): proto.write_pkt_line(None) return SendPackResult(old_refs, agent=agent, ref_status={}) - if len(new_refs) == 0 and len(orig_new_refs): + if len(new_refs) == 0 and orig_new_refs: # NOOP - Original new refs filtered out by policy proto.write_pkt_line(None) if report_status_parser is not None: diff --git a/dulwich/contrib/swift.py b/dulwich/contrib/swift.py index b407ecfb1..3d76acbe7 100644 --- a/dulwich/contrib/swift.py +++ b/dulwich/contrib/swift.py @@ -121,7 +121,7 @@ class PackInfoObjectStoreIterator(GreenThreadsObjectStoreIterator): def __len__(self): - while len(self.finder.objects_to_send): + while self.finder.objects_to_send: for _ in range(0, len(self.finder.objects_to_send)): sha = self.finder.next() self._shas.append(sha) @@ -735,7 +735,7 @@ def commit(): f.seek(0) pack = PackData(file=f, filename="") entries = pack.sorted_entries() - if len(entries): + if entries: basename = posixpath.join( self.pack_dir, "pack-%s" % iter_sha1(entry[0] for entry in entries), diff --git a/dulwich/contrib/test_swift.py b/dulwich/contrib/test_swift.py index 35f6ba7ce..8c44edd64 100644 --- a/dulwich/contrib/test_swift.py +++ b/dulwich/contrib/test_swift.py @@ -403,7 +403,7 @@ def test_create_root_fails(self): "geventhttpclient.HTTPClient.request", lambda *args: Response(status=404), ): - self.assertRaises(swift.SwiftException, lambda: self.conn.create_root()) + self.assertRaises(swift.SwiftException, self.conn.create_root) def test_get_container_objects(self): with patch( diff --git a/dulwich/diff_tree.py b/dulwich/diff_tree.py index 2962575f4..6e53c52d9 100644 --- a/dulwich/diff_tree.py +++ b/dulwich/diff_tree.py @@ -591,7 +591,7 @@ def _join_modifies(self): return modifies = {} - delete_map = dict((d.old.path, d) for d in self._deletes) + delete_map = {d.old.path: d for d in self._deletes} for add in self._adds: path = add.new.path delete = delete_map.get(path) diff --git a/dulwich/greenthreads.py b/dulwich/greenthreads.py index 9ed490548..ec89e8f38 100644 --- a/dulwich/greenthreads.py +++ b/dulwich/greenthreads.py @@ -135,7 +135,7 @@ def __iter__(self): def __len__(self): if len(self._shas) > 0: return len(self._shas) - while len(self.finder.objects_to_send): + while self.finder.objects_to_send: jobs = [] for _ in range(0, len(self.finder.objects_to_send)): jobs.append(self.p.spawn(self.finder.next)) diff --git a/dulwich/lru_cache.py b/dulwich/lru_cache.py index 24b7c18f6..be18766f5 100644 --- a/dulwich/lru_cache.py +++ b/dulwich/lru_cache.py @@ -196,7 +196,7 @@ def keys(self): def items(self): """Get the key:value pairs as a dict.""" - return dict((k, n.value) for k, n in self._cache.items()) + return {k: n.value for k, n in self._cache.items()} def cleanup(self): """Clear the cache until it shrinks to the requested size. diff --git a/dulwich/protocol.py b/dulwich/protocol.py index 0c4cae1f5..9641d06f6 100644 --- a/dulwich/protocol.py +++ b/dulwich/protocol.py @@ -121,7 +121,7 @@ def capability_symref(from_ref, to_ref): def extract_capability_names(capabilities): - return set(parse_capability(c)[0] for c in capabilities) + return {parse_capability(c)[0] for c in capabilities} def parse_capability(capability): diff --git a/dulwich/repo.py b/dulwich/repo.py index 10012e86a..de446623a 100644 --- a/dulwich/repo.py +++ b/dulwich/repo.py @@ -684,7 +684,7 @@ def get_shallow(self): if f is None: return set() with f: - return set(line.strip() for line in f) + return {line.strip() for line in f} def update_shallow(self, new_shallow, new_unshallow): """Update the list of shallow objects. @@ -889,7 +889,6 @@ def do_commit( # noqa: C901 Returns: New commit SHA1 """ - import time c = Commit() if tree is None: diff --git a/dulwich/tests/compat/test_pack.py b/dulwich/tests/compat/test_pack.py index 8ae614f5d..6da2f0ff3 100644 --- a/dulwich/tests/compat/test_pack.py +++ b/dulwich/tests/compat/test_pack.py @@ -76,7 +76,7 @@ def test_copy(self): pack_path = os.path.join(self._tempdir, "Elch") write_pack(pack_path, origpack.pack_tuples()) output = run_git_or_fail(["verify-pack", "-v", pack_path]) - orig_shas = set(o.id for o in origpack.iterobjects()) + orig_shas = {o.id for o in origpack.iterobjects()} self.assertEqual(orig_shas, _git_verify_pack_object_list(output)) def test_deltas_work(self): @@ -89,7 +89,7 @@ def test_deltas_work(self): write_pack(pack_path, all_to_pack, deltify=True) output = run_git_or_fail(["verify-pack", "-v", pack_path]) self.assertEqual( - set(x[0].id for x in all_to_pack), + {x[0].id for x in all_to_pack}, _git_verify_pack_object_list(output), ) # We specifically made a new blob that should be a delta @@ -119,7 +119,7 @@ def test_delta_medium_object(self): write_pack(pack_path, all_to_pack, deltify=True) output = run_git_or_fail(["verify-pack", "-v", pack_path]) self.assertEqual( - set(x[0].id for x in all_to_pack), + {x[0].id for x in all_to_pack}, _git_verify_pack_object_list(output), ) # We specifically made a new blob that should be a delta @@ -158,7 +158,7 @@ def test_delta_large_object(self): write_pack(pack_path, all_to_pack, deltify=True) output = run_git_or_fail(["verify-pack", "-v", pack_path]) self.assertEqual( - set(x[0].id for x in all_to_pack), + {x[0].id for x in all_to_pack}, _git_verify_pack_object_list(output), ) # We specifically made a new blob that should be a delta diff --git a/dulwich/tests/compat/test_repository.py b/dulwich/tests/compat/test_repository.py index 828a03c05..e7fa282cf 100644 --- a/dulwich/tests/compat/test_repository.py +++ b/dulwich/tests/compat/test_repository.py @@ -63,7 +63,7 @@ def _parse_refs(self, output): return refs def _parse_objects(self, output): - return set(s.rstrip(b"\n").split(b" ")[0] for s in BytesIO(output)) + return {s.rstrip(b"\n").split(b" ")[0] for s in BytesIO(output)} def test_bare(self): self.assertTrue(self._repo.bare) diff --git a/dulwich/tests/test_pack.py b/dulwich/tests/test_pack.py index 54f3ebdc9..ded79b24a 100644 --- a/dulwich/tests/test_pack.py +++ b/dulwich/tests/test_pack.py @@ -308,7 +308,7 @@ def test_iterobjects(self): def test_iterentries(self): with self.get_pack_data(pack1_sha) as p: - entries = set((sha_to_hex(s), o, c) for s, o, c in p.iterentries()) + entries = {(sha_to_hex(s), o, c) for s, o, c in p.iterentries()} self.assertEqual( set( [ @@ -501,7 +501,7 @@ def test_length_mismatch(self): bad_pack = Pack.from_lazy_objects(lambda: bad_data, lambda: index) self.assertRaises(AssertionError, lambda: bad_pack.data) self.assertRaises( - AssertionError, lambda: bad_pack.check_length_and_checksum() + AssertionError, bad_pack.check_length_and_checksum ) def test_checksum_mismatch(self): @@ -515,12 +515,12 @@ def test_checksum_mismatch(self): bad_pack = Pack.from_lazy_objects(lambda: bad_data, lambda: index) self.assertRaises(ChecksumMismatch, lambda: bad_pack.data) self.assertRaises( - ChecksumMismatch, lambda: bad_pack.check_length_and_checksum() + ChecksumMismatch, bad_pack.check_length_and_checksum ) def test_iterobjects_2(self): with self.get_pack(pack1_sha) as p: - objs = dict((o.id, o) for o in p.iterobjects()) + objs = {o.id: o for o in p.iterobjects()} self.assertEqual(3, len(objs)) self.assertEqual(sorted(objs), sorted(p.index)) self.assertTrue(isinstance(objs[a_sha], Blob)) diff --git a/dulwich/tests/test_walk.py b/dulwich/tests/test_walk.py index 86a35ab46..d77ede05f 100644 --- a/dulwich/tests/test_walk.py +++ b/dulwich/tests/test_walk.py @@ -344,7 +344,7 @@ def test_follow_rename(self): blob = make_object(Blob, data=b"blob") names = [b"a", b"a", b"b", b"b", b"c", b"c"] - trees = dict((i + 1, [(n, blob, F)]) for i, n in enumerate(names)) + trees = {i + 1: [(n, blob, F)] for i, n in enumerate(names)} c1, c2, c3, c4, c5, c6 = self.make_linear_commits(6, trees=trees) self.assertWalkYields([c5], [c6.id], paths=[b"c"]) diff --git a/setup.py b/setup.py index e782c367b..7f49272b2 100755 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ def has_ext_modules(self): tests_require = ['fastimport'] -if '__pypy__' not in sys.modules and not sys.platform == 'win32': +if '__pypy__' not in sys.modules and sys.platform != 'win32': tests_require.extend([ 'gevent', 'geventhttpclient', 'setuptools>=17.1'])