python/ray/_private/runtime_env/packaging.py
def _hash_directory(
    root: Path,
    relative_path: Path,
    excludes: Optional[Callable],
    logger: Optional[logging.Logger] = default_logger,
) -> bytes:
    """Helper function to create hash of a directory.

    It'll go through all the files in the directory and xor
    hash(file_name, file_content) to create a hash value.
    """
    hash_val = b"0" * 8
    BUF_SIZE = 4096 * 1024

    def handler(path: Path):
        md5 = hashlib.md5()
        md5.update(str(path.relative_to(relative_path)).encode())
        if not path.is_dir():
            with path.open("rb") as f:
                data = f.read(BUF_SIZE)
                while len(data) != 0:
                    md5.update(data)
                    data = f.read(BUF_SIZE)
        nonlocal hash_val
        hash_val = _xor_bytes(hash_val, md5.digest())

    excludes = [] if excludes is None else [excludes]
    _dir_travel(root, excludes, handler, logger=logger)
    return hash_val
Helper function to create hash of a directory.

    It'll go through all the files in the directory and xor
    hash(file_name, file_content) to create a hash value.
    
Helper function to create hash of a directory.
It'll go through all the files in the directory and xor
hash(file_name, file_content) to create a hash value.
Helper function to create hash of a directory . It ' ll go through all the files in the directory and xor hash ( file_name file_content ) to create a hash value .
def _hash_directory(
    root: Path,
    relative_path: Path,
    excludes: Optional[Callable],
    logger: Optional[logging.Logger] = default_logger,
) -> bytes:
    hash_val = b"0" * 8
    BUF_SIZE = 4096 * 1024
    def handler(path: Path):
        md5 = hashlib.md5()
        md5.update(str(path.relative_to(relative_path)).encode())
        if not path.is_dir():
            with path.open("rb") as f:
                data = f.read(BUF_SIZE)
                while len(data) != 0:
                    md5.update(data)
                    data = f.read(BUF_SIZE)
        nonlocal hash_val
        hash_val = _xor_bytes(hash_val, md5.digest())
    excludes = [] if excludes is None else [excludes]
    _dir_travel(root, excludes, handler, logger=logger)
    return hash_val
def _hash_directory ( root : Path , relative_path : Path , excludes : Optional [ Callable ] , logger : Optional [ logging . Logger ] = default_logger , ) -> bytes : hash_val = b"0" * 8 BUF_SIZE = 4096 * 1024 def handler ( path : Path ) : md5 = hashlib . md5 ( ) md5 . update ( str ( path . relative_to ( relative_path ) ) . encode ( ) ) if not path . is_dir ( ) : with path . open ( "rb" ) as f : data = f . read ( BUF_SIZE ) while len ( data ) != 0 : md5 . update ( data ) data = f . read ( BUF_SIZE ) nonlocal hash_val hash_val = _xor_bytes ( hash_val , md5 . digest ( ) ) excludes = [ ] if excludes is None else [ excludes ] _dir_travel ( root , excludes , handler , logger = logger ) return hash_val
Helper function to create hash of a directory.
Helper function to create hash of a directory .
"""Helper function to create hash of a directory.

    It'll go through all the files in the directory and xor
    hash(file_name, file_content) to create a hash value.
    """
root
Path
relative_path
Path
excludes
Optional[Callable]
logger
Optional[logging.Logger]