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