@@ -837,30 +837,6 @@ def hash_files(self, crypto=None, **kwargs) -> ty.Dict[str, bytes]:
837837 file_hashes [str (path )] = crypto_obj .hexdigest ()
838838 return file_hashes
839839
840- def __bytes_repr__ (
841- self , cache : dict # pylint: disable=unused-argument
842- ) -> ty .Iterable [bytes ]:
843- """Provided for compatibility with Pydra's hashing function, return the contents
844- of all the files in the file-set in chunks
845-
846- Parameters
847- ----------
848- cache : dict
849- an object passed around by Pydra's hashing function to store cached versions
850- of previously hashed objects, to allow recursive structures
851-
852- Yields
853- ------
854- bytes
855- a chunk of bytes of length FILE_CHUNK_LEN_DEFAULT from the contents of all
856- files in the file-set.
857- """
858- cls = type (self )
859- yield f"{ cls .__module__ } .{ cls .__name__ } :" .encode ()
860- for key , chunk_iter in self .byte_chunks ():
861- yield (",'" + key + "'=" ).encode ()
862- yield from chunk_iter
863-
864840 @classmethod
865841 def referenced_types (cls ) -> ty .Set [Classifier ]:
866842 """Returns a flattened list of nested types referenced within the fileset type
@@ -1639,8 +1615,23 @@ def type_name(cls):
16391615 assert cls .__name__ .endswith ("Mock" )
16401616 return cls .__name__ [: - len ("Mock" )]
16411617
1642- def __bytes_repr__ (self , cache ):
1643- yield from (str (fspath ).encode () for fspath in self .fspaths )
1618+ def byte_chunks (
1619+ self ,
1620+ mtime : bool = False ,
1621+ chunk_len = FILE_CHUNK_LEN_DEFAULT ,
1622+ relative_to : ty .Optional [os .PathLike ] = None ,
1623+ ignore_hidden_files : bool = False ,
1624+ ignore_hidden_dirs : bool = False ,
1625+ ):
1626+ if relative_to is None :
1627+ relative_to = os .path .commonpath (self .fspaths )
1628+ else :
1629+ relative_to = str (relative_to )
1630+ for key , fspath in sorted (
1631+ ((str (p )[len (relative_to ) :], p ) for p in self .fspaths ),
1632+ key = itemgetter (0 ),
1633+ ):
1634+ yield (key , iter ([key .encode ()])) # empty iterator as files don't exist
16441635
16451636 @classproperty
16461637 def namespace (cls ):
0 commit comments