Skip to content

Commit

Permalink
chore: refactor code quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
akshgpt7 committed Apr 2, 2021
1 parent 3720808 commit d6fc2e4
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 23 deletions.
12 changes: 12 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 0 additions & 2 deletions dulwich/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions dulwich/contrib/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion dulwich/contrib/test_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion dulwich/diff_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dulwich/greenthreads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion dulwich/lru_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion dulwich/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions dulwich/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -889,7 +889,6 @@ def do_commit( # noqa: C901
Returns:
New commit SHA1
"""
import time

c = Commit()
if tree is None:
Expand Down
8 changes: 4 additions & 4 deletions dulwich/tests/compat/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dulwich/tests/compat/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions dulwich/tests/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down Expand Up @@ -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):
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion dulwich/tests/test_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down

0 comments on commit d6fc2e4

Please sign in to comment.