a
    6Rh                     @  s   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ ddl	m
Z
 ddlmZ dd	lmZ d dlm  mZ d d
lmZ eZdddZG dd dejZdS )    )annotationsN)chain)ClassVar   )metadata)Distribution   )_ORIGINAL_SUBCOMMANDS)log c                 c  s(   t jddD ]}| | E dH  qdS )z%Find all files under revision controlzsetuptools.file_finders)groupN)r   entry_pointsload)dirnameep r   N/opt/python-3.9.24/usr/lib/python3.9/site-packages/setuptools/command/sdist.pywalk_revctrl   s    r   c                      s  e Zd ZU dZg dZded< i Zded< g dZedd	 eD Z	d
dddZ
d
dddZd
dddZeejdd Zd
d fddZ fddZdd Zdd Zdd Zdd Z fd d!Zd
d fd"d#Zd
dd$d%Zd
dd&d'Zd(d) Zd*d+ Z  ZS ),sdistz=Smart sdist that finds anything supported by revision control))zformats=Nz6formats for source distribution (comma-separated list))z	keep-tempkz@keep the distribution tree around after creating archive file(s))z	dist-dir=dzFdirectory to put the source distribution archive(s) in [default: dist])zowner=uz@Owner name used when creating a tar file [default: current user])zgroup=gzAGroup name used when creating a tar file [default: current group]r   distributionzClassVar[dict[str, str]]negative_opt)r   z.rstz.txtz.mdc                 c  s   | ]}d | V  qdS )ZREADMENr   ).0extr   r   r   	<genexpr>8       zsdist.<genexpr>None)returnc                 C  s   |  d | d}|j| _| jtj|jd |   | 	 D ]}|  | qD| 
  t| jdg }| jD ] }dd|f}||vrp|| qpd S )Negg_infozSOURCES.txt
dist_filesr   r   )run_commandget_finalized_commandfilelistappendospathjoinr!   check_readmeget_sub_commandsmake_distributiongetattrr   Zarchive_files)selfZei_cmdcmd_namer"   filedatar   r   r   run:   s    



z	sdist.runc                 C  s   t j|  d S N)origr   initialize_optionsr.   r   r   r   r5   M   s    zsdist.initialize_optionsc                 C  s8   |    tj|  W d   n1 s*0    Y  dS )z%
        Workaround for #516
        N)_remove_os_linkr4   r   r,   r6   r   r   r   r,   P   s    
zsdist.make_distributionc                  c  sd   G dd d} t td| }zt`W n ty4   Y n0 zdV  W || ur`|t_n|| ur^|t_0 dS )zG
        In a context, remove and restore os.link if it exists
        c                   @  s   e Zd ZdS )z&sdist._remove_os_link.<locals>.NoValueN)__name__
__module____qualname__r   r   r   r   NoValue^   s   r;   linkN)r-   r'   r<   	Exception)r;   Zorig_valr   r   r   r7   W   s    zsdist._remove_os_linkc                   s   t    |   d S r3   )superadd_defaults _add_defaults_build_sub_commandsr6   	__class__r   r   r?   l   s    
zsdist.add_defaultsc                   s&   t    tjdr"| jd d S )Nzpyproject.toml)r>   _add_defaults_optionalr'   r(   isfiler%   r&   r6   rA   r   r   rC   p   s    
zsdist._add_defaults_optionalc                 C  s8   | j  r4| d}| j|  | | | dS )zgetting python filesbuild_pyN)r   has_pure_modulesr$   r%   extendget_source_files_add_data_files_safe_data_filesr.   rE   r   r   r   _add_defaults_pythonu   s    

zsdist._add_defaults_pythonc                   sP     d}t| t } fdd|D }dd |D } jt| d S )Nbuildc                 3  s   | ]}  |V  qd S r3   )r$   r   cr6   r   r   r      r   z9sdist._add_defaults_build_sub_commands.<locals>.<genexpr>c                 s  s    | ]}t |d r| V  qdS )rH   N)hasattrrH   rN   r   r   r   r      r   )r$   setr+   r	   r%   rG   r   from_iterable)r.   rM   Zmissing_cmdsZcmdsfilesr   r6   r   r@   |   s
    
