U
    fhe                     @   s  d Z ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlZddlZddl
Z
ddl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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Z ddlmZ ddlm Z  ddl!m"Z" ddl#Z#ddl$m%Z% dj&ej' Z(dd Z)G dd dZ*G dd de*eZ+G dd deZG dd deZ,dd Z-d d! Z.d"d# Z/ej0Z0ej1Z1d$d% Z2d&d' Z3d1d)d*Z4d+d, Z5d2d-d.Z6G d/d0 d0e%Z7dS )3zUsetuptools.command.egg_info

Create a distribution's .egg-info directory and contents    )FileList)DistutilsInternalError)convert_path)logN   )metadata)_entry_points_normalization   )_requirestxt)Command)sdist)walk_revctrl)edit_config)	bdist_egg)glob)SetuptoolsDeprecationWarningz{}.{}c                 C   s  d}|  tjj}ttj}d|f }t|D ]\}}|t|d k}|dkrr|r`|d7 }q0|d||f 7 }q0d}t|}	||	k r|| }
|
dkr||d 7 }n |
d	kr||7 }n|
d
kr|d }||	k r|| dkr|d }||	k r|| dkr|d }||	k r,|| dkr,|d }q||	krF|t|
7 }nR||d | }d}|d dkrxd}|dd }|t|7 }|d|f 7 }|}n|t|
7 }|d7 }q~|s0||7 }q0|d7 }tj|tj	tj
B dS )z
    Translate a file path glob like '*.txt' in to a regular expression.
    This differs from fnmatch.translate which allows wildcards to match
    directory separators. It also knows about '**/' which matches any number of
    directories.
     z[^%s]r
   **z.*z
(?:%s+%s)*r   *?[!]^Nz[%s]z\Z)flags)splitospathsepreescape	enumeratelencompile	MULTILINEDOTALL)r   patZchunksr   Z
valid_charcchunkZ
last_chunkiZ	chunk_lencharZinner_iinnerZ
char_class r-   :lib/python3.8/site-packages/setuptools/command/egg_info.pytranslate_pattern%   sV    







r/   c                   @   sd   e Zd ZdZdZedd Zdd Zdd Ze	e
dd	d
Ze	dddZe	dddZeeZdS )
InfoCommonNc                 C   s   t | j S N)r	   	safe_namedistributionZget_nameselfr-   r-   r.   name|   s    zInfoCommon.namec                 C   s   |  | j }t|S r1   )
_maybe_tagr3   Zget_versionr	   safe_version)r5   Ztaggedr-   r-   r.   tagged_version   s    zInfoCommon.tagged_versionc                 C   s   | j r| |r|S || j  S )z
        egg_info may be called more than once for a distribution,
        in which case the version string already contains all tags.
        )vtags_already_taggedr5   versionr-   r-   r.   r7      s    zInfoCommon._maybe_tag)r=   returnc                 C   s   | | jp| |  S r1   )endswithr:   
_safe_tagsr<   r-   r-   r.   r;      s    zInfoCommon._already_tagged)r>   c              	   C   sN   zt d| j dd  W S  tjjk
rH   t | jdd Y S X d S )N0r
    .)r	   r8   r:   	packagingr=   ZInvalidVersionr2   replacer4   r-   r-   r.   r@      s    zInfoCommon._safe_tagsc                 C   s,   d}| j r|| j 7 }| jr(|td7 }|S )Nr   z%Y%m%d)	tag_buildtag_datetimestrftimer<   r-   r-   r.   tags   s    
zInfoCommon.tags)__name__
__module____qualname__rF   rG   propertyr6   r9   r7   strboolr;   r@   rJ   r:   r-   r-   r-   r.   r0   x   s   
r0   c                   @   s   e Zd ZdZddddgZdgZddiZdd	 Zed
d Z	e	j
dd Z	dd Zdd ZedfddZdddZdd Zdd Zdd Zdd ZdS ) egg_infoz+create a distribution's .egg-info directory)z	egg-base=ezLdirectory containing .egg-info directories [default: top of the source tree])tag-datedz0Add date stamp (e.g. 20050528) to version number)z
tag-build=bz-Specify explicit tag to add to version number)no-dateDz"Don't include date stamp [default]rS   rV   c                 C   s"   d | _ d | _d | _d | _d| _d S )NF)egg_baseegg_namerQ   egg_versionignore_egg_info_in_manifestr4   r-   r-   r.   initialize_options   s
    zegg_info.initialize_optionsc                 C   s   d S r1   r-   r4   r-   r-   r.   tag_svn_revision   s    zegg_info.tag_svn_revisionc                 C   s   d S r1   r-   )r5   valuer-   r-   r.   r]      s    c                 C   s0   t  }|  |d< d|d< t|t|d dS )z
        Materialize the value of date into the
        build tag. Install build keys in a deterministic order
        to avoid arbitrary reordering on subsequent builds.
        rF   r   rG   )rQ   N)collectionsOrderedDictrJ   r   dict)r5   filenamerQ   r-   r-   r.   save_version_info   s    zegg_info.save_version_infoc              
   C   s  | j | _|  | _tj| j}z6t|tjj}|r8dnd}tj	|| j| jf  W n< t
