o
    
_di                     @   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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%m&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 Z0d d! Z1d"d# Z2d$d% Z3d&d' Z4d(d) Z5d*d+ Z6d,d- Z7d7d/d0Z8d1d2 Z9d8d3d4Z:G d5d6 d6e(Z;dS )9zUsetuptools.command.egg_info

Create a distribution's .egg-info directory and contents    )FileList)DistutilsInternalError)convert_path)logN   )metadata)_entry_points_normalization)Command)sdist)walk_revctrl)edit_config)	bdist_egg)glob)	packaging)yield_lines)SetuptoolsDeprecationWarningz{}.{}c                 C   s  d}|  tjj}ttj}d|f }t|D ]\}}|t|d k}|dkr8|r/|d7 }n|d||f 7 }qd}t|}	||	k r|| }
|
dkrQ||d 7 }n|
d	krZ||7 }nx|
d
kr|d }||	k rp|| dkrp|d }||	k r~|| dkr~|d }||	k r|| dkr|d }||	k r|| dks||	kr|t|
7 }n0||d | }d}|d dkrd}|dd }|t|7 }|d|f 7 }|}n|t|
7 }|d7 }||	k sB|s||7 }q|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]   **z.*z
(?:%s+%s)*r   *?[!]^Nz[%s]z\Z)flags)splitospathsepreescape	enumeratelencompile	MULTILINEDOTALL)r   patchunksr    Z
valid_charcchunkZ
last_chunkiZ	chunk_lencharZinner_iinnerZ
char_class r/   ;lib/python3.10/site-packages/setuptools/command/egg_info.pytranslate_pattern&   s\   


-r1   c                   @   sf   e Zd ZdZdZedd Zdd Zdd Zde	d	e
fd
dZd	e	fddZd	e	fddZeeZdS )
InfoCommonNc                 C   s   t | j S N)r	   Z	safe_namedistributionZget_nameselfr/   r/   r0   name}   s   zInfoCommon.namec                 C   s   |  | j }t|S r3   )
_maybe_tagr4   Zget_versionr	   best_effort_version)r6   Ztaggedr/   r/   r0   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r6   versionr/   r/   r0   r8      s   zInfoCommon._maybe_tagr>   returnc                 C   s   | | jp| |  S r3   )endswithr;   
_safe_tagsr=   r/   r/   r0   r<         zInfoCommon._already_taggedc                 C   s   t d| j dd  S )N0r   )r	   r9   r;   r5   r/   r/   r0   rA      rB   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/   r0   tags   s   
zInfoCommon.tags)__name__
__module____qualname__rD   rE   propertyr7   r:   r8   strboolr<   rA   rH   r;   r/   r/   r/   r0   r2   y   s    
r2   c                   @   s   e Zd ZdZg d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]rQ   rT   c                 C   s"   d | _ d | _d | _d | _d| _d S )NF)egg_baseegg_namerO   egg_versionignore_egg_info_in_manifestr5   r/   r/   r0   initialize_options   
   
zegg_info.initialize_optionsc                 C      d S r3   r/   r5   r/   r/   r0   tag_svn_revision      zegg_info.tag_svn_revisionc                 C   r\   r3   r/   )r6   valuer/   r/   r0   r]      r^   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.
        rD   r   rE   )rO   N)collectionsOrderedDictrH   r   dict)r6   filenamerO   r/   r/   r0   save_version_info   s   zegg_info.save_version_infoc              
   C   sZ  | j | _|  | _tj| j}zt|tjj}|rdnd}tj	|| j| jf  W n t
