o
    yAf                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZmZ er$d dl	m
Z
 d2ddZd3ddZd4ddZd5ddZd6ddZd6ddZd7ddZd6d d!Zd8d$d%Zd9d'd(Zd:d*d+Zd;d<d0d1ZdS )=    )annotationsN)urlsafe_b64encode)TYPE_CHECKINGIterable)ZipInfosrcstrdstreturnNonec                 C  s>   z	t | | W d S  ty   t| | t |  Y d S w N)osreplaceOSErrorshutilcopy2remove)r   r	    r   =/usr/lib/python3.10/site-packages/hatchling/builders/utils.pyreplace_file   s   r   path*Iterable[tuple[str, list[str], list[str]]]c                 c  sf    t  }tj| ddD ]%\}}}t|}|j|jf}||v r%|d d = q|| |||fV  qd S )NT)followlinks)setr   walkstatst_devst_inoadd)r   seenrootdirsfilesr   
identifierr   r   r   	safe_walk   s   


r$   mapc                   C  s   t ttdS )N)      )r%   r   sortedr   r   r   r   get_known_python_major_versions"      r)   startc                 C  s   t j| |}|dkrdS |S )N. )r   r   relpath)r   r+   relative_pathr   r   r   get_relative_path&   s   r0   c                 C  s   t j| t jS r   )r   r   normpathstripsepr   r   r   r   normalize_relative_path0   s   r5   c                 C  s   t | tj S r   )r5   r   r3   r4   r   r   r   normalize_relative_directory4   r*   r6   inclusion_mapdict[str, str]r    c                 C  sp   i }|   D ]%\}}tjtj|}tj|s%tjtj||}t|||< qt	t
|  dd dS )Nc                 S  s   | d  tj| d | d fS )N   r   )countr   r3   )itemr   r   r   <lambda>E   s    z)normalize_inclusion_map.<locals>.<lambda>)key)itemsr   r   
expanduserr1   isabsabspathjoinr5   dictr(   )r7   r    Znormalized_inclusion_mapZ
raw_sourcer/   sourcer   r   r   normalize_inclusion_map8   s   rE   c                 C  s   t jdkr| t jdS | S )N/)r   r3   r   r4   r   r   r   normalize_archive_pathJ   s   
rG   digestbytesc                 C  s   t | ddS )Nascii=)r   decoderstrip)rH   r   r   r   format_file_hashQ   s   rN   intc                   C  s   t tjddS )z
    Returns an `int` derived from the `SOURCE_DATE_EPOCH` environment variable; see
    https://reproducible-builds.org/specs/source-date-epoch/.

    The default value will always be: `1580601600`
    SOURCE_DATE_EPOCHZ
1580601600)rO   r   environgetr   r   r   r   get_reproducible_timestampV   s   rS   st_modec                 C  s    | dB d@ }| d@ r|dO }|S )a  
    https://github.com/takluyver/flit/blob/6a2a8c6462e49f584941c667b70a6f48a7b3f9ab/flit_core/flit_core/common.py#L257

    Normalize the permission bits in the st_mode field from stat to 644/755.

    Popular VCSs only track whether a file is executable or not. The exact
    permissions can vary on systems with different umasks. Normalizing
    to 644 (non executable) or 755 (executable) makes builds more reproducible.
      i@   I   r   )rT   Znew_moder   r   r   normalize_file_permissions`   s   rX   rU   zip_infor   modec                 C  s   |d> | _ dS )z[
    https://github.com/takluyver/flit/commit/3889583719888aef9f28baaa010e698cb7884904
       N)external_attr)rY   rZ   r   r   r   set_zip_info_modeq   s   r]   )r   r   r	   r   r
   r   )r   r   r
   r   )r
   r%   )r   r   r+   r   r
   r   )r   r   r
   r   )r7   r8   r    r   r
   r8   )rH   rI   r
   r   )r
   rO   )rT   rO   r
   rO   )rU   )rY   r   rZ   rO   r
   r   )
__future__r   r   r   base64r   typingr   r   zipfiler   r   r$   r)   r0   r5   r6   rE   rG   rN   rS   rX   r]   r   r   r   r   <module>   s&    

	