k
r } ztjd| j| jf |W 5 d }~X Y nX | jd kr| jj}|pi dtj| _| d t| jd | _| jtjkrtj| j| j| _| j| jj_d S )Nz%s==%sz%s===%sz2Invalid distribution name or version syntax: %s-%sr   rX   	.egg-info)r6   rY   r9   rZ   rD   r=   ZVersion
isinstanceZrequirementsZRequirement
ValueError	distutilserrorsZDistutilsOptionErrorrX   r3   Zpackage_dirgetr   curdirZensure_dirnamer	   filename_componentrQ   r   joinr   )r5   Zparsed_versionZ
is_versionspecrR   dirsr-   r-   r.   finalize_options   s.    



zegg_info.finalize_optionsNc                 C   s   t | j| j||S )0Compute filename of the output egg. Private API.)_egg_basenamerY   rZ   )r5   
py_versionplatformr-   r-   r.   _get_egg_basename   s    zegg_info._get_egg_basenameFc                 C   sL   |r|  ||| n4tj|rH|dkr>|s>td|| dS | | dS )a  Write `data` to `filename` or delete if empty

        If `data` is non-empty, this routine is the same as ``write_file()``.
        If `data` is empty but not ``None``, this is the same as calling
        ``delete_file(filename)`.  If `data` is ``None``, then this is a no-op
        unless `filename` exists, in which case a warning is issued about the
        orphaned file (if `force` is false), or deleted (if `force` is true).
        Nz$%s not set in setup(), but %s exists)
write_filer   r   existsr   warndelete_file)r5   whatrb   dataforcer-   r-   r.   write_or_delete_file  s    	zegg_info.write_or_delete_filec                 C   s>   t d|| |d}| js:t|d}|| |  dS )zWrite `data` to `filename` (if not a dry run) after announcing it

        `what` is used in a log message to identify what is being written
        to the file.
        zwriting %s to %sutf-8wbN)r   infoencodedry_runopenwriteclose)r5   ry   rb   rz   fr-   r-   r.   ru     s    


zegg_info.write_filec                 C   s    t d| | jst| dS )z8Delete `filename` (if not a dry run) after announcing itzdeleting %sN)r   r   r   r   unlink)r5   rb   r-   r-   r.   rx      s    zegg_info.delete_filec              
   C   s   |  | j zt| jd  W n> tk
r\ } z d| j d}tj||W 5 d }~X Y nX tj	ddD ](}|
 }|| |jtj| j|j qjtj| jd}tj|r| | |   d S )Nz'Cannot update time stamp of directory ''zegg_info.writers)groupznative_libs.txt)ZmkpathrQ   r   utimeOSErrorrg   rh   ZDistutilsFileErrorr   entry_pointsloadr6   r   rl   rv   rx   find_sources)r5   rR   msgZepwriternlr-   r-   r.   run&  s     
zegg_info.runc                 C   s<   t j| jd}t| j}| j|_||_|	  |j
| _
dS )z"Generate SOURCES.txt manifest filezSOURCES.txtN)r   r   rl   rQ   manifest_makerr3   r[   ignore_egg_info_dirmanifestr   filelist)r5   Zmanifest_filenameZmmr-   r-   r.   r   8  s    
zegg_info.find_sources)F)rK   rL   rM   ZdescriptionZuser_optionsZboolean_optionsZnegative_optr\   rN   r]   setterrc   ro   PY_MAJORrt   r|   ru   rx   r   r   r-   r-   r-   r.   rQ      s.    


!
rQ   c                       s   e Zd Zd! fdd	Zdd Zdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd  Z  ZS )"r   NFc                    s   t  || || _d S r1   )super__init__r   )r5   rw   debug_printr   	__class__r-   r.   r   E  s    zFileList.__init__c              	   C   s  |  |\}}}}| j| j| j| jt| j|t| j|| j	| j
d}dddddddd	d}z|| }W n. tk
r   d
|d|}	t|	d Y nX |d}
|dkr|g}|
r|fnd}|| }| d|g|
r|gng  |  |D ]}||stj||f|  qd S )N)includeexcludezglobal-includezglobal-excludezrecursive-includezrecursive-excludegraftprunez%warning: no files found matching '%s'z9warning: no previously-included files found matching '%s'z>warning: no files found matching '%s' anywhere in distributionzRwarning: no previously-included files matching '%s' found anywhere in distributionz:warning: no files found matching '%s' under directory '%s'zNwarning: no previously-included files matching '%s' found under directory '%s'z+warning: no directories found matching '%s'z6no previously-included directories found matching '%s'z$Invalid MANIFEST.in: unknown action z in z
recursive->   r   r   r-   rB   )Z_parse_template_liner   r   global_includeglobal_exclude	functoolspartialrecursive_includerecursive_excluder   r   KeyErrorr   
startswithr   rl   r   rw   )r5   lineactionpatternsdirZdir_patternZ
action_mapZlog_mapZprocess_actionr   Zaction_is_recursiveZextra_log_argsZlog_tmplpatternr-   r-   r.   process_template_lineI  sV    
zFileList.process_template_linec                 C   sR   d}t t| jd ddD ]2}|| j| r| d| j|   | j|= d}q|S )z
        Remove all files from the file list that match the predicate.
        Return True if any matching files were removed
        Fr
   z
 removing T)ranger#   filesr   )r5   Z	predicatefoundr*   r-   r-   r.   _remove_files  s    zFileList._remove_filesc                 C   s$   dd t |D }| | t|S )z#Include files that match 'pattern'.c                 S   s   g | ]}t j|s|qS r-   r   r   isdir.0r   r-   r-   r.   
<listcomp>  s      z$FileList.include.<locals>.<listcomp>r   extendrP   r5   r   r   r-   r-   r.   r     s    
zFileList.includec                 C   s   t |}| |jS )z#Exclude files that match 'pattern'.)r/   r   matchr5   r   r   r-   r-   r.   r     s    zFileList.excludec                 C   s8   t j|d|}dd t|ddD }| | t|S )zN
        Include all files anywhere in 'dir/' that match the pattern.
        r   c                 S   s   g | ]}t j|s|qS r-   r   r   r-   r-   r.   r     s      z.FileList.recursive_include.<locals>.<listcomp>T)	recursive)r   r   rl   r   r   rP   )r5   r   r   Zfull_patternr   r-   r-   r.   r     s    
zFileList.recursive_includec                 C   s    t tj|d|}| |jS )zM
        Exclude any file anywhere in 'dir/' that match the pattern.
        r   r/   r   r   rl   r   r   )r5   r   r   r   r-   r-   r.   r     s    zFileList.recursive_excludec                 C   s$   dd t |D }| | t|S )zInclude all files from 'dir/'.c                 S   s"   g | ]}t j|D ]}|qqS r-   )rg   r   findall)r   Z	match_diritemr-   r-   r.   r     s    z"FileList.graft.<locals>.<listcomp>r   )r5   r   r   r-   r-   r.   r     s
    
zFileList.graftc                 C   s   t tj|d}| |jS )zFilter out files from 'dir/'.r   r   )r5   r   r   r-   r-   r.   r     s    zFileList.prunec                    sJ   | j dkr|   ttjd|  fdd| j D }| | t|S )z
        Include all files anywhere in the current directory that match the
        pattern. This is very inefficient on large file trees.
        Nr   c                    s   g | ]}  |r|qS r-   r   r   r   r-   r.   r     s     
 z+FileList.global_include.<locals>.<listcomp>)Zallfilesr   r/   r   r   rl   r   rP   r   r-   r   r.   r     s    

zFileList.global_includec                 C   s   t tjd|}| |jS )zD
        Exclude all files anywhere that match the pattern.
        r   r   r   r-   r-   r.   r     s    zFileList.global_excludec                 C   s8   | dr|d d }t|}| |r4| j| d S )Nr   )r?   r   
_safe_pathr   append)r5   r   r   r-   r-   r.   r     s
    

zFileList.appendc                 C   s   | j t| j| d S r1   )r   r   filterr   )r5   pathsr-   r-   r.   r     s    zFileList.extendc                 C   s   t t| j| j| _dS )z
        Replace self.files with only safe paths

        Because some owners of FileList manipulate the underlying
        ``files`` attribute directly, this method must be called to
        repair those paths.
        N)listr   r   r   r4   r-   r-   r.   _repair  s    zFileList._repairc              	   C   s   d}t |}|d kr(td|  dS t |d}|d krNt||d dS zBd|kp^d|k}| jrp|rpW dS tj|stj|rW dS W n& t	k
r   t||t
  Y nX d S )Nz!'%s' not %s encodable -- skippingz''%s' in unexpected encoding -- skippingFr}   rd   s	   .egg-infoT)unicode_utilsfilesys_decoder   rw   Z
try_encoder   r   r   rv   UnicodeEncodeErrorsysgetfilesystemencoding)r5   r   Zenc_warnZu_pathZ	utf8_pathZis_egg_infor-   r-   r.   r     s"    


zFileList._safe_path)NNF)rK   rL   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r-   r-   r   r.   r   B  s   F	

r   c                   @   st   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
dd Zdd Zdd Zdd Zdd Zdd ZdS )r   zMANIFEST.inc                 C   s"   d| _ d| _d| _d| _d| _d S )NTF)Zuse_defaultsr   Zmanifest_onlyZforce_manifestr   r4   r-   r-   r.   r\     s
    z!manifest_maker.initialize_optionsc                 C   s   d S r1   r-   r4   r-   r-   r.   ro     s    zmanifest_maker.finalize_optionsc                 C   sz   t | jd| _tj| js$|   |   tj| j	rB| 
  |   |   |   | j  | j  |   d S )N)r   )r   r   r   r   r   rv   r   write_manifestadd_defaultstemplateZread_templateadd_license_files_add_referenced_filesprune_file_listsortZremove_duplicatesr4   r-   r-   r.   r     s    

zmanifest_maker.runc                 C   s   t |}|tjdS )N/)r   r   rE   r   r   )r5   r   r-   r-   r.   _manifest_normalize%  s    
z"manifest_maker._manifest_normalizec                    sB    j    fdd j jD }d j } t j|f| dS )zo
        Write the file list in 'self.filelist' to the manifest file
        named by 'self.manifest'.
        c                    s   g | ]}  |qS r-   )r   r   r4   r-   r.   r   1  s     z1manifest_maker.write_manifest.<locals>.<listcomp>zwriting manifest file '%s'N)r   r   r   r   Zexecuteru   )r5   r   r   r-   r4   r.   r   )  s    

zmanifest_maker.write_manifestc                 C   s   |  |st| | d S r1   )_should_suppress_warningr   rw   )r5   r   r-   r-   r.   rw   5  s    
zmanifest_maker.warnc                 C   s   t d| S )z;
        suppress missing-file warnings from sdist
        zstandard file .*not found)r    r   )r   r-   r-   r.   r   9  s    z'manifest_maker._should_suppress_warningc                 C   s   t |  | j| j | j| j tt }|rB| j| nt	j
| jrX|   t	j
drp| jd | d}| j|j d S )Nzsetup.pyrQ   )r   r   r   r   r   r   r   r   r   r   r   rv   Zread_manifestget_finalized_commandr   rQ   )r5   ZrcfilesZei_cmdr-   r-   r.   r   @  s    


zmanifest_maker.add_defaultsc                 C   s4   | j jjpg }|D ]}td| q| j| d S )Nzadding license file '%s')r3   r   license_filesr   r   r   r   )r5   r   Zlfr-   r-   r.   r   R  s    z manifest_maker.add_license_filesc                 C   s4   t | jdg }|D ]}td| q| j| dS )zGAdd files referenced by the config (e.g. `file:` directive) to filelistZ_referenced_filesz%adding file referenced by config '%s'N)getattrr3   r   debugr   r   )r5   Z
referencedZrfr-   r-   r.   r   X  s    z$manifest_maker._add_referenced_filesc                 C   sZ   |  d}| j }| j|j | j| ttj	}| jj
d| d | dd d S )Nbuildz(^|z)(RCS|CVS|\.svn)T)Zis_regex)r   r3   Zget_fullnamer   r   Z
build_baser    r!   r   r   Zexclude_pattern)r5   r   Zbase_dirr   r-   r-   r.   r   `  s    

 zmanifest_maker.prune_file_listc                 C   s*   t |dr| S tjdddd | S )a0  
        The parent class implementation of this method
        (``sdist``) will try to include data files, which
        might cause recursion problems when
        ``include_package_data=True``.

        Therefore, avoid triggering any attempt of
        analyzing/building the manifest again.
        get_data_files_without_manifestz@`build_py` command does not inherit from setuptools' `build_py`.z
            Custom 'build_py' does not implement 'get_data_files_without_manifest'.
            Please extend command classes from setuptools instead of distutils.
            z!https://peps.python.org/pep-0632/)Zsee_url)hasattrr   r   emitZget_data_files)r5   Zbuild_pyr-   r-   r.   _safe_data_filesj  s    

	zmanifest_maker._safe_data_filesN)rK   rL   rM   r   r\   ro   r   r   r   rw   staticmethodr   r   r   r   r   r   r-   r-   r-   r.   r   
  s   