yD } ztjd| j| jf |d }~ww | jd u rX| jj}|pQi dtj| _| d t| jd | _| jtjkrvtj| j| j| _| j| jj_| jj}t|dd pt|dd }|d ur|| j kr| j|_tj| j|_d | j_d S d S d S )	Nz%s==%sz%s===%sz2Invalid distribution name or version syntax: %s-%sr   rV   	.egg-infokeyr7   ) r7   rW   r:   rX   r   r>   ZVersion
isinstancerequirementsZRequirement
ValueError	distutilserrorsZDistutilsOptionErrorrV   r4   Zpackage_dirgetr   curdirZensure_dirnamer	   filename_componentrO   r   joinr   Z_patched_distgetattrlowerZ_versionZ_parsed_version)r6   Zparsed_versionZ
is_versionspecrP   dirspdrf   r/   r/   r0   finalize_options   s@   



zegg_info.finalize_optionsNc                 C   s   t | j| j||S )0Compute filename of the output egg. Private API.)_egg_basenamerW   rX   )r6   
py_versionplatformr/   r/   r0   _get_egg_basename  s   zegg_info._get_egg_basenameFc                 C   sR   |r|  ||| dS tj|r'|du r |s td|| dS | | 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)r6   whatrc   dataforcer/   r/   r0   write_or_delete_file
  s   	zegg_info.write_or_delete_filec                 C   sB   t d|| |d}| jst|d}|| |  dS 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)r6   r   rc   r   fr/   r/   r0   r{     s   


zegg_info.write_filec                 C   s$   t d| | jst| dS dS )z8Delete `filename` (if not a dry run) after announcing itzdeleting %sN)r   r   r   r   unlink)r6   rc   r/   r/   r0   r~   )  s   zegg_info.delete_filec              
   C   s   |  | j z	t| jd  W n ty) } zd| j d}tj||d }~ww tj	ddD ]}|
 }|| |jtj| j|j q0tj| jd}tj|rX| | |   d S )Nz'Cannot update time stamp of directory ''zegg_info.writers)groupznative_libs.txt)ZmkpathrO   r   utimeOSErrorrj   rk   ZDistutilsFileErrorr   entry_pointsloadr7   r   ro   r|   r~   find_sources)r6   rP   msgZepwriternlr/   r/   r0   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   ro   rO   manifest_makerr4   rY   ignore_egg_info_dirmanifestr   filelist)r6   Zmanifest_filenameZmmr/   r/   r0   r   A  s   
zegg_info.find_sourcesF)rI   rJ   rK   descriptionZuser_optionsZboolean_optionsZnegative_optrZ   rL   r]   setterrd   ru   PY_MAJORrz   r   r{   r~   r   r   r/   r/   r/   r0   rO      s&    


,
rO   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 r3   )super__init__r   )r6   r}   debug_printr   	__class__r/   r0   r   N  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yD   td
j|dw |d}	|dv rQ|g}|	rV|fnd}
|| }| d|g|	rg|gng  |  |D ]}||stj||g|
R   qpd 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/this cannot happen: invalid action '{action!s}')actionz
recursive->   r   r   r/    )Z_parse_template_liner   r   global_includeglobal_exclude	functoolspartialrecursive_includerecursive_excluder   r   KeyErrorr   format
startswithr   ro   r   r}   )r6   liner   patternsdirZdir_patternZ
action_mapZlog_mapZprocess_actionZaction_is_recursiveZextra_log_argsZlog_tmplpatternr/   r/   r0   process_template_lineR  s^   

	zFileList.process_template_linec                 C   sR   d}t t| jd ddD ]}|| 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   )r6   Z	predicatefoundr,   r/   r/   r0   _remove_files  s   zFileList._remove_filesc                 C   $   dd t |D }| | t|S )z#Include files that match 'pattern'.c                 S      g | ]
}t j|s|qS r/   r   r   isdir.0r   r/   r/   r0   
<listcomp>      z$FileList.include.<locals>.<listcomp>r   extendrN   r6   r   r   r/   r/   r0   r     s   
zFileList.includec                 C   s   t |}| |jS )z#Exclude files that match 'pattern'.)r1   r   matchr6   r   r   r/   r/   r0   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   r   r/   r   r   r/   r/   r0   r     r   z.FileList.recursive_include.<locals>.<listcomp>T)	recursive)r   r   ro   r   r   rN   )r6   r   r   Zfull_patternr   r/   r/   r0   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   r1   r   r   ro   r   r   )r6   r   r   r   r/   r/   r0   r     s   zFileList.recursive_excludec                 C   r   )zInclude all files from 'dir/'.c                 S   s"   g | ]}t j|D ]}|q
qS r/   )rj   r   findall)r   Z	match_diritemr/   r/   r0   r     s    
z"FileList.graft.<locals>.<listcomp>r   )r6   r   r   r/   r/   r0   r     s
   
