diff --git a/pydra/engine/helpers.py b/pydra/engine/helpers.py index e5d185c9be..fc7867b8dd 100644 --- a/pydra/engine/helpers.py +++ b/pydra/engine/helpers.py @@ -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 """ @@ -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() \ No newline at end of file + return crypto_obj.hexdigest() diff --git a/pydra/engine/specs.py b/pydra/engine/specs.py index 3be288471a..52c4a81157 100644 --- a/pydra/engine/specs.py +++ b/pydra/engine/specs.py @@ -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"] } diff --git a/pydra/engine/tests/test_helpers.py b/pydra/engine/tests/test_helpers.py index 589022d8fd..a409ae51bf 100644 --- a/pydra/engine/tests/test_helpers.py +++ b/pydra/engine/tests/test_helpers.py @@ -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" + ) diff --git a/pydra/engine/tests/test_specs.py b/pydra/engine/tests/test_specs.py index 4b5918d7f7..fd03d3fbba 100644 --- a/pydra/engine/tests/test_specs.py +++ b/pydra/engine/tests/test_specs.py @@ -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" + )