@@ -1083,7 +1083,7 @@ def _initialize_bagit(self): # type: () -> None
1083
1083
bag_it_file .write ("BagIt-Version: 0.97\n " )
1084
1084
bag_it_file .write ("Tag-File-Character-Encoding: %s\n " % ENCODING )
1085
1085
1086
- def open_log_file_for_activity (self , uuid_uri : str ) -> WritableBagFile :
1086
+ def open_log_file_for_activity (self , uuid_uri : str ) -> Union [ TextIOWrapper , WritableBagFile ] :
1087
1087
self .self_check ()
1088
1088
# Ensure valid UUID for safe filenames
1089
1089
activity_uuid = uuid .UUID (uuid_uri )
@@ -1140,8 +1140,7 @@ def user_provenance(self, document): # type: (ProvDocument) -> None
1140
1140
# get their name wrong!)
1141
1141
document .actedOnBehalfOf (account , user )
1142
1142
1143
- def write_bag_file (self , path , encoding = ENCODING ):
1144
- # type: (str, Optional[str]) -> WritableBagFile
1143
+ def write_bag_file (self , path : str , encoding : Optional [str ]= ENCODING )-> Union [TextIOWrapper , WritableBagFile ]:
1145
1144
"""Write the bag file into our research object."""
1146
1145
self .self_check ()
1147
1146
# For some reason below throws BlockingIOError
@@ -1150,12 +1149,9 @@ def write_bag_file(self, path, encoding=ENCODING):
1150
1149
if encoding is not None :
1151
1150
# encoding: match Tag-File-Character-Encoding: UTF-8
1152
1151
# newline: ensure LF also on Windows
1153
- return cast (
1154
- WritableBagFile ,
1155
- TextIOWrapper (
1152
+ return TextIOWrapper (
1156
1153
cast (IO [bytes ], bag_file ), encoding = encoding , newline = "\n "
1157
- ),
1158
- )
1154
+ )
1159
1155
return bag_file
1160
1156
1161
1157
def add_tagfile (self , path , timestamp = None ):
@@ -1503,8 +1499,7 @@ def packed_workflow(self, packed): # type: (str) -> None
1503
1499
rel_path = str (PurePosixPath (WORKFLOW ) / "packed.cwl" )
1504
1500
# Write as binary
1505
1501
with self .write_bag_file (rel_path , encoding = None ) as write_pack :
1506
- # YAML is always UTF8, but json.dumps gives us str in py2
1507
- write_pack .write (packed .encode (ENCODING ))
1502
+ write_pack .write (packed )
1508
1503
_logger .debug ("[provenance] Added packed workflow: %s" , rel_path )
1509
1504
1510
1505
def has_data_file (self , sha1hash ): # type: (str) -> bool
@@ -1513,8 +1508,7 @@ def has_data_file(self, sha1hash): # type: (str) -> bool
1513
1508
hash_path = os .path .join (folder , sha1hash )
1514
1509
return os .path .isfile (hash_path )
1515
1510
1516
- def add_data_file (self , from_fp , timestamp = None , content_type = None ):
1517
- # type: (IO[Any], Optional[datetime.datetime], Optional[str]) -> str
1511
+ def add_data_file (self , from_fp : IO [Any ], timestamp : Optional [datetime .datetime ]= None , content_type : Optional [str ]= None ) -> str :
1518
1512
"""Copy inputs to data/ folder."""
1519
1513
self .self_check ()
1520
1514
tmp_dir , tmp_prefix = os .path .split (self .temp_prefix )
@@ -1554,17 +1548,15 @@ def add_data_file(self, from_fp, timestamp=None, content_type=None):
1554
1548
self ._content_types [rel_path ] = content_type
1555
1549
return rel_path
1556
1550
1557
- def _self_made (self , timestamp = None ):
1558
- # type: (Optional[datetime.datetime]) -> Dict[str, Any]
1551
+ def _self_made (self , timestamp : Optional [datetime .datetime ] = None ) -> Dict [str , Any ]:
1559
1552
if timestamp is None :
1560
1553
timestamp = datetime .datetime .now ()
1561
1554
return {
1562
1555
"createdOn" : timestamp .isoformat (),
1563
1556
"createdBy" : {"uri" : self .engine_uuid , "name" : self .cwltool_version },
1564
1557
}
1565
1558
1566
- def add_to_manifest (self , rel_path , checksums ):
1567
- # type: (str, Dict[str,str]) -> None
1559
+ def add_to_manifest (self , rel_path : str , checksums : Dict [str ,str ]) -> None :
1568
1560
"""Add files to the research object manifest."""
1569
1561
self .self_check ()
1570
1562
if PurePosixPath (rel_path ).is_absolute ():
@@ -1593,8 +1585,7 @@ def add_to_manifest(self, rel_path, checksums):
1593
1585
_logger .debug ("[provenance] Added to %s: %s" , manifestpath , line )
1594
1586
checksum_file .write (line )
1595
1587
1596
- def _add_to_bagit (self , rel_path , ** checksums ):
1597
- # type: (str, Any) -> None
1588
+ def _add_to_bagit (self , rel_path : str , ** checksums : str ) -> None :
1598
1589
if PurePosixPath (rel_path ).is_absolute ():
1599
1590
raise ValueError ("rel_path must be relative: %s" % rel_path )
1600
1591
local_path = os .path .join (self .folder , _local_path (rel_path ))
@@ -1714,8 +1705,7 @@ def _relativise_files(
1714
1705
except TypeError :
1715
1706
pass
1716
1707
1717
- def close (self , save_to = None ):
1718
- # type: (Optional[str]) -> None
1708
+ def close (self , save_to : Optional [str ]= None ) -> None :
1719
1709
"""Close the Research Object, optionally saving to specified folder.
1720
1710
1721
1711
Closing will remove any temporary files used by this research object.
@@ -1748,11 +1738,11 @@ def close(self, save_to=None):
1748
1738
1749
1739
1750
1740
def checksum_copy (
1751
- src_file , # type : IO[Any]
1752
- dst_file = None , # type : Optional[IO[Any]]
1753
- hasher = Hasher , # type: Callable[[], hashlib._Hash]
1754
- buffersize = 1024 * 1024 , # type: int
1755
- ): # type: (...) -> str
1741
+ src_file : IO [Any ],
1742
+ dst_file : Optional [IO [Any ]] = None ,
1743
+ hasher = Hasher , # type: Callable[[], hashlib._Hash]
1744
+ buffersize : int = 1024 * 1024 ,
1745
+ ) -> str :
1756
1746
"""Compute checksums while copying a file."""
1757
1747
# TODO: Use hashlib.new(Hasher_str) instead?
1758
1748
checksum = hasher ()
0 commit comments