Skip to content

Commit

Permalink
Let the class variable assignments are done by the class method, not …
Browse files Browse the repository at this point in the history
…the write_seq function.
  • Loading branch information
btasdelen authored and FrankZijlstra committed Jun 14, 2024
1 parent 33244ac commit 45f18a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 15 additions & 1 deletion pypulseq/Sequence/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1839,5 +1839,19 @@ def write(self, name: str, create_signature: bool = True, remove_duplicates: boo
Boolean flag to indicate if the file has to be signed.
remove_duplicates : bool, default=True
Remove duplicate events from the sequence before writing
Returns
-------
signature or None : If create_signature is True, it returns the written .seq file's signature as a string,
otherwise it returns None. Note that, if remove_duplicates is True, signature belongs to the
deduplicated sequences signature, and not the Sequence that is stored in the Sequence object.
"""
return write_seq(self, name, create_signature, remove_duplicates)
signature = write_seq(self, name, create_signature, remove_duplicates)

if signature is not None:
self.signature_type = "md5"
self.signature_file = "text"
self.signature_value = signature
return signature
else:
return None
9 changes: 6 additions & 3 deletions pypulseq/Sequence/write_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def write(self, file_name: Union[str, Path], create_signature, remove_duplicates
remove_duplicates : bool
Before writing, remove and remap events that would be duplicates after
the rounding done during writing
Returns
-------
md5 or None : If create_signature is True, it returns the written .seq file's signature as a string,
otherwise it returns None. Note that, if remove_duplicates is True, signature belongs to the
deduplicated sequences signature, and not the Sequence that is stored in the Sequence object.
Raises
------
Expand Down Expand Up @@ -258,9 +264,6 @@ def write(self, file_name: Union[str, Path], create_signature, remove_duplicates
buffer = output_file.read()

md5 = hashlib.md5(buffer.encode("utf-8")).hexdigest()
self.signature_type = "md5"
self.signature_file = "text"
self.signature_value = md5

# Write signature
with open(file_name, "a") as output_file:
Expand Down

0 comments on commit 45f18a8

Please sign in to comment.