3
LYb                 @   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 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m Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'j(Z(ddl)m*Z* ddl+m,Z, yddl-m.Z. W n e/k
r@   Y nX dd Z0G dd deZ1G dd deZG dd deZ2dd Z3dd Z4dd Z5d d! Z6d"d# Z7d$d% Z8d&d' Z9d(d) Z:d1d+d,Z;d-d. Z<d/d0 Z=dS )2zUsetuptools.command.egg_info

Create a distribution's .egg-info directory and contents    )FileList)DistutilsInternalError)convert_path)logN)six)map)Command)sdist)walk_revctrl)edit_config)	bdist_egg)parse_requirements	safe_nameparse_versionsafe_versionyield_lines
EntryPointiter_entry_pointsto_filename)glob)	packaging)	svn_utilsc             C   s  d}| j tjj}tjtj}d|f }xt|D ]\}}|t|d k}|dkrv|rd|d7 }q4|d||f 7 }q4d}t|}	x:||	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 }x&||	k r6|| dkr6|d }qW ||	krR|tj|
7 }nR||d | }d}|d dkrd}|dd }|tj|7 }|d|f 7 }|}n|tj|
7 }|d7 }qW |s4||7 }q4W tj|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.*z
(?:%s+%s)*r   *?[!]^Nz[%s]z\Z(?ms))	splitospathsepreescape	enumeratelencompile)r   patchunksr#   Z
valid_charcchunk
last_chunkiZ	chunk_lencharZinner_iinnerZ
char_class r1   u/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/setuptools/setuptools/command/egg_info.pytranslate_pattern)   sT    




r3   c               @   s   e Zd ZdZd/d0d1d2d3d4gZddgZdddZdd Zdd Zdd Z	d5d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.S )6egg_infoz+create a distribution's .egg-info directory	egg-base=eLdirectory containing .egg-info directories (default: top of the source tree)tag-svn-revisionr,Add subversion revision ID to version numbertag-dated0Add date stamp (e.g. 20050528) to version number
tag-build=b-Specify explicit tag to add to version numberno-svn-revisionR*Don't add subversion revision ID [default]no-dateD"Don't include date stamp [default])zno-svn-revisionzno-datec             C   s:   d | _ d | _d | _d | _d | _d| _d| _d| _d | _d S )Nr   F)	egg_nameegg_versionegg_baser4   	tag_buildtag_svn_revisiontag_datebroken_egg_infovtags)selfr1   r1   r2   initialize_options   s    zegg_info.initialize_optionsc             C   sB   t tdt}| }| j |d< d|d< d|d< t|t|d dS )z
        Materialize the values of svn_revision and date into the
        build tag. Install these keys in a deterministic order
        to avoid arbitrary reordering on subsequent builds.
        OrderedDictrJ   r   rL   rK   )r4   N)getattrcollectionsdicttagsr   )rO   filenameZodictr4   r1   r1   r2   save_version_info   s    zegg_info.save_version_infoc             C   sV  t | jj | _| j | _| j | _t| j}y6t	|t
jj}|rFdnd}tt|| j| jf  W n, tk
r   tjjd| j| jf Y nX | jd kr| jj}|pi jdtj| _| jd t| jd | _| jtjkrtjj| j| j| _d| jkr| j  | j| jj_| jj}|d k	rR|j | jj! krR| j|_"t| j|_#d | j_d S )Nz%s==%sz%s===%sz2Invalid distribution name or version syntax: %s-%sr   rI   z	.egg-info-)$r   distributionget_namerG   rU   rN   tagged_versionrH   r   
isinstancer   versionVersionlistr   
ValueError	distutilserrorsDistutilsOptionErrorrI   package_dirgetr!   curdirensure_dirnamer   r4   r"   joincheck_broken_egg_infometadataZ_patched_distkeylower_version_parsed_version)rO   parsed_versionZ
is_versionspecdirspdr1   r1   r2   finalize_options   s8    




zegg_info.finalize_optionsFc             C   sN   |r| j ||| n6tjj|rJ|dkr@| r@tjd|| dS | j| 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)rO   whatrV   dataforcer1   r1   r2   write_or_delete_file   s    	
zegg_info.write_or_delete_filec             C   sD   t jd|| tjr|jd}| js@t|d}|j| |j  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 %szutf-8wbN)	r   infor   PY3encodedry_runopenwriteclose)rO   rx   rV   ry   fr1   r1   r2   rt      s    


