Skip to content

Commit 74a1fda

Browse files
committed
Fixing coding style with the help of pep8 (wip)
1 parent c3335f9 commit 74a1fda

File tree

8 files changed

+30
-53
lines changed

8 files changed

+30
-53
lines changed

.pep8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pep8]
2+
exclude = .git,build,docs
3+
ignore =

setup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
from __future__ import print_function
3232

3333
import codecs
34-
import os
35-
from subprocess import Popen, PIPE
36-
import sys
3734
from distutils.core import setup, Extension, Command
3835
from distutils.command.build import build
3936
from distutils.command.sdist import sdist
4037
from distutils import log
38+
import os
39+
import shlex
40+
from subprocess import Popen, PIPE
41+
import sys
42+
import unittest
4143

4244
# Read version from local pygit2/version.py without pulling in
4345
# pygit2/__init__.py
@@ -85,11 +87,9 @@ def finalize_options(self):
8587
def run(self):
8688
self.run_command('build')
8789
bld = self.distribution.get_command_obj('build')
88-
#Add build_lib in to sys.path so that unittest can found DLLs and libs
90+
# Add build_lib in to sys.path so that unittest can found DLLs and libs
8991
sys.path = [os.path.abspath(bld.build_lib)] + sys.path
9092

91-
import shlex
92-
import unittest
9393
test_argv0 = [sys.argv[0] + ' test --args=']
9494
# For transfering args to unittest, we have to split args by ourself,
9595
# so that command like:

test/test_blob.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from __future__ import absolute_import
3131
from __future__ import unicode_literals
32-
import os
32+
from os.path import dirname, join
3333
import unittest
3434

3535
import pygit2
@@ -91,14 +91,14 @@ def test_create_blob_fromworkdir(self):
9191
self.assertEqual(len(BLOB_FILE_CONTENT), blob.size)
9292
self.assertEqual(BLOB_FILE_CONTENT, blob.read_raw())
9393

94-
def test_create_blob_outside_workdir(self):
9594

96-
path = os.path.join(os.path.dirname(__file__), 'data', self.repo_dir + '.tar')
95+
def test_create_blob_outside_workdir(self):
96+
path = join(dirname(__file__), 'data', self.repo_dir + '.tar')
9797
self.assertRaises(KeyError, self.repo.create_blob_fromworkdir, path)
9898

99-
def test_create_blob_fromdisk(self):
10099

101-
path = os.path.join(os.path.dirname(__file__), 'data', self.repo_dir + '.tar')
100+
def test_create_blob_fromdisk(self):
101+
path = join(dirname(__file__), 'data', self.repo_dir + '.tar')
102102
blob_oid = self.repo.create_blob_fromdisk(path)
103103
blob = self.repo[blob_oid]
104104

test/test_diff.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import unittest
3333
import pygit2
3434
from pygit2 import GIT_DIFF_INCLUDE_UNMODIFIED
35+
from pygit2 import GIT_DIFF_IGNORE_WHITESPACE, GIT_DIFF_IGNORE_WHITESPACE_EOL
3536
from . import utils
3637
from itertools import chain
3738

@@ -183,9 +184,9 @@ def test_diff_empty_tree(self):
183184
diff = commit_a.tree.diff_to_tree()
184185

185186
def get_context_for_lines(diff):
186-
hunks = chain(*map(lambda x: x.hunks, [p for p in diff]))
187-
lines = chain(*map(lambda x: x.lines, hunks))
188-
return map(lambda x: x[0], lines)
187+
hunks = chain(*map(lambda x: x.hunks, [p for p in diff]))
188+
lines = chain(*map(lambda x: x.lines, hunks))
189+
return map(lambda x: x[0], lines)
189190

190191
entries = [p.new_file_path for p in diff]
191192
self.assertAll(lambda x: commit_a.tree[x], entries)
@@ -204,8 +205,8 @@ def test_diff_tree_opts(self):
204205
commit_c = self.repo[COMMIT_SHA1_3]
205206
commit_d = self.repo[COMMIT_SHA1_4]
206207

207-
for flag in [pygit2.GIT_DIFF_IGNORE_WHITESPACE,
208-
pygit2.GIT_DIFF_IGNORE_WHITESPACE_EOL]:
208+
for flag in [GIT_DIFF_IGNORE_WHITESPACE,
209+
GIT_DIFF_IGNORE_WHITESPACE_EOL]:
209210
diff = commit_c.tree.diff_to_tree(commit_d.tree, flag)
210211
self.assertTrue(diff is not None)
211212
self.assertEqual(0, len(diff[0].hunks))
@@ -277,7 +278,7 @@ def test_find_similar(self):
277278
#~ Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate
278279
#~ --find-copies-harder during rename transformion...
279280
diff = commit_a.tree.diff_to_tree(commit_b.tree,
280-
GIT_DIFF_INCLUDE_UNMODIFIED)
281+
GIT_DIFF_INCLUDE_UNMODIFIED)
281282
self.assertAll(lambda x: x.status != 'R', diff)
282283
diff.find_similar()
283284
self.assertAny(lambda x: x.status == 'R', diff)

