Skip to content

Commit b79d1be

Browse files
committed
WIP: flake8 compliance
1 parent ba87916 commit b79d1be

16 files changed

+186
-220
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ jobs:
4444
python -m pip install flake8 pytest
4545
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
4646
47-
# - name: Lint with flake8
48-
# shell: bash
49-
# run: |
50-
# # stop the build if there are Python syntax errors or undefined names
51-
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
52-
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
53-
# flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
47+
- name: Lint with flake8
48+
shell: bash
49+
run: |
50+
# stop the build if there are Python syntax errors or undefined names
51+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
52+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
53+
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
5454
5555
- name: Install package
5656
shell: bash

h5pyd/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434

3535

3636
__doc__ = \
37-
"""
37+
"""
3838
This is the h5pyd package, a Python interface to the HDF REST Server.
3939
4040
Version %s
4141
42-
""" % (version.version)
42+
""" % (version.version)
4343

4444

4545
def enable_ipython_completer():

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
max-line-length = 120
33
# E402: module level import not at top of file
44
# C901: too complex
5-
ignore = E402, C901
5+
# F401: unused exports are necessary in __init__.py
6+
ignore = E402, C901, F401

test/hl/test_dataset_getitem.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@
6060
Update using new NULL dataset constructor once h5py 2.7 is out.
6161
"""
6262

63+
6364
class TestEmpty(TestCase):
6465

6566
def setUp(self):
6667
TestCase.setUp(self)
6768
filename = self.getFileName("dataset_testempty")
6869
print("filename:", filename)
6970
self.f = h5py.File(filename, 'w')
70-
self.dset = self.f.create_dataset('x',dtype='S10')
71+
self.dset = self.f.create_dataset('x', dtype='S10')
7172
self.empty_obj = h5py.Empty(np.dtype("S10"))
7273

7374
def test_ndim(self):
@@ -100,7 +101,7 @@ def test_slice(self):
100101
def test_multi_block_slice(self):
101102
""" MultiBlockSlice -> ValueError """
102103
""" TBD """
103-
#with self.assertRaises(ValueError):
104+
# with self.assertRaises(ValueError):
104105
# self.dset[h5py.MultiBlockSlice()]
105106

106107
def test_index(self):
@@ -111,7 +112,7 @@ def test_index(self):
111112
def test_indexlist(self):
112113
""" index list -> ValueError """
113114
with self.assertRaises(ValueError):
114-
self.dset[[1,2,5]]
115+
self.dset[[1, 2, 5]]
115116

116117
def test_mask(self):
117118
""" mask -> ValueError """
@@ -123,7 +124,7 @@ def test_fieldnames(self):
123124
""" field name -> ValueError """
124125
with self.assertRaises(ValueError):
125126
self.dset['field']
126-
127+
127128

128129
class TestScalarFloat(TestCase):
129130

@@ -175,7 +176,7 @@ def test_index(self):
175176
def test_indexlist(self):
176177
""" index list -> ValueError """
177178
with self.assertRaises(ValueError):
178-
self.dset[[1,2,5]]
179+
self.dset[[1, 2, 5]]
179180

180181
# FIXME: NumPy permits this
181182
def test_mask(self):
@@ -198,9 +199,9 @@ def setUp(self):
198199
print("filename:", filename)
199200
self.f = h5py.File(filename, 'w')
200201
self.data = np.array((42.5, -118, "Hello"), dtype=[('a', 'f'), ('b', 'i'), ('c', '|S10')])
201-
#self.dset = self.f.create_dataset('x', data=self.data)
202+
# self.dset = self.f.create_dataset('x', data=self.data)
202203
self.dset = self.f.create_dataset('x', (), dtype=[('a', 'f'), ('b', 'i'), ('c', '|S10')])
203-
self.dset[...] = (42.5, -118, "Hello")
204+
self.dset[...] = (42.5, -118, "Hello")
204205

205206
def test_ndim(self):
206207
""" Verify number of dimensions """
@@ -246,7 +247,7 @@ def test_index(self):
246247
def test_indexlist(self):
247248
""" index list -> ValueError """
248249
with self.assertRaises(ValueError):
249-
self.dset[[1,2,5]]
250+
self.dset[[1, 2, 5]]
250251

251252
# FIXME: NumPy permits this
252253
def test_mask(self):
@@ -259,13 +260,12 @@ def test_mask(self):
259260
@ut.skip
260261
def test_fieldnames(self):
261262
""" field name -> bare value """
262-
#TBD: fix when field access is supported in hsds
263+
# TBD: fix when field access is supported in hsds
263264
out = self.dset['a']
264265
self.assertIsInstance(out, np.float32)
265266
self.assertEqual(out, self.dset['a'])
266267

267268

268-
269269
class TestScalarArray(TestCase):
270270

271271
def setUp(self):
@@ -279,7 +279,7 @@ def setUp(self):
279279
try:
280280
self.dset[...] = self.data
281281
except (IOError, OSError) as oe:
282-
#TBD this is failing on HSDS
282+
# TBD this is failing on HSDS
283283
if not self.is_hsds():
284284
raise oe
285285

@@ -454,7 +454,7 @@ def test_index_outofrange(self):
454454
self.dset[100]
455455

456456
def test_indexlist_simple(self):
457-
self.assertNumpyBehavior(self.dset, self.data, np.s_[[1,2,5]])
457+
self.assertNumpyBehavior(self.dset, self.data, np.s_[[1, 2, 5]])
458458

459459
def test_indexlist_single_index_ellipsis(self):
460460
self.assertNumpyBehavior(self.dset, self.data, np.s_[[0], ...])
@@ -475,12 +475,12 @@ def test_indexlist_outofrange(self):
475475
def test_indexlist_nonmonotonic(self):
476476
""" we require index list values to be strictly increasing """
477477
with self.assertRaises(TypeError):
478-
self.dset[[1,3,2]]
478+
self.dset[[1, 3, 2]]
479479

480480
def test_indexlist_repeated(self):
481481
""" we forbid repeated index values """
482482
with self.assertRaises(TypeError):
483-
self.dset[[1,1,2]]
483+
self.dset[[1, 1, 2]]
484484

485485
def test_mask_true(self):
486486
self.assertNumpyBehavior(self.dset, self.data, np.s_[self.data > -100])
@@ -509,7 +509,7 @@ def setUp(self):
509509
filename = self.getFileName("dataset_test2dzerofloat")
510510
print("filename:", filename)
511511
self.f = h5py.File(filename, 'w')
512-
self.data = np.ones((0,3), dtype='f')
512+
self.data = np.ones((0, 3), dtype='f')
513513
self.dset = self.f.create_dataset('x', data=self.data)
514514

515515
def test_ndim(self):
@@ -521,7 +521,8 @@ def test_shape(self):
521521
self.assertEqual(self.dset.shape, (0, 3))
522522

523523
def test_indexlist(self):
524-
self.assertNumpyBehavior(self.dset, self.data, np.s_[:,[0,1,2]])
524+
self.assertNumpyBehavior(self.dset, self.data, np.s_[:, [0, 1, 2]])
525+
525526

526527
class Test2DFloat(TestCase):
527528

@@ -530,9 +531,9 @@ def setUp(self):
530531
filename = self.getFileName("dataset_test2dfloat")
531532
print("filename:", filename)
532533
self.f = h5py.File(filename, 'w')
533-
self.data = np.ones((5,3), dtype='f')
534+
self.data = np.ones((5, 3), dtype='f')
534535
self.dset = self.f.create_dataset('x', data=self.data)
535-
536+
536537
def test_ndim(self):
537538
""" Verify number of dimensions """
538539
self.assertEqual(self.dset.ndim, 2)
@@ -543,14 +544,14 @@ def test_size(self):
543544

544545
def test_nbytes(self):
545546
""" Verify nbytes """
546-
self.assertEqual(self.dset.nbytes, 15*self.data.dtype.itemsize)
547+
self.assertEqual(self.dset.nbytes, 15 * self.data.dtype.itemsize)
547548

548549
def test_shape(self):
549550
""" Verify shape """
550551
self.assertEqual(self.dset.shape, (5, 3))
551552

552553
def test_indexlist(self):
553-
self.assertNumpyBehavior(self.dset, self.data, np.s_[:,[0,1,2]])
554+
self.assertNumpyBehavior(self.dset, self.data, np.s_[:, [0, 1, 2]])
554555

555556
@ut.expectedFailure
556557
def test_index_emptylist(self):
@@ -559,18 +560,20 @@ def test_index_emptylist(self):
559560
# with h5py 3.2.1 at least
560561
self.assertNumpyBehavior(self.dset, self.data, np.s_[[]])
561562

563+
562564
class Test3DFloat(TestCase):
563565

564566
def setUp(self):
565567
TestCase.setUp(self)
566568
filename = self.getFileName("dataset_test3dfloat")
567569
print("filename:", filename)
568570
self.f = h5py.File(filename, 'w')
569-
self.data = np.ones((4,6,8), dtype='f')
571+
self.data = np.ones((4, 6, 8), dtype='f')
570572
self.dset = self.f.create_dataset('x', data=self.data, dtype='f')
571573

572574
def test_index_simple(self):
573-
self.assertNumpyBehavior(self.dset, self.data, np.s_[1,2:4,3:6])
575+
self.assertNumpyBehavior(self.dset, self.data, np.s_[1, 2:4, 3:6])
576+
574577

575578
class TestVeryLargeArray(TestCase):
576579

@@ -585,6 +588,7 @@ def setUp(self):
585588
def test_size(self):
586589
self.assertEqual(self.dset.size, 2**31)
587590

591+
588592
if __name__ == '__main__':
589593
loglevel = logging.ERROR
590594
logging.basicConfig(format='%(asctime)s %(message)s', level=loglevel)

test/hl/test_dataset_initializer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# request a copy from [email protected]. #
1111
##############################################################################
1212
import logging
13-
import numpy as np
1413

1514
import config
1615

@@ -21,8 +20,8 @@
2120

2221
from common import ut, TestCase
2322

24-
class TestDatasetInitializer(TestCase):
2523

24+
class TestDatasetInitializer(TestCase):
2625

2726
def test_create_arange_dset(self):
2827
filename = self.getFileName("create_arange_dset")
@@ -36,9 +35,9 @@ def test_create_arange_dset(self):
3635
start = 10
3736
step = 2
3837
dims = (extent,)
39-
initializer="arange"
38+
initializer = "arange"
4039
initializer_opts = [f"--start={start}", f"--step={step}"]
41-
kwargs = {"dtype": "i8", "initializer":initializer, "initializer_opts": initializer_opts}
40+
kwargs = {"dtype": "i8", "initializer": initializer, "initializer_opts": initializer_opts}
4241
dset = f.create_dataset('arange_dset', dims, **kwargs)
4342

4443
self.assertEqual(dset.name, "/arange_dset")
@@ -56,6 +55,7 @@ def test_create_arange_dset(self):
5655

5756
f.close()
5857

58+
5959
if __name__ == '__main__':
6060
loglevel = logging.ERROR
6161
logging.basicConfig(format='%(asctime)s %(message)s', level=loglevel)

test/hl/test_dataset_objref.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
class TestObjRef(TestCase):
2323

24-
2524
def test_create(self):
2625
filename = self.getFileName("objref_test")
2726
print(filename)
@@ -133,7 +132,6 @@ def test_create(self):
133132
self.assertEqual(obj.id.id, d1.id.id) # ref to d1
134133
self.assertEqual(obj.name, "/g2/d1")
135134

136-
137135
def test_delete(self):
138136
filename = self.getFileName("objref_delete_test")
139137
print(filename)
@@ -142,15 +140,15 @@ def test_delete(self):
142140
self.assertTrue('/' in f)
143141

144142
# create a dataset
145-
dset = f.create_dataset('dset', data=[1,2,3])
143+
dset = f.create_dataset('dset', data=[1, 2, 3])
146144
dset_ref = dset.ref
147145

148146
f.attrs["dset_ref"] = dset_ref
149147
del f['dset']
150148
try:
151149
f[dset_ref]
152150
except ValueError:
153-
pass # expected
151+
pass # expected
154152

155153
f.close()
156154

0 commit comments

Comments
 (0)