z&sdist._add_defaults_build_sub_commandsc                 C  s   |j S )a  
        Since the ``sdist`` class is also used to compute the MANIFEST
        (via :obj:`setuptools.command.egg_info.manifest_maker`),
        there might be recursion problems when trying to obtain the list of
        data_files and ``include_package_data=True`` (which in turn depends on
        the files included in the MANIFEST).

        To avoid that, ``manifest_maker`` should be able to overwrite this
        method and avoid recursive attempts to build/analyze the MANIFEST.
        )
data_filesrK   r   r   r   rJ      s    zsdist._safe_data_filesc                 C  s   | j dd |D  dS )zA
        Add data files as found in build_py.data_files.
        c                 s  s.   | ]&\}}}}|D ]}t j||V  qqd S r3   )r'   r(   r)   )r   _src_dir	filenamesnamer   r   r   r      s   
z(sdist._add_data_files.<locals>.<genexpr>N)r%   rG   )r.   rT   r   r   r   rI      s    zsdist._add_data_filesc                   s0   zt    W n ty*   td Y n0 d S )Nz&data_files contains unexpected objects)r>   _add_defaults_data_files	TypeErrorr
   warnr6   rA   r   r   rY      s    zsdist._add_defaults_data_filesc                   s.   t    ttj}| jjd| dd d S )Nz^(\.tox|\.nox|\.venv)T)Zis_regex)r>   prune_file_listreescaper'   sepr%   Zexclude_pattern)r.   r_   rA   r   r   r\      s    
zsdist.prune_file_listc                 C  s8   | j D ]}tj|r d S q| dd| j   d S )Nz,standard file not found: should have one of z, )READMESr'   r(   existsr[   r)   )r.   fr   r   r   r*      s    
zsdist.check_readmec                 C  s^   t j| || tj|d}ttdrJtj|rJt| | 	d| | 
d| d S )Nz	setup.cfgr<   r!   )r4   r   make_release_treer'   r(   r)   rP   ra   unlink	copy_filer$   Zsave_version_info)r.   base_dirrS   destr   r   r   rc      s    
zsdist.make_release_treec                 C  sN   t j| jsdS t| jd}| }W d    n1 s<0    Y  |dkS )NFrbs+   # file GENERATED by distutils, do NOT edit
)r'   r(   rD   manifestopenreadline)r.   fp
first_liner   r   r   _manifest_is_not_generated   s
    &z sdist._manifest_is_not_generatedc              	   C  s   t d| j t| jd}|D ]^}z|d}W n& tyV   t |d Y qY n0 | }|ds|spq| j	
| q|  dS )zRead the manifest file (named by 'self.manifest') and use it to
        fill in 'self.filelist', the list of files to include in the source
        distribution.
        zreading manifest file '%s'rh   zUTF-8z  not UTF-8 decodable -- skipping#N)r
   infori   rj   decodeUnicodeDecodeErrorr[   strip
startswithr%   r&   close)r.   ri   Z
bytes_lineliner   r   r   read_manifest   s    
zsdist.read_manifest)r8   r9   r:   __doc__user_options__annotations__r   ZREADME_EXTENSIONStupler`   r2   r5   r,   staticmethod
contextlibcontextmanagerr7   r?   rC   rL   r@   rJ   rI   rY   r\   r*   rc   rn   rw   __classcell__r   r   rA   r   r      s0   

		r   )r   )
__future__r   r}   r'   r]   	itertoolsr   typingr   Z
_importlibr   distr   rM   r	   Zdistutils.command.sdistcommandr   r4   	distutilsr
   listZ_default_revctrlr   r   r   r   r   <module>   s   
