
`@_A                 @   sU  d  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 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( y d d l) m* Z* Wn e+ k
 rYn XGd d   d e  Z, Gd d   d e  Z Gd d   d e  Z- d d   Z. d d   Z/ d d   Z0 d d   Z1 d d   Z2 d  d!   Z3 d" d#   Z4 d$ d%   Z5 d& d' d(  Z6 d) d*   Z7 d+ d,   Z8 d S)-zUsetuptools.command.egg_info

Create a distribution's .egg-info directory and contents    )FileList)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)	packaging)	svn_utilsc               @   s   e  Z d  Z d Z d. d/ d0 d1 d2 d3 g Z d d g Z d d d d i Z d d   Z d d   Z d d   Z	 d 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- S)4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]c             C   sU   d  |  _  d  |  _ d  |  _ d  |  _ d  |  _ d |  _ d |  _ d |  _ d  |  _ d  S)Nr   F)	egg_nameegg_versionegg_baser   	tag_buildtag_svn_revisiontag_datebroken_egg_infovtags)self r2   A/tmp/pip-build-tw3_dw7d/setuptools/setuptools/command/egg_info.pyinitialize_options9   s    								zegg_info.initialize_optionsc          	   C   s;   t  d t  d d d d d |  j     } t | |  d  S)Nr   r-   r   r.   r,   )dicttagsr
   )r1   filenamevaluesr2   r2   r3   save_version_infoD   s    zegg_info.save_version_infoc             C   s  t  |  j j    |  _ |  j   |  _ |  j   |  _ t |  j  } yK t	 | t
 j j  } | ri d n d } t t | |  j |  j f   Wn4 t k
 r t j j d |  j |  j f   Yn X|  j d  k r |  j j } | p i  j d t j  |  _ |  j d  t |  j  d |  _ |  j t j k rSt j j |  j |  j  |  _ d |  j k rl|  j   |  j |  j j _ |  j j } | d  k	 r| j  |  j j!   k r|  j | _" t |  j  | _# d  |  j _ d  S)Nz%s==%sz%s===%sz2Invalid distribution name or version syntax: %s-%s r+   z	.egg-info-)$r   distributionget_namer)   r6   r0   tagged_versionr*   r   
isinstancer   versionVersionlistr   
ValueError	distutilserrorsDistutilsOptionErrorr+   package_dirgetoscurdirensure_dirnamer   r   pathjoincheck_broken_egg_infometadataZ_patched_distkeylower_version_parsed_version)r1   parsed_versionZ
is_versionspecdirspdr2   r2   r3   finalize_optionsN   s8    !	
$zegg_info.finalize_optionsFc             C   si   | r |  j  | | |  nI t j j |  re | d k rX | rX 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_filerI   rL   existsr   warndelete_file)r1   whatr7   dataforcer2   r2   r3   write_or_delete_file}   s    	zegg_info.write_or_delete_filec             C   s^   t  j d | |  t j r+ | j d  } |  j sZ 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)r1   r]   r7   r^   fr2   r2   r3   rY      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   rb   re   rI   unlink)r1   r7   r2   r2   r3   r\      s    	zegg_info.delete_filec             C   sE   |  j  j   } |  j r4 | j |  j  r4 t |  St | |  j  S)N)r<   get_versionr0   endswithr   )r1   r@   r2   r2   r3   r>      s    
zegg_info.tagged_versionc             C   s   |  j  |  j  |  j j } xX t d  D]J } | j d |  | j   } | |  | j t j	 j
 |  j | j   q) Wt j	 j
 |  j d  } t j	 j |  r |  j |  |  j   d  S)Nzegg_info.writers	installerznative_libs.txt)mkpathr   r<   Zfetch_build_eggr   requireresolvenamerI   rL   rM   rZ   r\   find_sources)r1   rm   epwriternlr2   r2   r3   run   s    ,zegg_info.runc             C   sY   d } |  j  r | |  j  7} |  j r9 | d |  j   7} |  j rU | t j d  7} | S)Nr:   z-r%sz-%Y%m%d)r,   r-   get_svn_revisionr.   timestrftime)r1   r@   r2   r2   r3   r6      s    			zegg_info.tagsc               C   s2   d t    k r d St t j j t j  j    S)Nr   0)globalsstrr   ZSvnInfoloadrI   rJ   get_revisionr2   r2   r2   r3   rw      s    zegg_info.get_svn_revisionc             C   sJ   t  j j |  j d  } t |  j  } | | _ | j   | j |  _ d S)z"Generate SOURCES.txt manifest filezSOURCES.txtN)	rI   rL   rM   r   manifest_makerr<   manifestrv   filelist)r1   Zmanifest_filenamemmr2   r2   r3   rr      s
    	
zegg_info.find_sourcesc             C   s   |  j  d } |  j t j k r7 t j j |  j |  } t j j |  r t j d d d d d | |  j	  |  j	 |  _
 | |  _	 d  S)Nz	.egg-infor;   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.
)r)   r+   rI   rJ   rL   rM   rZ   r   r[   r   r/   )r1   Zbeir2   r2   r3   rN      s    zegg_info.check_broken_egg_infoN)r   r   r   )r   r   r   )r   r   r   )r    r!   r"   )r#   r$   r%   )r&   r'   r(   )__name__
__module____qualname__descriptionuser_optionsboolean_optionsnegative_optr4   r9   rX   r`   rY   r\   r>   rv   r6   staticmethodrw   rr   rN   r2   r2   r2   r3   r   &   s0     	
/
r   c               @   sF   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 S)r   z@File list that accepts only existing, platform-independent pathsc             C   sN   | j  d  r | d  d  } t |  } |  j |  rJ |  j j |  d  S)N   )rl   r   
_safe_pathfilesappend)r1   itemrL   r2   r2   r3   r      s
    zFileList.appendc             C   s    |  j  j t |  j |   d  S)N)r   extendfilterr   )r1   pathsr2   r2   r3   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)rB   r   r   r   )r1   r2   r2   r3   _repair   s    zFileList._repairc             C   s   d } t  j |  } | d  k r6 t j d |  d St  j | d  } | d  k rk t j | | d  d Sy, t j j |  s t j j |  r d SWn+ t k
 r t j | | t	 j
    Yn Xd  S)Nz!'%s' not %s encodable -- skippingz''%s' in unexpected encoding -- skippingFzutf-8T)unicode_utilsfilesys_decoder   r[   Z