zegg_info.write_filec             C   s    t jd| | jstj| dS )z8Delete `filename` (if not a dry run) after announcing itzdeleting %sN)r   r}   r   r!   unlink)rO   rV   r1   r1   r2   rw      s    zegg_info.delete_filec             C   s2   | j j }| jr$|j| jr$t|S t|| j S )N)rY   get_versionrN   endswithr   )rO   r]   r1   r1   r2   r[     s    
zegg_info.tagged_versionc             C   s   | j | j | jj}x@tdD ]4}|j|d |j }|| |jtj	j
| j|j qW tj	j
| jd}tj	j|r|| j| | j  d S )Nzegg_info.writers)	installerznative_libs.txt)mkpathr4   rY   Zfetch_build_eggr   requireresolvenamer!   r"   rh   ru   rw   find_sources)rO   r   epwriternlr1   r1   r2   run
  s     
zegg_info.runc             C   sL   d}| j r|| j 7 }| jr4tjd |d| j  7 }| jrH|tjd7 }|S )Nr   zJtag_svn_revision is deprecated and will not be honored in a future releasez-r%sz-%Y%m%d)rJ   rK   warningsrv   get_svn_revisionrL   timestrftime)rO   r]   r1   r1   r2   rU     s    
zegg_info.tagsc               C   s$   dt  krdS ttjjtjj S )Nr   0)globalsstrr   ZSvnInfoloadr!   rf   get_revisionr1   r1   r1   r2   r   '  s    
zegg_info.get_svn_revisionc             C   s4   t jj| jd}t| j}||_|j  |j| _dS )z"Generate SOURCES.txt manifest filezSOURCES.txtN)	r!   r"   rh   r4   manifest_makerrY   manifestr   filelist)rO   Zmanifest_filenamemmr1   r1   r2   r   -  s
    
