
][\-G                 @   s   d  Z  d d l Z d d l Z d d l Z d d l Td 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 d d l m Z d d l Td d	 l m Z d d
 l
 m Z d d l m Z d d   Z Gd d   d e	  Z d S)zadistutils.command.sdist

Implements the Distutils 'sdist' command (create a source distribution).    N)*)glob)warn)Command)dir_utildep_util	file_utilarchive_util)TextFile)FileList)log)convert_pathc              C   s   d d l  m }  d d l m } g  } x6 | j   D]( } | j d | d | | d f  q3 W| j   |  |  j d  d S)zoPrint all possible values for the 'formats' option (used by
    the "--help-formats" command-line option).
    r   )FancyGetopt)ARCHIVE_FORMATSzformats=N   z.List of available source distribution formats:)Zdistutils.fancy_getoptr   Zdistutils.archive_utilr   keysappendsortZ
print_help)r   r   formatsformat r   -/usr/lib/python3.4/distutils/command/sdist.pyshow_formats   s    
r   c               @   sk  e  Z d  Z d Z d d   Z dM dN dO dP dQ dR dS dT dU d d d d f dV dW dX dY g Z d
 d d d d d" g Z d* d d+ e f g Z i d
 d 6d d 6Z	 i d, d- 6d. d/ 6Z
 d0 e f g Z d1 d2   Z d3 d4   Z d5 d6   Z d7 d8   Z d9 d:   Z d; d<   Z d= d>   Z d? d@   Z dA dB   Z dC dD   Z dE dF   Z dG dH   Z dI dJ   Z dK dL   Z d S)Zsdistz6create a source distribution (tarball, zip file, etc.)c             C   s   |  j  S)zYCallable used for the check sub-command.

        Placed here so user_options can view it)metadata_check)selfr   r   r   checking_metadata&   s    zsdist.checking_metadata	template=t5name of manifest template file [default: MANIFEST.in]	manifest=m)name of manifest file [default: MANIFEST]use-defaultsNRinclude the default file set in the manifest [default; disable with --no-defaults]no-defaults"don't include the default file setprunespecifically exclude files/directories that should not be distributed (build tree, RCS/CVS dirs, etc.) [default; disable with --no-prune]no-prune$don't automatically exclude anythingmanifest-onlyoEjust regenerate the manifest and then stop (implies --force-manifest)force-manifestfkforcibly regenerate the manifest and carry on as usual. Deprecated: now the manifest is always regenerated.formats=6formats 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]metadata-check[Ensure that all required elements of meta-data are supplied. Warn if any missing. [default]owner=u@Owner name used when creating a tar file [default: current user]group=gAGroup name used when creating a tar file [default: current group]zhelp-formatsz#list available distribution formatsZgztarposixzipntcheckc             C   sy   d  |  _  d  |  _ d |  _ d |  _ d |  _ d |  _ d  |  _ d |  _ d  |  _ d  |  _	 d |  _
 d  |  _ d  |  _ d  S)N   r   )templatemanifestuse_defaultsr'   manifest_onlyZforce_manifestr   	keep_tempdist_dirarchive_filesr   ownergroup)r   r   r   r   initialize_optionsd   s    												zsdist.initialize_optionsc             C   s   |  j  d  k r d |  _  n  |  j d  k r6 d |  _ n  |  j d  |  j d  k r y |  j t j g |  _ Wq t k
 r t d t j   Yq Xn  t	 j
 |  j  } | r t d |   n  |  j d  k r d |  _ n  d  S)NZMANIFESTzMANIFEST.inr   z<don't know how to create source distributions on platform %szunknown archive format '%s'Zdist)rE   rD   Zensure_string_listr   default_formatosnameKeyErrorZDistutilsPlatformErrorr	   Zcheck_archive_formatsZDistutilsOptionErrorrI   )r   Z
bad_formatr   r   r   finalize_options{   s$    zsdist.finalize_optionsc             C   sU   t    |  _ x! |  j   D] } |  j |  q W|  j   |  j rG d  S|  j   d  S)N)r   filelistZget_sub_commandsZrun_commandget_file_listrG   make_distribution)r   Zcmd_namer   r   r   run   s    
	z	sdist.runc             C   s7   t  d t  |  j j d  } | j   | j   d S)zDeprecated API.zadistutils.command.sdist.check_metadata is deprecated,               use the check command insteadrB   N)r   PendingDeprecationWarningdistributionZget_command_objZensure_finalizedrV   )r   rB   r   r   r   check_metadata   s
    