try_encoderI   rL   rZ   UnicodeEncodeErrorsysgetfilesystemencoding)r1   rL   Zenc_warnZu_pathZ	utf8_pathr2   r2   r3   r      s    $zFileList._safe_pathN)r   r   r   __doc__r   r   r   r   r2   r2   r2   r3   r      s
   
r   c               @   s   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 d   Z d S)r   zMANIFEST.inc             C   s(   d |  _  d |  _ d |  _ d |  _ d  S)Nr   )Zuse_defaultsZpruneZmanifest_onlyZforce_manifest)r1   r2   r2   r3   r4     s    			z!manifest_maker.initialize_optionsc             C   s   d  S)Nr2   )r1   r2   r2   r3   rX     s    zmanifest_maker.finalize_optionsc             C   s   t    |  _ t j j |  j  s+ |  j   |  j j   |  j   t j j |  j	  ra |  j
   |  j   |  j j   |  j j   |  j   d  S)N)r   r   rI   rL   rZ   r   write_manifestfindalladd_defaultstemplateZread_templateprune_file_listsortZremove_duplicates)r1   r2   r2   r3   rv      s    



zmanifest_maker.runc             C   s"   t  j |  } | j t j d  S)N/)r   r   replacerI   sep)r1   rL   r2   r2   r3   _manifest_normalize-  s    z"manifest_maker._manifest_normalizec                sY     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 Sr2   )r   ).0ri   )r1   r2   r3   
<listcomp>9  s   	 z1manifest_maker.write_manifest.<locals>.<listcomp>zwriting manifest file '%s'N)r   r   r   r   executerY   )r1   r   msgr2   )r1   r3   r   1  s    zmanifest_maker.write_manifestc             C   s#   | j  d  s t j |  |  d  S)Nzstandard file not found:)
startswithr   r[   )r1   r   r2   r2   r3   r[   =  s    zmanifest_maker.warnc             C   s   t  j |   |  j j |  j  |  j j |  j  t t    } | r[ |  j j |  n t	 j
 j |  j  rz |  j   |  j d  } |  j d |  |  j j d d | j d  S)Nr   cmd*prefix)r   r   r   r   r   r   rB   r	   r   rI   rL   rZ   Zread_manifestget_finalized_command_add_egg_infoZinclude_patternr   )r1   ZrcfilesZei_cmdr2   r2   r3   r   A  s    
zmanifest_maker.add_defaultsc                s[     j  t j k r d St j j   j   }   f d d   | D } |  j j j |  d S)a  
        Add paths for egg-info files for an external egg-base.

        The egg-info files are written to egg-base. If egg-base is
        outside the current working directory, this method
        searchs the egg-base directory for files to include
        in the manifest. Uses distutils.filelist.findall (which is
        really the version monkeypatched in by setuptools/__init__.py)
        to perform the search.

        Since findall records relative paths, prefix the returned
        paths with cmd.egg_base, so add_default's include_pattern call
        (which is looking for the absolute cmd.egg_info) will match
        them.
        Nc             3   s'   |  ] } t  j j   j |  Vq d  S)N)rI   rL   rM   r+   )r   rL   )r   r2   r3   	<genexpr>c  s    z/manifest_maker._add_egg_info.<locals>.<genexpr>)r+   rI   rJ   rD   r   r   allfilesr   )r1   r   Z