zFileList.graftc                 C   s   t tj|d}| |jS )zFilter out files from 'dir/'.r   r   )r6   r   r   r/   r/   r0   r     s   zFileList.prunec                    sJ   | j du 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/   r0   r     s    z+FileList.global_include.<locals>.<listcomp>)Zallfilesr   r1   r   r   ro   r   rN   r   r/   r   r0   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/   r0   r     s   zFileList.global_excludec                 C   s<   | dr|d d }t|}| |r| j| d S d S )Nr   )r@   r   
_safe_pathr   append)r6   r   r   r/   r/   r0   r     s   

zFileList.appendc                 C   s   | j t| j| d S r3   )r   r   filterr   )r6   pathsr/   r/   r0   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   r5   r/   r/   r0   _repair  s   zFileList._repairc              	   C   s   d}t |}|d u rtd|  dS t |d}|d u r't||d dS z"d|v p/d|v }| jr8|r8W dS tj|sDtj|rGW dS W d S  t	y\   t||t
  Y d S w )Nz!'%s' not %s encodable -- skippingz''%s' in unexpected encoding -- skippingFr   re   s	   .egg-infoT)unicode_utilsfilesys_decoder   r}   Z
try_encoder   r   r   r|   UnicodeEncodeErrorsysgetfilesystemencoding)r6   r   Zenc_warnZu_pathZ	utf8_pathZis_egg_infor/   r/   r0   r     s&   

zFileList._safe_path)NNF)rI   rJ   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r/   r/   r   r0   r   K  s     G	

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 )Nr   F)Zuse_defaultsr   Zmanifest_onlyZforce_manifestr   r5   r/   r/   r0   rZ     r[   z!manifest_maker.initialize_optionsc                 C   r\   r3   r/   r5   r/   r/   r0   ru     s   zmanifest_maker.finalize_optionsc                 C   sz   t | jd| _tj| js|   |   tj| j	r!| 
  |   |   |   | j  | j  |   d S )N)r   )r   r   r   r   r   r|   r   write_manifestadd_defaultstemplateZread_templateadd_license_files_add_referenced_filesprune_file_listsortZremove_duplicatesr5   r/   r/   r0   r   !  s   

zmanifest_maker.runc                 C   s   t |}|tjdS )N/)r   r   replacer   r    )r6   r   r/   r/   r0   _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   r5   r/   r0   r   ;  s    z1manifest_maker.write_manifest.<locals>.<listcomp>zwriting manifest file '%s'N)r   r   r   r   Zexecuter{   )r6   r   r   r/   r5   r0   r   3  s   

zmanifest_maker.write_manifestc                 C   s   |  |st| | d S d S r3   )_should_suppress_warningr   r}   )r6   r   r/   r/   r0   r}   ?  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/   r0   r   C  s   z'manifest_maker._should_suppress_warningc                 C   s   t |  | j| j | j| j tt }|r!| j| nt	j
| jr,|   t	j
dr8| jd | d}| j|j d S )Nzsetup.pyrO   )r   r   r   r   r   r   r   r   r   r   r   r|   Zread_manifestget_finalized_commandr   rO   )r6   ZrcfilesZei_cmdr/   r/   r0   r   J  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')r4   r   license_filesr   r   r   r   )r6   r   Zlfr/   r/   r0   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)rp   r4   r   debugr   r   )r6   Z
referencedZrfr/   r/   r0   r   b  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)r   )Zis_regex)r   r4   Zget_fullnamer   r   Z
build_baser!   r"   r   r    Zexclude_pattern)r6   r   base_dirr    r/   r/   r0   r   j  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)r6   Zbuild_pyr/   r/   r0   _safe_data_filest  s   

	zmanifest_maker._safe_data_filesN)rI   rJ   rK   r   rZ   ru   r   r   r   r}   staticmethodr   r   r   r   r   r   r/   r/   r/   r0   r     s    

