(bdist_dir: str)
Rewrite RECORD file with hashes for all files in `wheel_sdir`

    Copied from :method:`wheel.bdist_wheel.bdist_wheel.write_record`

    Will also unsign wheel

    Parameters
    ----------
    bdist_dir : str
        Path of unpacked wheel file
Rewrite RECORD file with hashes for all files in `wheel_sdir`
Rewrite RECORD file with hashes for all files in wheel_sdir
def rewrite_record(bdist_dir: str) -> None:
    """Rewrite RECORD file with hashes for all files in `wheel_sdir`

    Copied from :method:`wheel.bdist_wheel.bdist_wheel.write_record`

    Will also unsign wheel

    Parameters
    ----------
    bdist_dir : str
        Path of unpacked wheel file
    """
    info_dir = _dist_info_dir(bdist_dir)
    record_path = pjoin(info_dir, "RECORD")
    record_relpath = relpath(record_path, bdist_dir)
    # Unsign wheel - because we're invalidating the record hash
    sig_path = pjoin(info_dir, "RECORD.jws")
    if exists(sig_path):
        os.unlink(sig_path)

    def walk() -> Generator[str, None, None]:
        for dir, dirs, files in os.walk(bdist_dir):
            for f in files:
                yield pjoin(dir, f)

    def skip(path: str) -> bool:
        """Wheel hashes every possible file."""
        return path == record_relpath

    with open(record_path, "w+", newline="", encoding="utf-8") as record_file:
        writer = csv.writer(record_file)
        for path in walk():
            relative_path = relpath(path, bdist_dir)
            if skip(relative_path):
                hash_ = ""
                size = ""
            else:
                with open(path, "rb") as f:
                    data = f.read()
                digest = hashlib.sha256(data).digest()
                sha256 = urlsafe_b64encode(digest).rstrip(b"=").decode("ascii")
                hash_ = f"sha256={sha256}"
                size = f"{len(data)}"
            record_path = relpath(path, bdist_dir).replace(psep, "/")
            writer.writerow((record_path, hash_, size))
def rewrite_record ( bdist_dir : str ) -> None : info_dir = _dist_info_dir ( bdist_dir ) record_path = pjoin ( info_dir , "RECORD" ) record_relpath = relpath ( record_path , bdist_dir ) # Unsign wheel - because we're invalidating the record hash sig_path = pjoin ( info_dir , "RECORD.jws" ) if exists ( sig_path ) : os . unlink ( sig_path ) def walk ( ) -> Generator [ str , None , None ] : for dir , dirs , files in os . walk ( bdist_dir ) : for f in files : yield pjoin ( dir , f ) def skip ( path : str ) -> bool : """Wheel hashes every possible file.""" return path == record_relpath with open ( record_path , "w+" , newline = "" , encoding = "utf-8" ) as record_file : writer = csv . writer ( record_file ) for path in walk ( ) : relative_path = relpath ( path , bdist_dir ) if skip ( relative_path ) : hash_ = "" size = "" else : with open ( path , "rb" ) as f : data = f . read ( ) digest = hashlib . sha256 ( data ) . digest ( ) sha256 = urlsafe_b64encode ( digest ) . rstrip ( b"=" ) . decode ( "ascii" ) hash_ = f"sha256={sha256}" size = f"{len(data)}" record_path = relpath ( path , bdist_dir ) . replace ( psep , "/" ) writer . writerow ( ( record_path , hash_ , size ) )