test/test_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_mode(self):
129129
def test_bare_index(self):
130130
index = pygit2.Index(os.path.join(self.repo.path, 'index'))
131131
self.assertEqual([x.hex for x in index],
132-
[x.hex for x in self.repo.index])
132+
[x.hex for x in self.repo.index])
133133

134134
self.assertRaises(pygit2.GitError, lambda: index.add('bye.txt'))
135135

test/test_refs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,27 @@ def test_create_reference(self):
180180

181181
# try to create existing reference with force
182182
reference = self.repo.create_reference('refs/tags/version1',
183-
LAST_COMMIT, force=True)
183+
LAST_COMMIT, force=True)
184184
self.assertEqual(reference.target.hex, LAST_COMMIT)
185185

186186

187187
def test_create_symbolic_reference(self):
188+
repo = self.repo
188189
# We add a tag as a new symbolic reference that always points to
189190
# "refs/heads/master"
190-
reference = self.repo.create_reference('refs/tags/beta',
191+
reference = repo.create_reference('refs/tags/beta',
191192
'refs/heads/master')
192193
self.assertEqual(reference.type, GIT_REF_SYMBOLIC)
193194
self.assertEqual(reference.target, 'refs/heads/master')
194195

195196

196197
# try to create existing symbolic reference
197-
self.assertRaises(ValueError, self.repo.create_reference,
198+
self.assertRaises(ValueError, repo.create_reference,
198199
'refs/tags/beta', 'refs/heads/master')
199200

200201
# try to create existing symbolic reference with force
201-
reference = self.repo.create_reference('refs/tags/beta',
202-
'refs/heads/master', force=True)
202+
reference = repo.create_reference('refs/tags/beta',
203+
'refs/heads/master', force=True)
203204
self.assertEqual(reference.type, GIT_REF_SYMBOLIC)
204205
self.assertEqual(reference.target, 'refs/heads/master')
205206

test/test_remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_remote_create(self):
4444
name = 'upstream'
4545
url = 'git://github.com/libgit2/pygit2.git'
4646

47-
remote = self.repo.create_remote(name, url);
47+
remote = self.repo.create_remote(name, url)
4848

4949
self.assertEqual(type(remote), pygit2.Remote)
5050
self.assertEqual(name, remote.name)
@@ -94,7 +94,7 @@ def test_remote_list(self):
9494

9595
name = 'upstream'
9696
url = 'git://github.com/libgit2/pygit2.git'
97-
remote = self.repo.create_remote(name, url);
97+
remote = self.repo.create_remote(name, url)
9898
self.assertTrue(remote.name in [x.name for x in self.repo.remotes])
9999

100100

test/test_status.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,6 @@
3535
from . import utils
3636

3737

38-
EXPECTED = {
39-
"current_file": pygit2.GIT_STATUS_CURRENT,
40-
"file_deleted": pygit2.GIT_STATUS_WT_DELETED,
41-
"modified_file": pygit2.GIT_STATUS_WT_MODIFIED,
42-
"new_file": pygit2.GIT_STATUS_WT_NEW,
43-
44-
"staged_changes": pygit2.GIT_STATUS_INDEX_MODIFIED,
45-
"staged_changes_file_deleted": pygit2.GIT_STATUS_INDEX_MODIFIED |
46-
pygit2.GIT_STATUS_WT_DELETED,
47-
"staged_changes_file_modified": pygit2.GIT_STATUS_INDEX_MODIFIED |
48-
pygit2.GIT_STATUS_WT_MODIFIED,
49-
50-
"staged_delete": pygit2.GIT_STATUS_INDEX_DELETED,
51-
"staged_delete_file_modified": pygit2.GIT_STATUS_INDEX_DELETED |
52-
pygit2.GIT_STATUS_WT_NEW,
53-
"staged_new": pygit2.GIT_STATUS_INDEX_NEW,
54-
55-
"staged_new_file_deleted": pygit2.GIT_STATUS_INDEX_NEW |
56-
pygit2.GIT_STATUS_WT_DELETED,
57-
"staged_new_file_modified": pygit2.GIT_STATUS_INDEX_NEW |
58-
pygit2.GIT_STATUS_WT_MODIFIED,
59-
60-
"subdir/current_file": pygit2.GIT_STATUS_CURRENT,
61-
"subdir/deleted_file": pygit2.GIT_STATUS_WT_DELETED,
62-
"subdir/modified_file": pygit2.GIT_STATUS_WT_MODIFIED,
63-
"subdir/new_file": pygit2.GIT_STATUS_WT_NEW,
64-
}
65-
6638
class StatusTest(utils.DirtyRepoTestCase):
6739

6840
def test_status(self):

0 commit comments

Comments
 (0)