discoveredZresolvedr2   )r   r3   r   N  s
    zmanifest_maker._add_egg_infoc             C   s   |  j  d  } |  j j   } |  j j d  d | j |  j j d  d | t j t j	  } |  j j d | d | d d d  S)Nbuildr   z(^|z)(RCS|CVS|\.svn)Zis_regexr   )
r   r<   get_fullnamer   Zexclude_pattern
build_basereescaperI   r   )r1   r   base_dirr   r2   r2   r3   r   f  s    zmanifest_maker.prune_file_listN)r   r   r   r   r4   rX   rv   r   r   r[   r   r   r   r2   r2   r2   r3   r     s   r   c          	   C   sH   d j  |  } | j d  } t |  d   } | j |  Wd QRXd S)z{Create a file with the specified name and write 'contents' (a
    sequence of strings without line terminators) to it.
    
zutf-8ra   N)rM   rd   rf   rg   )r7   contentsri   r2   r2   r3   rY   p  s    rY   c             C   s   t  j d |  |  j s |  j j } |  j | j | _ } |  j | j | _ } z | j	 |  j
  Wd  | | | _ | _ Xt |  j d d   } t j |  j
 |  d  S)Nz
writing %sZzip_safe)r   rb   re   r<   rO   r*   r@   r)   rq   write_pkg_infor   getattrr   Zwrite_safety_flag)r   basenamer7   rO   ZoldverZoldnamesafer2   r2   r3   r   }  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.)rI   rL   rZ   r   r[   )r   r   r7   r2   r2   r3   warn_depends_obsolete  s    r   c             C   s>   t  | p f   } d d   } t | |  } |  j |  d  S)Nc             S   s   |  d S)Nr   r2   )liner2   r2   r3   <lambda>  s    z%_write_requirements.<locals>.<lambda>)r   r   
writelines)streamreqslinesZ	append_crr2   r2   r3   _write_requirements  s    r   c             C   s   |  j  } t j   } t | | j  | j p1 i  } x> t |  D]0 } | j d j t	      t | | |  qA W|  j
 d | | j    d  S)Nz
[{extra}]
requirements)r<   r   StringIOr   Zinstall_requiresextras_requiresortedrg   formatvarsr`   getvalue)r   r   r7   distr^   r   extrar2   r2   r3   write_requirements  s    	r   c             C   s9   t    } t | |  j j  |  j d | | j    d  S)Nzsetup-requirements)r   r   r<   Zsetup_requiresr`   r   )r   r   r7   r^   r2   r2   r3   write_setup_requirements  s    	r   c             C   sO   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   )split)r   kr2   r2   r3   r     s   	z(write_toplevel_names.<locals>.<listcomp>ztop-level namesr   )r5   fromkeysr<   Ziter_distribution_namesrY   rM   r   )r   r   r7   pkgsr2   r2   r3   write_toplevel_names  s    	r   c             C   s   t  |  | | d  d  S)NT)	write_arg)r   r   r7   r2   r2   r3   overwrite_arg  s    r   Fc             C   sd   t  j j |  d } t |  j | d   } | d  k	 rJ d j |  d } |  j | | | |  d  S)Nr   r   )rI   rL   splitextr   r<   rM   r`   )r   r   r7   r_   Zargnamevaluer2   r2   r3   r     s
    r   c             C   s   |  j  j } t | t j  s* | d  k r3 | } n | d  k	 r g  } x t | j    D]k \ } } t | t j  s t j | |  } d j	 t t
 t | j      } | j d | | f  qX Wd j	 |  } |  j d | | d  d  S)Nr   z	[%s]
%s

r:   zentry pointsT)r<   entry_pointsr?   r   string_typesr   itemsr   parse_grouprM   r   r|   r8   r   r`   )r   r   r7   rs   r^   sectionr   r2   r2   r3   write_entries  s    	$r   c              C   s{   t  j d t  t j j d  rw t j d  C }  x9 |  D]1 } t j	 d |  } | r; t
 | j d   Sq; WWd QRXd 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   )warningsr[   DeprecationWarningrI   rL   rZ   iorf   r   matchintgroup)ri   r   r   r2   r2   r3   get_pkg_info_revision  s    r   )9r   distutils.filelistr   Z	_FileListdistutils.utilr   rD   r   Zdistutils.errorsrI   r   r   r   r   rx   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   pkg_resources.externr   Zsetuptools_svnr   ImportErrorr   r   rY   r   r   r   r   r   r   r   r   r   r   r2   r2   r2   r3   <module>   sN   :0\
