Skip to content

Commit 90be376

Browse files
authored
Merge pull request #8 from dw/quality-control
Quality control (flake8, Travis CI, and coveralls)
2 parents e929b6b + a95abc1 commit 90be376

File tree

7 files changed

+54
-16
lines changed

7 files changed

+54
-16
lines changed

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
sudo: false
2+
3+
language: "python"
4+
5+
python:
6+
- "2.7"
7+
- "3.4"
8+
- "3.5"
9+
- "3.6"
10+
- "3.7-dev"
11+
12+
install:
13+
- "pip install ."
14+
- "pip install -U coveralls flake8"
15+
16+
script:
17+
- "coverage run --include='cdblib/*.py' setup.py test"
18+
- "flake8 ."
19+
20+
notifications:
21+
- email: false
22+
23+
after_success:
24+
- "coveralls"

cdblib/cdblib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def putstring(self, key, value, encoding='utf-8'):
215215
def putstrings(self, key, values, encoding='utf-8'):
216216
'''Write zero or more unicode strings to the output file. Equivalent to
217217
calling putstring() in a loop.'''
218-
self.puts(key, (six.text_type.encode(value, encoding) for value in values))
218+
self.puts(key, (six.text_type.encode(v, encoding) for v in values))
219219

220220
def finalize(self):
221221
'''Write the final hash tables to the output file, and write out its
@@ -238,7 +238,7 @@ def finalize(self):
238238
self.fp.seek(0)
239239
for pair in index:
240240
self.fp.write(self.write_pair(*pair))
241-
self.fp = None # prevent double finalize()
241+
self.fp = None # prevent double finalize()
242242

243243

244244
class Writer64(Writer):

cdblib/cdbmake.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, stdin, stdout, stderr):
3535
def parse_args(self, args):
3636
try:
3737
opts, args = getopt.gnu_getopt(args, 'p8')
38-
except getopt.error as e:
38+
except getopt.error as e:
3939
self.usage(str(e))
4040

4141
for opt, arg in opts:
@@ -67,11 +67,10 @@ def parse_input(self):
6767
elif plus != '+':
6868
self.die('bad or missing plus, line/record #%d', rec_nr)
6969

70-
bad = False
7170
try:
7271
klen = int(''.join(iter(partial(read, 1), ',')), 10)
7372
dlen = int(''.join(iter(partial(read, 1), ':')), 10)
74-
except ValueError as e:
73+
except ValueError:
7574
self.die('bad or missing length, line/record #%d', rec_nr)
7675

7776
key = read(klen)
@@ -118,4 +117,4 @@ def main(args=None, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr):
118117

119118

120119
if __name__ == '__main__':
121-
main(sys.argv[1:])
120+
main(sys.argv[1:])

cdblib/djb_hash.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
# iterating over byte strings differently.
88
if six.PY2:
99
def djb_hash(s):
10-
'''Return the value of DJB's hash function for the given byte string.'''
10+
'''Return the value of DJB's hash function for byte string *s*'''
1111
h = 5381
1212
for c in s:
1313
h = (((h << 5) + h) ^ ord(c)) & 0xffffffff
1414
return h
1515
else:
16-
def djb_hash(s):
17-
'''Return the value of DJB's hash function for the given byte string.'''
16+
def djb_hash(s): # noqa
17+
'''Return the value of DJB's hash function for byte string *s*'''
1818
h = 5381
1919
for c in s:
2020
h = (((h << 5) + h) ^ c) & 0xffffffff
2121
return h
2222

2323
# If the C Extensions is available (Python 2 only), use it
2424
try:
25-
from ._djb_hash import djb_hash
25+
from ._djb_hash import djb_hash # noqa
2626
except ImportError:
2727
pass

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
filename =
3+
./cdblib/*.py
4+
./setup.py

setup.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22
from os import environ
3-
from sys import version_info
43

54
from setuptools import Extension, find_packages, setup
65

@@ -13,20 +12,25 @@
1312
else:
1413
ext_modules = []
1514

15+
16+
description = "Pure Python reader/writer for Dan J. Berstein's CDB format."
17+
1618
setup(
1719
author='David Wilson',
1820
author_email='dw@botanicus.net',
19-
description="Pure Python reader/writer for Dan J. Berstein's CDB format.",
21+
description=description,
22+
long_description=description,
2023
download_url='https://github.com/dw/python-pure-cdb',
2124
keywords='cdb file format appengine database db',
2225
license='MIT',
2326
name='pure-cdb',
27+
version='2.1.0',
2428
packages=find_packages(include=['cdblib']),
2529
ext_modules=ext_modules,
2630
install_requires=['six>=1.0.0,<2.0.0'],
2731
test_suite='tests',
28-
version='2.1.0',
29-
entry_points = {
32+
tests_require=['flake8'],
33+
entry_points={
3034
'console_scripts': ['python-pure-cdbmake=cdblib.cdbmake:main'],
31-
}
35+
},
3236
)

tests/cdblib_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ def reader_to_cdbmake_md5(self, filename):
4040
data = infile.read()
4141

4242
for key, value in self.reader_cls(data).iteritems():
43-
md5.update(b'+%d,%d:%s->%s\n' % (len(key), len(value), key, value))
43+
# Hack to work around lack of bytes.format() in Python 3.4
44+
data = '+{},{}:{}->{}\n'.format(
45+
len(key),
46+
len(value),
47+
key.decode('utf-8'),
48+
value.decode('utf-8')
49+
)
50+
md5.update(data.encode('utf-8'))
4451

4552
md5.update(b'\n')
4653

0 commit comments

Comments
 (0)