@@ -888,30 +888,6 @@ def hash_files(
888888 file_hashes [str (path )] = crypto_obj .hexdigest ()
889889 return file_hashes
890890
891- def __bytes_repr__ (
892- self , cache : ty .Dict [ty .Any , str ] # pylint: disable=unused-argument
893- ) -> ty .Iterable [bytes ]:
894- """Provided for compatibility with Pydra's hashing function, return the contents
895- of all the files in the file-set in chunks
896-
897- Parameters
898- ----------
899- cache : dict[Any, str]
900- an object passed around by Pydra's hashing function to store cached versions
901- of previously hashed objects, to allow recursive structures
902-
903- Yields
904- ------
905- bytes
906- a chunk of bytes of length FILE_CHUNK_LEN_DEFAULT from the contents of all
907- files in the file-set.
908- """
909- cls = type (self )
910- yield f"{ cls .__module__ } .{ cls .__name__ } :" .encode ()
911- for key , chunk_iter in self .byte_chunks ():
912- yield (",'" + key + "'=" ).encode ()
913- yield from chunk_iter
914-
915891 @classmethod
916892 def referenced_types (cls ) -> ty .Set [ty .Type [Classifier ]]:
917893 """Returns a flattened list of nested types referenced within the fileset type
@@ -1702,8 +1678,23 @@ def type_name(cls) -> str:
17021678 assert class_name .endswith ("Mock" )
17031679 return class_name [: - len ("Mock" )]
17041680
1705- def __bytes_repr__ (self , cache : ty .Dict [str , ty .Any ]) -> ty .Iterable [bytes ]:
1706- yield from (str (fspath ).encode () for fspath in self .fspaths )
1681+ def byte_chunks (
1682+ self ,
1683+ mtime : bool = False ,
1684+ chunk_len = FILE_CHUNK_LEN_DEFAULT ,
1685+ relative_to : ty .Optional [os .PathLike ] = None ,
1686+ ignore_hidden_files : bool = False ,
1687+ ignore_hidden_dirs : bool = False ,
1688+ ):
1689+ if relative_to is None :
1690+ relative_to = os .path .commonpath (self .fspaths )
1691+ else :
1692+ relative_to = str (relative_to )
1693+ for key , fspath in sorted (
1694+ ((str (p )[len (relative_to ) :], p ) for p in self .fspaths ),
1695+ key = itemgetter (0 ),
1696+ ):
1697+ yield (key , iter ([key .encode ()])) # empty iterator as files don't exist
17071698
17081699 @classproperty
17091700 def namespace (cls ) -> str :
0 commit comments