zegg_info.find_sourcesc             C   sd   | j d }| jtjkr&tjj| j|}tjj|r`tjdd d dd  || j	 | j	| _
|| _	d S )Nz	.egg-inforX   N   z
Note: Your current .egg-info directory has a '-' in its name;
this will not work correctly with "setup.py develop".

Please rename %s to %s to correct this problem.
)rG   rI   r!   rf   r"   rh   ru   r   rv   r4   rM   )rO   Zbeir1   r1   r2   ri   5  s    

zegg_info.check_broken_egg_infoN)r5   r6   r7   )r8   r9   r:   )r;   r<   r=   )r>   r?   r@   )rA   rB   rC   )rD   rE   rF   )F)__name__
__module____qualname__descriptionuser_optionsboolean_optionsnegative_optrP   rW   rs   r{   rt   rw   r[   r   rU   staticmethodr   r   ri   r1   r1   r1   r2   r4   {   s0     /
r4   c               @   s|   e Z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dS )r   c             C   s<  | j |\}}}}|dkrV| jddj|  x"|D ]}| j|s4tjd| q4W n|dkr| jddj|  x"|D ]}| j|sxtjd| qxW n|dkr| jd	dj|  x"|D ]}| j|stjd
| qW nZ|dkr(| jddj|  x&|D ]}| j|stjd| qW n|dkrx| jd|dj|f  x|D ]"}| j	||sPtjd|| qPW n|dkr| jd|dj|f  x|D ]"}| j
||stjd|| qW np|dkr| jd|  | j|s8tjd| n>|dkr,| jd|  | j|s8tjd| ntd| d S )Nincludezinclude  z%warning: no files found matching '%s'excludezexclude z9warning: no previously-included files found matching '%s'zglobal-includezglobal-include z>warning: no files found matching '%s' anywhere in distributionzglobal-excludezglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionzrecursive-includezrecursive-include %s %sz:warning: no files found matching '%s' under directory '%s'zrecursive-excludezrecursive-exclude %s %szNwarning: no previously-included files matching '%s' found under directory '%s'graftzgraft z+warning: no directories found matching '%s'prunezprune z6no previously-included directories found matching '%s'z'this cannot happen: invalid action '%s')Z_parse_template_linedebug_printrh   r   r   rv   r   global_includeglobal_excluderecursive_includerecursive_excluder   r   r   )rO   lineactionpatternsdirZdir_patternpatternr1   r1   r2   process_template_lineH  sd    













zFileList.process_template_linec             C   sV   d}xLt t| jd ddD ]2}|| j| r| jd| j|   | j|= d}qW |S )z
        Remove all files from the file list that match the predicate.
        Return True if any matching files were removed
        Fr   z
 removing Tr   )ranger'   filesr   )rO   	predicatefoundr.   r1   r1   r2   _remove_files  s    zFileList._remove_filesc             C   s$   dd t |D }| j| t|S )z#Include files that match 'pattern'.c             S   s   g | ]}t jj|s|qS r1   )r!   r"   isdir).0r   r1   r1   r2   
<listcomp>  s    z$FileList.include.<locals>.<listcomp>)r   extendbool)rO   r   r   r1   r1   r2   r     s    
zFileList.includec             C   s   t |}| j|jS )z#Exclude files that match 'pattern'.)r3   r   match)rO   r   r   r1   r1   r2   r     s    zFileList.excludec             C   s8   t jj|d|}dd t|ddD }| j| t|S )zN
        Include all files anywhere in 'dir/' that match the pattern.
        z**c             S   s   g | ]}t jj|s|qS r1   )r!   r"   r   )r   r   r1   r1   r2   r     s    z.FileList.recursive_include.<locals>.<listcomp>T)	recursive)r!   r"   rh   r   r   r   )rO   r   r   Zfull_patternr   r1   r1   r2   r     s    
zFileList.recursive_includec             C   s    t tjj|d|}| j|jS )zM
        Exclude any file anywhere in 'dir/' that match the pattern.
        z**)r3   r!   r"   rh   r   r   )rO   r   r   r   r1   r1   r2   r     s    zFileList.recursive_excludec             C   s   t jj|}| j| t|S )zInclude all files from 'dir/'.)ra   r   findallr   r   )rO   r   r   r1   r1   r2   r     s    
zFileList.graftc             C   s   t tjj|d}| j|jS )zFilter out files from 'dir/'.z**)r3   r!   r"   rh   r   r   )rO   r   r   r1   r1   r2   r     s    zFileList.prunec                sJ   | j dkr| j  ttjjd|  fdd| j D }| j| t|S )z
        Include all files anywhere in the current directory that match the
        pattern. This is very inefficient on large file trees.
        Nz**c                s   g | ]} j |r|qS r1   )r   )r   r   )r   r1   r2   r     s    z+FileList.global_include.<locals>.<listcomp>)allfilesr   r3   r!   r"   rh   r   r   )rO   r   r   r1   )r   r2   r     s    

zFileList.global_includec             C   s   t tjjd|}| j|jS )zD
        Exclude all files anywhere that match the pattern.
        z**)r3   r!   r"   rh   r   r   )rO   r   r   r1   r1   r2   r     s    zFileList.global_excludec             C   s8   |j dr|d d }t|}| j|r4| jj| d S )Nr   r   )r   r   
_safe_pathr   append)rO   itemr"   r1   r1   r2   r     s
    

zFileList.appendc             C   s   | j jt| j| d S )N)r   r   filterr   )rO   pathsr1   r1   r2   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)r_   r   r   r   )rO   r1   r1   r2   _repair  s    zFileList._repairc             C   s   d}t j|}|d kr(tjd|  dS t j|d}|d krNtj||d dS y tjj|shtjj|rldS W n& tk
r   tj||t	j
  Y nX d S )Nz!'%s' not %s encodable -- skippingz''%s' in unexpected encoding -- skippingFzutf-8T)unicode_utilsfilesys_decoder   rv   Z
try_encoder!   r"   ru   UnicodeEncodeErrorsysgetfilesystemencoding)rO   r"   Zenc_warnZu_pathZ	utf8_pathr1   r1   r2   r     s    
zFileList._safe_pathN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r1   r1   r1   r2   r   E  s   I

r   c               @   sP   e Zd Z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S )r   zMANIFEST.inc             C   s   d| _ d| _d| _d| _d S )Nr   )Zuse_defaultsr   Zmanifest_onlyZforce_manifest)rO   r1   r1   r2   rP     s    z!manifest_maker.initialize_optionsc             C   s   d S )Nr1   )rO   r1   r1   r2   rs     s    zmanifest_maker.finalize_optionsc             C   sd   t  | _tjj| js| j  | j  tjj| jr<| j	  | j
  | jj  | jj  | j  d S )N)r   r   r!   r"   ru   r   write_manifestadd_defaultstemplateZread_templateprune_file_listsortZremove_duplicates)rO   r1   r1   r2   r     s    

zmanifest_maker.runc             C   s   t j|}|jtjdS )N/)r   r   replacer!   r#   )rO   r"   r1   r1   r2   _manifest_normalize  s    
z"manifest_maker._manifest_normalizec                sB    j j   fdd j jD }d j } 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 | ]} j |qS r1   )r   )r   r   )rO   r1   r2   r   )  s    z1manifest_maker.write_manifest.<locals>.<listcomp>zwriting manifest file '%s'N)r   r   r   r   executert   )rO   r   msgr1   )rO   r2   r   !  s    

zmanifest_maker.write_manifestc             C   s   |j dstj| | d S )Nzstandard file not found:)
startswithr	   rv   )rO   r   r1   r1   r2   rv   -  s    
zmanifest_maker.warnc             C   st   t j|  | jj| j | jj| j tt }|rB| jj| nt	j
j| jrX| j  | jd}| jj|j d S )Nr4   )r	   r   r   r   r   r   r_   r
   r   r!   r"   ru   Zread_manifestget_finalized_commandr   r4   )rO   ZrcfilesZei_cmdr1   r1   r2   r   1  s    


zmanifest_maker.add_defaultsc             C   sZ   | j d}| jj }| jj|j | jj| tjtj	}| jj
d| d | dd d S )Nbuildz(^|z)(RCS|CVS|\.svn)r   )Zis_regex)r   rY   get_fullnamer   r   
build_baser$   r%   r!   r#   Zexclude_pattern)rO   r   base_dirr#   r1   r1   r2   r   =  s    

zmanifest_maker.prune_file_listN)r   r   r   r   rP   rs   r   r   r   rv   r   r   r1   r1   r1   r2   r     s   r   c          	   C   s8   dj |}|jd}t| d}|j| W d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.
    
zutf-8r|   N)rh   r   r   r   )rV   contentsr   r1   r1   r2   rt   G  s    

rt   c             C   s|   t jd| | jsx| jj}| j|j |_}| j|j |_}z|j	| j
 W d || |_|_X t| jdd }tj| j
| d S )Nz
writing %sZzip_safe)r   r}   r   rY   rj   rH   r]   rG   r   write_pkg_infor4   rR   r   Zwrite_safety_flag)cmdbasenamerV   rj   ZoldverZoldnamesafer1   r1   r2   r   T  s    r   c             C   s   t jj|rtjd d S )NzsWARNING: 'depends.txt' is not used by setuptools 0.6!
Use the install_requires/extras_require setup() args instead.)r!   r"   ru   r   rv   )r   r   rV   r1   r1   r2   warn_depends_obsoletef  s    r   c             C   s,   t |pf }dd }t||}| j| d S )Nc             S   s   | d S )Nr   r1   )r   r1   r1   r2   <lambda>p  s    z%_write_requirements.<locals>.<lambda>)r   r   
writelines)streamreqslinesZ	append_crr1   r1   r2   _write_requirementsn  s    
r   c             C   sn   | j }tj }t||j |jp"i }x2t|D ]&}|jdjf t	  t|||  q.W | j
d||j  d S )Nz
[{extra}]
requirements)rY   r   StringIOr   Zinstall_requiresextras_requiresortedr   formatvarsr{   getvalue)r   r   rV   distry   r   extrar1   r1   r2   write_requirementsu  s    
r   c             C   s*   t  }t|| jj | jd||j  d S )Nzsetup-requirements)r   r   rY   Zsetup_requiresr{   r   )r   r   rV   ry   r1   r1   r2   write_setup_requirements  s    r   c             C   s:   t jdd | jj D }| jd|djt|d  d S )Nc             S   s   g | ]}|j d dd qS ).r   r   )r    )r   kr1   r1   r2   r     s   z(write_toplevel_names.<locals>.<listcomp>ztop-level namesr   )rT   fromkeysrY   Ziter_distribution_namesrt   rh   r   )r   r   rV   pkgsr1   r1   r2   write_toplevel_names  s    r   c             C   s   t | ||d d S )NT)	write_arg)r   r   rV   r1   r1   r2   overwrite_arg  s    r  Fc             C   sH   t jj|d }t| j|d }|d k	r4dj|d }| j|||| d S )Nr   r   )r!   r"   splitextrR   rY   rh   r{   )r   r   rV   rz   Zargnamevaluer1   r1   r2   r     s
    r   c             C   s   | j j}t|tjs|d kr"|}nr|d k	rg }xZt|j D ]J\}}t|tjsttj||}dj	tt
t|j }|jd||f  q<W dj	|}| jd||d d S )Nr   z	[%s]
%s

r   zentry pointsT)rY   entry_pointsr\   r   string_typesr   itemsr   parse_grouprh   r   r   valuesr   r{   )r   r   rV   r   ry   sectionr   r1   r1   r2   write_entries  s    
r
  c              C   s^   t jdt tjjdrZtjd2} x*| D ]"}tj	d|}|r*t
|jdS q*W W dQ R X dS )zd
    Get a -r### off of PKG-INFO Version in case this is an sdist of
    a subversion revision.
    z$get_pkg_info_revision is deprecated.zPKG-INFOzVersion:.*-r(\d+)\s*$r   Nr   )r   rv   DeprecationWarningr!   r"   ru   ior   r$   r   intgroup)r   r   r   r1   r1   r2   get_pkg_info_revision  s    
r  )F)>__doc__distutils.filelistr   Z	_FileListZdistutils.errorsr   distutils.utilr   ra   r   r!   r$   r   r  r   r   rS   Zsetuptools.externr   Zsetuptools.extern.six.movesr   
setuptoolsr   Zsetuptools.command.sdistr	   r
   Zsetuptools.command.setoptr   Zsetuptools.commandr   pkg_resourcesr   r   r   r   r   r   r   r   Zsetuptools.unicode_utilsr   Zsetuptools.globr   Zpkg_resources.externr   Zsetuptools_svnr   ImportErrorr3   r4   r   rt   r   r   r   r   r   r   r  r   r
  r  r1   r1   r1   r2   <module>   sZ   (
R K AB

