Skip to content

Commit d7b933d

Browse files
committed
WIP: More flake8
1 parent 124126f commit d7b933d

27 files changed

+206
-228
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ 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+
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # stop the build if there are Python syntax errors or undefined names
51+
# flake8 . --count --max-complexity=10 --max-line-length=127 --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
5452

5553
- name: Install package
5654
shell: bash

h5pyd/_hl/folders.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import logging
1919
from .httpconn import HttpConn
2020
from .config import Config
21+
import sys
2122

2223

2324
class Folder:
@@ -199,6 +200,8 @@ def __init__(
199200

200201
connect_try = 0
201202

203+
print(f"\nMaking req = {req}\n")
204+
202205
while True:
203206
try:
204207
rsp = self._http_conn.GET(req)
@@ -210,22 +213,27 @@ def __init__(
210213
raise
211214
connect_try += 1
212215

216+
print(f"Entire rsp from initial folder get req: {rsp.status_code}")
217+
sys.stdout.flush()
218+
213219
if rsp.status_code in (404, 410) and mode in ("w", "w-", "x"):
214220
# create folder
215221
body = {"folder": True}
216222
if owner:
217223
body["owner"] = owner
224+
print(f"Attempting to PUT with req {req}")
218225
rsp = self._http_conn.PUT(req, body=body)
219226
if rsp.status_code != 201:
220227
self._http_conn.close()
221228
raise IOError(rsp.status_code, rsp.reason)
222229
elif rsp.status_code != 200:
223230
# folder must exist
224231
if rsp.status_code < 500:
225-
self.log.warning("status_code: {}".format(rsp.status_code))
232+
print("status_code: {}".format(rsp.status_code))
226233
else:
227-
self.log.error("status_code: {}".format(rsp.status_code))
234+
print("status_code: {}".format(rsp.status_code))
228235
raise IOError(rsp.status_code, rsp.reason)
236+
229237
domain_json = json.loads(rsp.text)
230238
self.log.info("domain_json: {}".format(domain_json))
231239
if "class" in domain_json:

h5pyd/_hl/serverinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def getServerInfo(endpoint=None, username=None, password=None, api_key=None, **k
5151
try:
5252
rsp = http_conn.GET("/about")
5353
break
54-
except IOError as ioe:
54+
except IOError:
5555
if connect_try < len(connect_backoff):
5656
time.sleep(connect_backoff[connect_try])
5757
else:

h5pyd/_hl/table.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
from __future__ import absolute_import
1414
import numpy
15-
from .base import _decode
15+
from .base import _decode
1616
from .base import bytesToArray
1717
from .dataset import Dataset
1818
from .objectid import DatasetID
1919
from . import selections as sel
2020
from .h5type import Reference
2121
from .h5type import check_dtype
22-
from .h5type import getQueryDtype
22+
from .h5type import getQueryDtype
2323

2424

2525
class Cursor():
@@ -64,17 +64,18 @@ def __iter__(self):
6464
if nrows - indx < read_count:
6565
read_count = nrows - indx
6666
if self._query is None:
67-
arr = self._table[indx+self._start:read_count+indx+self._start]
67+
arr = self._table[indx + self._start:read_count + indx + self._start]
6868
else:
6969
# call table to return query result
7070
if query_complete:
7171
arr = None # nothing more to fetch
7272
else:
73-
arr = self._table.read_where(self._query, start=indx+self._start, limit=read_count)
73+
arr = self._table.read_where(self._query, start=indx + self._start, limit=read_count)
7474
if arr is not None and arr.shape[0] < read_count:
7575
query_complete = True # we've gotten all the rows
76-
if arr is not None and indx%self._buffer_rows < arr.shape[0]:
77-
yield arr[indx%self._buffer_rows]
76+
if arr is not None and indx % self._buffer_rows < arr.shape[0]:
77+
yield arr[indx % self._buffer_rows]
78+
7879

7980
class Table(Dataset):
8081

@@ -95,7 +96,6 @@ def __init__(self, bind):
9596
if len(self._shape) > 1:
9697
raise ValueError("Table must be one-dimensional")
9798

98-
9999
@property
100100
def colnames(self):
101101
"""Numpy-style attribute giving the number of dimensions"""
@@ -118,7 +118,7 @@ def read(self, start=None, stop=None, step=None, field=None, out=None):
118118
step = 1
119119
arr = self[start:stop:step]
120120
if field is not None:
121-
#TBD - read just the field once the service supports it
121+
# TBD - read just the field once the service supports it
122122
tmp = arr[field]
123123
arr = tmp
124124
if out is not None:
@@ -127,12 +127,12 @@ def read(self, start=None, stop=None, step=None, field=None, out=None):
127127
else:
128128
return arr
129129

130-
131-
132-
def read_where(self, condition, condvars=None, field=None, start=None, stop=None, step=None, limit=0, include_index=True):
130+
def read_where(self, condition, condvars=None, field=None,
131+
start=None, stop=None, step=None, limit=0, include_index=True):
133132
"""Read rows from table using pytable-style condition
134133
"""
135134
names = () # todo
135+
136136
def readtime_dtype(basetype, names):
137137
""" Make a NumPy dtype appropriate for reading """
138138

@@ -143,7 +143,7 @@ def readtime_dtype(basetype, names):
143143
raise ValueError("Field names only allowed for compound types")
144144

145145
for name in names: # Check all names are legal
146-
if not name in basetype.names:
146+
if name not in basetype.names:
147147
raise ValueError("Field %s does not appear in this type." % name)
148148

149149
return numpy.dtype([(name, basetype.fields[name][0]) for name in names])
@@ -158,7 +158,6 @@ def readtime_dtype(basetype, names):
158158
# todo - will need the following once we have binary transfers
159159
# mtype = h5t.py_create(new_dtype)
160160
rsp_type = getQueryDtype(mtype)
161-
162161

163162
# Perform the dataspace selection
164163
if start or stop:
@@ -190,7 +189,7 @@ def readtime_dtype(basetype, names):
190189
if limit > 0:
191190
params["Limit"] = limit - total_rows
192191
self.log.info("req - cursor: {} page_size: {}".format(cursor, page_size))
193-
end_row = cursor+page_size
192+
end_row = cursor + page_size
194193
if end_row > stop:
195194
end_row = stop
196195
selection_arg = slice(cursor, end_row)
@@ -205,8 +204,8 @@ def readtime_dtype(basetype, names):
205204
rsp = self.GET(req, params=params)
206205
if isinstance(rsp, bytes):
207206
# binary response
208-
arr = bytesToArray(rsp, rsp_type, None)
209-
count = len(arr)
207+
arr = bytesToArray(rsp, rsp_type, None)
208+
count = len(arr)
210209
self.log.info(f"got {count} rows binary data")
211210
else:
212211
values = rsp["value"]
@@ -229,7 +228,7 @@ def readtime_dtype(basetype, names):
229228
else:
230229
e = values[i]
231230
arr[i] = tuple(e)
232-
231+
233232
self.log.info("got {} rows".format(count))
234233
total_rows += count
235234
data.append(arr)
@@ -263,14 +262,13 @@ def readtime_dtype(basetype, names):
263262
start = 0
264263
for arr in data:
265264
nrows = len(arr)
266-
ret_arr[start:(start+nrows)] = arr[:]
265+
ret_arr[start:(start + nrows)] = arr[:]
267266
start += nrows
268267
else:
269268
ret_arr = data[0]
270269

271270
return ret_arr
272271

273-
274272
def update_where(self, condition, value, start=None, stop=None, step=None, limit=None):
275273
"""Modify rows in table using pytable-style condition
276274
"""
@@ -317,13 +315,11 @@ def update_where(self, condition, value, start=None, stop=None, step=None, limit
317315

318316
return arr
319317

320-
def create_cursor(self, condition=None, start=None, stop=None):
318+
def create_cursor(self, condition=None, start=None, stop=None):
321319
"""Return a cursor for iteration
322320
"""
323321
return Cursor(self, query=condition, start=start, stop=stop)
324322

325-
326-
327323
def append(self, rows):
328324
""" Append rows to end of table
329325
"""
@@ -344,7 +340,7 @@ def append(self, rows):
344340
try:
345341
val_dtype = val.dtype
346342
except AttributeError:
347-
pass # not a numpy object, just leave dtype as None
343+
pass # not a numpy object, just leave dtype as None
348344

349345
if isinstance(val, Reference):
350346
# h5pyd References are just strings
@@ -400,7 +396,6 @@ def append(self, rows):
400396
params = {}
401397
body = {}
402398

403-
404399
format = "json"
405400

406401
if use_base64:

h5pyd/config.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import json
1414

15+
1516
class Config:
1617
"""
1718
User Config state
@@ -71,7 +72,7 @@ def __delitem__(self, name):
7172

7273
def __len__(self):
7374
return len(self._cfg)
74-
75+
7576
def __iter__(self):
7677
""" Iterate over config names """
7778
keys = self._cfg.keys()
@@ -86,11 +87,3 @@ def __repr__(self):
8687

8788
def keys(self):
8889
return self._cfg.keys()
89-
90-
91-
92-
93-
94-
95-
96-

h5pyd/h5ds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def is_attached(dsetid: DatasetID, dscaleid: DatasetID, idx: int) -> bool:
7272
dimlist = _getAttributeJson("DIMENSION_LIST", dsetid)
7373
reflist = _getAttributeJson("REFERENCE_LIST", dscaleid)
7474
try:
75-
return ([f"datasets/{dsetid.id}", idx] in reflist["value"] and
76-
f"datasets/{dscaleid.id}" in dimlist["value"][idx])
75+
return ([f"datasets/{dsetid.id}", idx] in
76+
reflist["value"] and f"datasets/{dscaleid.id}" in dimlist["value"][idx])
7777
except (KeyError, IndexError):
7878
return False

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"azure": [
4444
"msrestazure",
4545
"adal"
46-
],
46+
],
4747
"google": [
4848
"google-api-python-client",
4949
"google-auth-oauthlib",

test/apps/common.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_user1(self):
5050
# HS_USERNAME is the username h5pyd will look up if
5151
# if not provided in the File constructor
5252
user1 = {}
53-
if "HS_USERNAME" in os.environ:
53+
if "HS_USERNAME" in os.environ:
5454
user1["name"] = os.environ["HS_USERNAME"]
5555
else:
5656
user1["name"] = "test_user1"
@@ -64,7 +64,7 @@ def test_user1(self):
6464
@property
6565
def test_user2(self):
6666
user2 = {}
67-
if "TEST2_USERNAME" in os.environ:
67+
if "TEST2_USERNAME" in os.environ:
6868
user2["name"] = os.environ["TEST2_USERNAME"]
6969
else:
7070
user2["name"] = "test_user2"
@@ -86,22 +86,22 @@ def use_h5py():
8686
@classmethod
8787
def setUpClass(cls):
8888
pass
89-
#cls.tempdir = tempfile.mkdtemp(prefix='h5py-test_')
89+
# cls.tempdir = tempfile.mkdtemp(prefix='h5py-test_')
9090

9191
@classmethod
9292
def tearDownClass(cls):
9393
pass
94-
#shutil.rmtree(cls.tempdir)
94+
# shutil.rmtree(cls.tempdir)
9595

9696
def setUp(self):
9797
self.test_dir = str(int(time.time()))
98-
#self.f = h5py.File(self.mktemp(), 'w')
98+
# self.f = h5py.File(self.mktemp(), 'w')
9999

100100
def tearDown(self):
101101
try:
102102
if self.f:
103103
self.f.close()
104-
except:
104+
except Exception:
105105
pass
106106

107107
if not hasattr(ut.TestCase, 'assertSameElements'):
@@ -150,11 +150,11 @@ def assertArrayEqual(self, dset, arr, message=None, precision=None):
150150
self.assertTrue(
151151
dset.shape == arr.shape,
152152
"Shape mismatch (%s vs %s)%s" % (dset.shape, arr.shape, message)
153-
)
153+
)
154154
self.assertTrue(
155155
dset.dtype == arr.dtype,
156156
"Dtype mismatch (%s vs %s)%s" % (dset.dtype, arr.dtype, message)
157-
)
157+
)
158158

159159
if arr.dtype.names is not None:
160160
for n in arr.dtype.names:
@@ -164,12 +164,12 @@ def assertArrayEqual(self, dset, arr, message=None, precision=None):
164164
self.assertTrue(
165165
np.all(np.abs(dset[...] - arr[...]) < precision),
166166
"Arrays differ by more than %.3f%s" % (precision, message)
167-
)
167+
)
168168
else:
169169
self.assertTrue(
170170
np.all(dset[...] == arr[...]),
171171
"Arrays are not equal (dtype %s) %s" % (arr.dtype.str, message)
172-
)
172+
)
173173

174174
def assertNumpyBehavior(self, dset, arr, s):
175175
""" Apply slicing arguments "s" to both dset and arr.
@@ -210,7 +210,6 @@ def getFileName(self, basename):
210210
filename += ".h5"
211211
return filename
212212

213-
214213
def getPathFromDomain(self, domain):
215214
"""
216215
Convert DNS-style domain name to filepath
@@ -226,9 +225,7 @@ def getPathFromDomain(self, domain):
226225
path = '/'
227226
for name in names:
228227
if name:
229-
path += name
230-
path += '/'
228+
path += name
229+
path += '/'
231230
path = path[:-1] # strip trailing slash
232231
return path
233-
234-

0 commit comments

Comments
 (0)