r   c                 C   sN   d |}|d}t| d}|| W d   dS 1 s w   Y  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)ro   r   r   r   )rc   contentsr   r/   r/   r0   r{     s
   

"r{   c              	   C   s   t d| | jsE| jj}| j|j|_}| j|j|_}z|	| j
 W |||_|_n|||_|_w t| jdd }t| j
| d S d S )Nz
writing %sZzip_safe)r   r   r   r4   r   rX   r>   rW   r7   write_pkg_inforO   rp   r   Zwrite_safety_flag)cmdbasenamerc   r   ZoldverZoldnamesafer/   r/   r0   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   rc   r/   r/   r0   warn_depends_obsolete  s    r   c                 C   s,   t |pd}dd }t||}| | d S )Nr/   c                 S   s   | d S )Nr   r/   )r   r/   r/   r0   	append_cr  s   z&_write_requirements.<locals>.append_cr)r   map
writelines)streamZreqslinesr   r/   r/   r0   _write_requirements  s   
r   c                 C   sn   | j }t }t||j |jpi }t|D ]}|djdi t	  t|||  q| 
d||  d S )Nz
[{extra}]
rh   r/   )r4   ioStringIOr   Zinstall_requiresextras_requiresortedr   r   varsr   getvalue)r   r   rc   Zdistr   r  Zextrar/   r/   r0   write_requirements  s   
r  c                 C   s,   t  }t|| jj | d||  d S )Nzsetup-requirements)r   r  r   r4   Zsetup_requiresr   r  )r   r   rc   r   r/   r/   r0   write_setup_requirements  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 ).r   r   )r   )r   kr/   r/   r0   r     r   z(write_toplevel_names.<locals>.<listcomp>ztop-level namesr   )rb   fromkeysr4   Ziter_distribution_namesr{   ro   r  )r   r   rc   Zpkgsr/   r/   r0   write_toplevel_names  s    r  c                 C   s   t | ||d d S )NT)	write_argr   r/   r/   r0   overwrite_arg  s   r  Fc                 C   sH   t j|d }t| j|d }|d urd|d }| |||| d S )Nr   r   )r   r   splitextrp   r4   ro   r   )r   r   rc   r   argnamer_   r/   r/   r0   r    s
   r  c                 C   s,   t | jj}t |}| d||d d S )Nzentry pointsT)r   r   r4   r   Zrenderr   )r   r   rc   ZepsZdefnr/   r/   r0   write_entries  s   
r  c                 C   sB   t | }t |}| d| d|pt }|r|d| 7 }|S )rv   -z-py)r	   rn   r   )rW   rX   rx   ry   r7   r>   Zeggr/   r/   r0   rw     s   

rw   c                   @   s   e Zd ZdZdS )EggInfoDeprecationWarningz?Deprecated behavior warning for EggInfo, bypassing suppression.N)rI   rJ   rK   __doc__r/   r/   r/   r0   r    s    r  r   )NN)<r  Zdistutils.filelistr   Z	_FileListZdistutils.errorsr   Zdistutils.utilr   rj   r   r   r   r!   r   r   rF   r`   Z
_importlibr   r   r   r	   Z
setuptoolsr
   Zsetuptools.command.sdistr   r   Zsetuptools.command.setoptr   Zsetuptools.commandr   Zsetuptools.unicode_utilsr   Zsetuptools.globr   Zsetuptools.externr   Zsetuptools.extern.jaraco.textr   warningsr   r   version_infor   r1   r2   rO   r   r{   r   r   r   r  r  r  r  r  r  rw   r  r/   r/   r/   r0   <module>   s\    S, ' Jy




