
`@_                 @   s   d  d l  m  Z  d  d l m Z d  d l j j 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 Z d Z e Z d	 d
 d  Z Gd d   d e j  Z d S)    )glob)logN)six)cs_path_existsREADME
README.rst
README.txt c             c   s@   x9 t  j d  D]( } x | j   |   D] } | Vq) Wq Wd S)z%Find all files under revision controlzsetuptools.file_findersN)pkg_resourcesiter_entry_pointsload)dirnameepitem r   >/tmp/pip-build-tw3_dw7d/setuptools/setuptools/command/sdist.pywalk_revctrl   s    r   c               @   s   e  Z d  Z d Z d  d d d d f d! g Z i  Z d d   Z d d   Z e j	 d" k  p d# e j	 k ou d$ k  n p d% e j	 k o d& k  n Z
 e
 r e Z d d   Z d d   Z d d   Z d d   Z d d   Z d S)'sdistz=Smart sdist that finds anything supported by revision controlformats=N6formats for source distribution (comma-separated list)z	keep-tempkz1keep the distribution tree around after creating zarchive file(s)	dist-dir=dFdirectory to put the source distribution archive(s) in [default: dist]c             C   s   |  j  d  |  j d  } | j |  _ |  j j t j j | j d   |  j   x! |  j	   D] } |  j  |  qa Wd d  l
 } d | j j k r |  j   |  j   t |  j d g   } x9 |  j D]. } d d | f } | | k r | j |  q Wd  S)Negg_infozSOURCES.txtr   check
dist_filesr   r	   )run_commandget_finalized_commandfilelistappendospathjoinr   check_readmeget_sub_commandsdistutils.commandcommand__all__Zcheck_metadataZmake_distributiongetattrdistributionZarchive_files)selfZei_cmdcmd_name	distutilsr   filedatar   r   r   run)   s     "


z	sdist.runc          	   C   sR   y t  j j |   Wn7 t j   \ } } } | j j j d j     Yn Xd  S)Ntemplate)	origr   read_templatesysexc_infotb_nexttb_framef_localsclose)r+   _tbr   r   r   Z__read_template_hackC   s    zsdist.__read_template_hack         r         c                s6  t  |  j j g } x | D] } t | t  r | } d } x1 | D]) } t |  rA d } |  j j |  PqA W| s |  j d d j	 |   q t |  r |  j j |  q |  j d |  q Wd d g } x? | D]7 } t
 t t t |    } | r |  j j |  q W|  j j   r|  j d  } |  j j | j    |  j j sx@ | j D]5 \ }	   }	 }
 |  j j   f d	 d
   |
 D  q]W|  j j   r|  j d  } |  j j | j    |  j j   r|  j d  } |  j j | j    |  j j   r2|  j d  } |  j j | j    d  S)Nr   r?   z,standard file not found: should have one of z, zstandard file '%s' not foundztest/test*.pyz	setup.cfgbuild_pyc                s%   g  |  ] } t  j j   |   q Sr   )r!   r"   r#   ).0filename)src_dirr   r   
<listcomp>   s   	z&sdist.add_defaults.<locals>.<listcomp>	build_ext
build_clibbuild_scripts)READMESr*   script_name
isinstancetupler   r   r    warnr#   listfilterr   extendhas_pure_modulesr   Zget_source_filesZinclude_package_data
data_fileshas_ext_moduleshas_c_librarieshas_scripts)r+   Z	standardsfnZaltsZgot_itoptionalpatternfilesrA   r:   	filenamesrF   rG   rH   r   )rD   r   add_defaultsZ   sL    	zsdist.add_defaultsc             C   sE   x> t  D] } t j j |  r d  Sq W|  j d d j t    d  S)Nz,standard file not found: should have one of z, )rI   r!   r"   existsrM   r#   )r+   fr   r   r   r$      s    zsdist.check_readmec             C   s   t  j j |  | |  t j j | d  } t t d  ri t j j |  ri t j |  |  j	 d |  |  j
 d  j |  d  S)Nz	setup.cfglinkr   )r2   r   make_release_treer!   r"   r#   hasattrr\   unlink	copy_filer   Zsave_version_info)r+   base_dirrY   destr   r   r   r_      s    !zsdist.make_release_treec          	   C   sT   t  j j |  j  s d St j |  j d   } | j   } Wd  QRX| d j   k S)NFrbz+# file GENERATED by distutils, do NOT edit
)r!   r"   isfile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  j d |  j  t |  j d  } x | D] } t j rw y | j d  } Wn& t k
 rv t  j d |  w, Yn X| j	   } | j
 d  s, | r q, |  j j |  q, W| j   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'ZrbUzUTF-8z"%r not UTF-8 decodable -- skipping#N)r   inforg   ri   r   PY3decodeUnicodeDecodeErrorrM   strip
startswithr   r    r9   )r+   rg   liner   r   r   read_manifest   s    	zsdist.read_manifest)r   Nr   )r   r   r   )r<   r=   r<   )r>   r   )r>   r?   r@   )r>   r<   )r>   r<   r?   )__name__
__module____qualname____doc__user_optionsnegative_optr0   Z_sdist__read_template_hackr4   version_infoZhas_leaky_handler3   r[   r$   r_   rn   rw   r   r   r   r   r      s*     	5

r   )r   r   r   )r   r-   r   Zdistutils.command.sdistr'   r   r2   r!   r4   rh   Zsetuptools.externr   Zsetuptools.utilsr   r
   rI   rN   Z_default_revctrlr   r   r   r   r   <module>   s   