o
    JAf                     @   s   d dl mZ d dlm  mZ d dl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 eZdd
dZG dd deejZdS )    )logN)chain   )sdist_add_defaults   )metadata)_ORIGINAL_SUBCOMMANDS c                 c   s0    t jddD ]}| | D ]}|V  qqdS )z%Find all files under revision controlzsetuptools.file_finders)groupN)r   entry_pointsload)dirnameepitem r   Z/usr/lib/python3.10/site-packages/setuptools-67.5.1-py3.10.egg/setuptools/command/sdist.pywalk_revctrl   s   r   c                       s   e Zd ZdZg dZi Zg dZedd eD Zdd Z	dd	 Z
d
d Zdd Zeejdd Z 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 Z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	   z.rstz.txtz.mdc                 c   s    | ]}d  |V  qdS )z	README{0}N)format).0extr   r   r   	<genexpr>-       zsdist.<genexpr>c                 C   s   |  d | d}|j| _| jtj|jd |   | 	 D ]}|  | q"| 
  t| jdg }| jD ]}dd|f}||vrH|| q8d 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getattrdistributionarchive_files)selfei_cmdcmd_namer   filedatar   r   r   run/   s   




z	sdist.runc                 C   s   t j|  |   d S N)origr   initialize_options_default_to_gztarr,   r   r   r   r4   B   s   zsdist.initialize_optionsc                 C   s   t jdkrd S dg| _d S )N)      r   betar   gztar)sysversion_infoformatsr6   r   r   r   r5   G   s   
zsdist._default_to_gztarc                 C   s:   |    tj|  W d   dS 1 sw   Y  dS )z%
        Workaround for #516
        N)_remove_os_linkr3   r   r(   r6   r   r   r   r(   M   s   
"zsdist.make_distributionc               
   c   sv    G dd d} t td| }zt`W n	 ty   Y nw zdV  W || ur-ttd| dS dS || ur:ttd| w w )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    rB   linkN)r)   r#   rC   	Exceptionsetattr)rB   orig_valr   r   r   r>   T   s   zsdist._remove_os_linkc                    s   t    |   d S r2   )superadd_defaults _add_defaults_build_sub_commandsr6   	__class__r   r   rH   i   s   
zsdist.add_defaultsc                    s*   t    tjdr| jd d S d S )Nzpyproject.toml)rG   _add_defaults_optionalr#   r$   isfiler!   r"   r6   rJ   r   r   rL   m   s   
zsdist._add_defaults_optionalc                 C   s<   | j  r| d}| j|  | | | dS dS )zgetting python filesbuild_pyN)r*   has_pure_modulesr    r!   extendget_source_files_add_data_files_safe_data_filesr,   rN   r   r   r   _add_defaults_pythonr   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 r2   )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 )rQ   N)hasattrrQ   rW   r   r   r   r   ~   s     )r    setr'   r   r!   rP   r   from_iterable)r,   rV   missing_cmdscmdsfilesr   r6   r   rI   y   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_filesrT   r   r   r   rS      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   s0    | ]\}}}}|D ]
}t j||V  q
qd S r2   )r#   r$   r%   )r   _src_dir	filenamesnamer   r   r   r      s    
z(sdist._add_data_files.<locals>.<genexpr>N)r!   rP   )r,   r_   r   r   r   rR      s   zsdist._add_data_filesc                    s0   zt    W d S  ty   td Y d S w )Nz&data_files contains unexpected objects)rG   _add_defaults_data_files	TypeErrorr   warnr6   rJ   r   r   rd      s
   zsdist._add_defaults_data_filesc                 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$   existsrf   r%   )r,   fr   r   r   r&      s   

zsdist.check_readmec                 C   s^   t j| || tj|d}ttdr%tj|r%t| | 	d| | 
d| d S )Nz	setup.cfgrC   r   )r3   r   make_release_treer#   r$   r%   rY   rh   unlink	copy_filer    save_version_info)r,   base_dirr^   destr   r   r   rj      s   
zsdist.make_release_treec                 C   sT   t j| js	dS t| jd}| }W d    n1 sw   Y  |d kS )NFrbz+# file GENERATED by distutils, do NOT edit
)r#   r$   rM   manifestioopenreadlineencode)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y(   t d|  Y qw | }|ds4|s5q| 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'rp   zUTF-8z"%r not UTF-8 decodable -- skipping#N)r   inforq   rs   decodeUnicodeDecodeErrorrf   strip
startswithr!   r"   close)r,   rq   liner   r   r   read_manifest   s   zsdist.read_manifest)r?   r@   rA   __doc__user_optionsnegative_optREADME_EXTENSIONStuplerg   r1   r4   r5   r(   staticmethod
contextlibcontextmanagerr>   rH   rL   rU   rI   rS   rR   rd   r&   rj   rx   r   __classcell__r   r   rJ   r   r      s0    


r   )r	   )	distutilsr   distutils.command.sdistcommandr   r3   r#   r;   rr   r   	itertoolsr   
py36compatr   
_importlibr   rV   r   list_default_revctrlr   r   r   r   r   <module>   s    