zsdist.check_metadatac             C   s   t  j j |  j  } | rP |  j   rP |  j   |  j j   |  j j   d S| sq |  j	 d d |  j  n  |  j j
   |  j r |  j   n  | r |  j   n  |  j r |  j   n  |  j j   |  j j   |  j   d S)aC  Figure out the list of files to include in the source
        distribution, and put it in 'self.filelist'.  This might involve
        reading the manifest template (and writing the manifest), or just
        reading the manifest, or just using the default file set -- it all
        depends on the user's options.
        Nz&manifest template '%s' does not exist z(using default file list))rO   pathisfilerD   _manifest_is_not_generatedread_manifestrS   r   Zremove_duplicatesr   findallrF   add_defaultsread_templater'   prune_file_listwrite_manifest)r   Ztemplate_existsr   r   r   rT      s(    
			zsdist.get_file_listc             C   s	  d |  j  j g } x | D] } t | t  r | } d } x: | D]2 } t j j |  rA d } |  j j |  PqA qA W| s |  j	 d d j
 |   q q t j j |  r |  j j |  q |  j	 d |  q Wd d	 g } x9 | D]1 } t t j j t |   } |  j j |  q W|  j d
  } |  j  j   rV|  j j | j    n  xM | j D]B \ }	 }
 } } x- | D]% } |  j j t j j
 |
 |   qyWq`W|  j  j   r`x |  j  j D] } t | t  rt |  } t j j |  rY|  j j |  qYq| \ } } x? | D]7 } t |  } t j j |  r|  j j |  qqWqWn  |  j  j   r|  j d  } |  j j | j    n  |  j  j   r|  j d  } |  j j | j    n  |  j  j   r|  j d  } |  j j | j    n  d S)a9  Add all the default files to self.filelist:
          - README or README.txt
          - setup.py
          - test/test*.py
          - all pure Python modules mentioned in setup script
          - all files pointed by package_data (build_py)
          - all files defined in data_files.
          - all files defined as scripts.
          - all C sources listed as part of extensions or C libraries
            in the setup script (doesn't catch C headers!)
        Warns if (README or README.txt) or setup.py are missing; everything
        else is optional.
        README
README.txtFTz,standard file not found: should have one of z, zstandard file '%s' not foundztest/test*.pyz	setup.cfgbuild_py	build_ext
build_clibbuild_scriptsN)rc   rd   )rX   Zscript_name
isinstancetuplerO   rZ   existsrS   r   r   joinfilterr[   r   extendget_finalized_commandZhas_pure_modulesZget_source_filesZ
data_filesZhas_data_filesstrr   Zhas_ext_modulesZhas_c_librariesZhas_scripts)r   Z	standardsfnZaltsZgot_itZoptionalpatternfilesre   ZpkgZsrc_dirZ	build_dir	filenamesfilenameitemdirnamer/   rf   rg   rh   r   r   r   r_      s\    	'zsdist.add_defaultsc             C   s   t  j d |  j  t |  j d d d d d d d d d d d d } z x | j   } | d	 k rh Pn  y |  j j |  WqL t t f k
 r } z% |  j	 d
 | j
 | j | f  WYd	 d	 } ~ XqL XqL Wd	 | j   Xd	 S)zRead and parse manifest template file named by self.template.

        (usually "MANIFEST.in") The parsing and processing is done by
        'self.filelist', which updates itself accordingly.
        zreading manifest template '%s'Zstrip_commentsrC   Zskip_blanksZ
join_linesZ	lstrip_wsZ	rstrip_wsZcollapse_joinNz%s, line %d: %s)r   inforD   r
   readlinerS   Zprocess_template_lineZDistutilsTemplateError
