Skip to content

Commit

Permalink
sty: black
Browse files Browse the repository at this point in the history
  • Loading branch information
satra committed Aug 5, 2019
1 parent 74a7de7 commit 02100b6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
7 changes: 3 additions & 4 deletions pydra/engine/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ def hash_function(obj):
return sha256(str(obj).encode()).hexdigest()


def hash_file(afile, chunk_len=8192, crypto=sha256,
raise_notfound=False):
def hash_file(afile, chunk_len=8192, crypto=sha256, raise_notfound=False):
"""
Computes hash of a file using 'crypto' module
"""
Expand All @@ -255,10 +254,10 @@ def hash_file(afile, chunk_len=8192, crypto=sha256,
return None

crypto_obj = crypto()
with open(afile, 'rb') as fp:
with open(afile, "rb") as fp:
while True:
data = fp.read(chunk_len)
if not data:
break
crypto_obj.update(data)
return crypto_obj.hexdigest()
return crypto_obj.hexdigest()
4 changes: 3 additions & 1 deletion pydra/engine/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def hash(self):
from .helpers import hash_function, hash_file

inp_dict = {
field.name: hash_file(getattr(self, field.name)) if field.type == File else getattr(self, field.name)
field.name: hash_file(getattr(self, field.name))
if field.type == File
else getattr(self, field.name)
for field in dc.fields(self)
if field.name not in ["_graph_checksums"]
}
Expand Down
9 changes: 6 additions & 3 deletions pydra/engine/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def test_create_pyscript(tmpdir):

def test_hash_file(tmpdir):
outdir = Path(tmpdir)
with open(outdir / 'test.file', 'wt') as fp:
fp.write('test')
assert helpers.hash_file(outdir / 'test.file') == '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
with open(outdir / "test.file", "wt") as fp:
fp.write("test")
assert (
helpers.hash_file(outdir / "test.file")
== "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
)
25 changes: 13 additions & 12 deletions pydra/engine/tests/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,20 @@ def test_lazy_getvale():

def test_file_hash(tmpdir):
tmpdir.chdir()
outfile = 'test.file'
outfile = "test.file"
fields = [("in_file", ty.Any)]
input_spec = SpecInfo(name="Inputs", fields=fields,
bases=(BaseSpec,))
input_spec = SpecInfo(name="Inputs", fields=fields, bases=(BaseSpec,))
inputs = make_klass(input_spec)
assert inputs(str(outfile)).hash == '1384a1eb11cd94a5b826a82b948313b9237a0956d406ccff59e79ec92b3c935f'
with open(outfile, 'wt') as fp:
fp.write('test')
assert (
inputs(str(outfile)).hash
== "1384a1eb11cd94a5b826a82b948313b9237a0956d406ccff59e79ec92b3c935f"
)
with open(outfile, "wt") as fp:
fp.write("test")
fields = [("in_file", File)]
input_spec = SpecInfo(name="Inputs", fields=fields,
bases=(BaseSpec,))
input_spec = SpecInfo(name="Inputs", fields=fields, bases=(BaseSpec,))
inputs = make_klass(input_spec)
assert inputs(outfile).hash == '088625131e6718a00170ad445a9c295244dffd4e5d847c8ee4b1606d623dacb1'



assert (
inputs(outfile).hash
== "088625131e6718a00170ad445a9c295244dffd4e5d847c8ee4b1606d623dacb1"
)

0 comments on commit 02100b6

Please sign in to comment.