r   c              	   C   s8   d |}|d}t| d}|| W 5 Q R X dS )z{Create a file with the specified name and write 'contents' (a
    sequence of strings without line terminators) to it.
    
r}   r~   N)rl   r   r   r   )rb   contentsr   r-   r-   r.   ru     s    

ru   c              	   C   s|   t d| | jsx| jj}| j|j |_}| j|j |_}z|	| j
 W 5 || |_|_X t| jdd }t| j
| d S )Nz
writing %sZzip_safe)r   r   r   r3   r   rZ   r=   rY   r6   write_pkg_inforQ   r   r   Zwrite_safety_flag)cmdbasenamerb   r   ZoldverZoldnameZsafer-   r-   r.   r     s    r   c                 C   s   dS )aj  
    Unused: left to avoid errors when updating (from source) from <= 67.8.
    Old installations have a .dist-info directory with the entry-point
    ``depends.txt = setuptools.command.egg_info:warn_depends_obsolete``.
    This may trigger errors when running the first egg_info in build_meta.
    TODO: Remove this function in a version sufficiently > 68.
    Nr-   r   r   rb   r-   r-   r.   warn_depends_obsolete  s    r   c                 C   s:   t dd | j D }| d|dt|d  d S )Nc                 S   s   g | ]}| d dd qS )rC   r
   r   )r   )r   kr-   r-   r.   r     s    z(write_toplevel_names.<locals>.<listcomp>ztop-level namesr   )ra   fromkeysr3   Ziter_distribution_namesru   rl   sorted)r   r   rb   Zpkgsr-   r-   r.   write_toplevel_names  s    
