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