ValueErrorr   ru   Zcurrent_lineclose)r   rD   linemsgr   r   r   r`   (  s     	%zsdist.read_templatec             C   s   |  j  d  } |  j j   } |  j j d d | j |  j j d d | t j d k re d } n d } d d d	 d
 d d d g } d | d j |  | f } |  j j | d d d S)av  Prune off branches that might slip into the file list as created
        by 'read_template()', but really don't belong there:
          * the build tree (typically "build")
          * the release tree itself (only an issue if we ran "sdist"
            previously with --keep-temp, or it aborted)
          * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories
        buildNprefixZwin32z/|\\/ZRCSZCVSz\.svnz\.hgz\.gitz\.bzrZ_darcsz(^|%s)(%s)(%s).*|Zis_regexrC   )	ro   rX   get_fullnamerS   Zexclude_patternZ
build_basesysplatformrl   )r   r~   base_dirZsepsZvcs_dirsZvcs_ptrnr   r   r   ra   E  s    		zsdist.prune_file_listc             C   st   |  j    r$ t j d |  j  d S|  j j d d  } | j d d  |  j t j	 |  j | f d |  j  d S)zWrite the file list in 'self.filelist' (presumably as filled in
        by 'add_defaults()' and 'read_template()') to the manifest file
        named by 'self.manifest'.
        z5not writing to manually maintained manifest file '%s'Nr   z*# file GENERATED by distutils, do NOT editzwriting manifest file '%s')
r\   r   rx   rE   rS   rs   insertZexecuter   Z
write_file)r   Zcontentr   r   r   rb   ]  s    	zsdist.write_manifestc          
   C   sP   t  j j |  j  s d St |  j  } z | j   } Wd  | j   X| d k S)NFz+# file GENERATED by distutils, do NOT edit
)rO   rZ   r[   rE   openry   r{   )r   fpZ
first_liner   r   r   r\   l  s    z sdist._manifest_is_not_generatedc             C   sy   t  j d |  j  t |  j  } xF | D]> } | j   } | j d  s) | rW q) n  |  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'#N)	r   rx   rE   r   strip
startswithrS   r   r{   )r   rE   r|   r   r   r   r]   x  s    zsdist.read_manifestc             C   s   |  j  |  t j | | d |  j t t d  rH d } d | } n d } d | } | sn t j d  n t j |  x_ | D]W } t j	 j
 |  s t j d |  q t j	 j | |  } |  j | | d | q W|  j j j |  d S)	a  Create the directory tree that will become the source
        distribution archive.  All directories implied by the filenames in
        'files' are created under 'base_dir', and then we hard link or copy
        (if hard linking is unavailable) those files into place.
        Essentially, this duplicates the developer's source tree, but in a
        directory named after the distribution, containing only the files
        to be distributed.
        dry_runlinkZhardzmaking hard links in %s...Nzcopying files to %s...z)no files to distribute -- empty manifest?z#'%s' not a regular file -- skipping)Zmkpathr   Zcreate_treer   hasattrrO   r   r   rx   rZ   r[   rl   Z	copy_filerX   ZmetadataZwrite_pkg_info)r   r   rs   r   r}   filedestr   r   r   make_release_tree  s     	
zsdist.make_release_treec          
   C   s  |  j  j   } t j j |  j |  } |  j | |  j j  g  } d |  j	 k r} |  j	 j
 |  j	 j |  j	 j d    n  xd |  j	 D]Y } |  j | | d | d |  j d |  j } | j
 |  |  j  j j
 d d | f  q W| |  _ |  j st j | d |  j n  d S)	a  Create the source distribution(s).  First, we create the release
        tree with 'make_release_tree()'; then, we create all required
        archive files (according to 'self.formats') from the release tree.
        Finally, we clean up by blowing away the release tree (unless
        'self.keep_temp' is true).  The list of archive files created is
        stored so it can be retrieved later by 'get_archive_files()'.
        Ztarr   rK   rL   r    r   N)rX   r   rO   rZ   rl   rI   r   rS   rs   r   r   popindexZmake_archiverK   rL   Z
dist_filesrJ   rH   r   Zremove_treer   )r   r   Z	base_namerJ   Zfmtr   r   r   r   rU     s    
+ 		zsdist.make_distributionc             C   s   |  j  S)zzReturn the list of archive files created when the command
        was run, or None if the command hasn't run yet.
        )rJ   )r   r   r   r   get_archive_files  s    zsdist.get_archive_files)r   r   r   )r    r!   r"   )r#   Nr$   )r%   Nr&   )zpruneNr(   )r)   Nr*   )r+   r,   r-   )r.   r/   r0   )r1   Nr2   )r4   r5   r6   )r7   Nr8   )r9   r:   r;   )r<   r=   r>   )__name__
__module____qualname__Zdescriptionr   Zuser_optionsZboolean_optionsr   Zhelp_optionsZnegative_optrN   Zsub_commandsrM   rR   rV   rY   rT   r_   r`   ra   rb   r\   r]   r   rU   r   r   r   r   r   r   "   sn                	



(P*r   )__doc__rO   stringr   typesr   warningsr   Zdistutils.corer   Z	distutilsr   r   r   r	   Zdistutils.text_filer
   Zdistutils.errorsZdistutils.filelistr   r   Zdistutils.utilr   r   r   r   r   r   r   <module>   s   
"