r   c                 C   s   t | ||d d S )NT)	write_argr   r-   r-   r.   overwrite_arg  s    r   Fc                 C   sH   t j|d }t| j|d }|d k	r4d|d }| |||| d S )Nr   r   )r   r   splitextr   r3   rl   r|   )r   r   rb   r{   argnamer^   r-   r-   r.   r     s
    r   c                 C   s,   t | jj}t |}| d||d d S )Nzentry pointsT)r   r   r3   r   Zrenderr|   )r   r   rb   ZepsZdefnr-   r-   r.   write_entries  s    
r   c                 C   sB   t | }t |}| d| d|p&t }|r>|d| 7 }|S )rp   -z-py)r	   rk   r   )rY   rZ   rr   rs   r6   r=   Zeggr-   r-   r.   rq     s    

rq   c                   @   s   e Zd ZdZdS )EggInfoDeprecationWarningz?Deprecated behavior warning for EggInfo, bypassing suppression.N)rK   rL   rM   __doc__r-   r-   r-   r.   r     s   r   )F)NN)8r   Zdistutils.filelistr   Z	_FileListZdistutils.errorsr   Zdistutils.utilr   rg   r   r   r   r    r   rH   r_   Z
_importlibr   r   r   r	   r   Z
setuptoolsr   Zsetuptools.command.sdistr   r   Zsetuptools.command.setoptr   Zsetuptools.commandr   Zsetuptools.unicode_utilsr   Zsetuptools.globr   rD   warningsr   formatversion_infor   r/   r0   rQ   r   ru   r   r   Zwrite_requirementsZwrite_setup_requirementsr   r   r   r   rq   r   r-   r-   r-   r.   <module>   sV   S/  Iy


