support python 3.5, fix exceptions

This commit is contained in:
Connor Olding 2018-03-24 11:46:57 +01:00
parent 4b564e96ba
commit 05eeb6cbb5
6 changed files with 14 additions and 11 deletions

View file

@ -7,7 +7,7 @@ and checked for integrity by SHA-256 hashes.
### dependencies ### dependencies
python 3.6 (or later), numpy. python 3.5 (or later), numpy.
### install ### install

6
TODO
View file

@ -4,8 +4,6 @@
* document prepare() function * document prepare() function
* support python 3.5
* adjust dates created/modified on server-hosted files to something sensible * adjust dates created/modified on server-hosted files to something sensible
* host files on a more reliable service * host files on a more reliable service
@ -14,6 +12,10 @@
* basic tests (including running pycodestyle) * basic tests (including running pycodestyle)
* --fix (delete corrupt files) and --debug (logging.DEBUG) __main__ arguments
* try python 3.2 with an old version of numpy (don't care if it doesn't work)
### release version 1.0 ### release version 1.0
* submit to pypi * submit to pypi

View file

@ -90,14 +90,15 @@ def validate(name):
if name not in hashes.keys(): if name not in hashes.keys():
raise UnknownDatasetError(name) raise UnknownDatasetError(name)
with open(construct_path(name), "rb") as f: path = construct_path(name)
with open(path, "rb") as f:
data = f.read() data = f.read()
known_hash = hashes[name] known_hash = hashes[name]
hash = hashlib.sha256(data).hexdigest() hash = hashlib.sha256(data).hexdigest()
if hash != known_hash: if hash != known_hash:
raise IntegrityError(file, known_hash, hash) raise IntegrityError(path, known_hash, hash)
def onehot(ind): def onehot(ind):

View file

@ -31,7 +31,7 @@ for name in metadata.keys():
# print out the shape table for use in the README. # print out the shape table for use in the README.
data = prepare(name) data = prepare(name)
prefix = metadata[name][0] prefix = metadata[name][0]
row_data = [f"[{prefix}][]"] row_data = ["[{}][]".format(prefix)]
row_data += [name.replace("_", "\\_")] row_data += [name.replace("_", "\\_")]
row_data += [str(array.shape) for array in data] row_data += [str(array.shape) for array in data]
print(row.format(*row_data)) print(row.format(*row_data))
@ -39,4 +39,4 @@ for name in metadata.keys():
print() print()
for anchor, url in urls.items(): for anchor, url in urls.items():
print(f"[{anchor}]: {url}") print("[{}]: {}".format(anchor, url))

View file

@ -5,9 +5,9 @@ class IntegrityError(Exception):
self.computed_hash = computed_hash self.computed_hash = computed_hash
def __str__(self): def __str__(self):
return f"""Failed to validate dataset: {name} return """Failed to validate dataset: {self.file}
Hash mismatch: {self.computed_hash} should be {self.expected_hash} Hash mismatch: {self.computed_hash} should be {self.expected_hash}
Please check your local file for tampering or corruption.""" Please check your local file for tampering or corruption.""".format(self=self)
class UnknownDatasetError(Exception): class UnknownDatasetError(Exception):
@ -15,4 +15,4 @@ class UnknownDatasetError(Exception):
self.dataset = dataset self.dataset = dataset
def __str__(self): def __str__(self):
return f"Unknown mnist-like dataset: {dataset}" return "Unknown mnist-like dataset: {self.dataset}".format(self=self)

View file

@ -22,7 +22,7 @@ setup(
'Natural Language :: English', 'Natural Language :: English',
'Programming Language :: Python', 'Programming Language :: Python',
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.5',
'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering',
] ]
) )