a ÕDOg=Jã@s¸dZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd l m Z dd lmZdd lmZdd lmZdd lmZmZdd„ZGdd„deƒZdS)zadistutils.command.sdist Implements the Distutils 'sdist' command (create a source distribution).éN)Úglob)Úwarn)ÚCommand)Údir_util)Ú file_util)Ú archive_util)ÚTextFile)ÚFileList)Úlog)Ú convert_path)ÚDistutilsTemplateErrorÚDistutilsOptionErrorcCs`ddlm}ddlm}g}| ¡D] }| d|d||df¡q$| ¡||ƒ d¡dS)zoPrint all possible values for the 'formats' option (used by the "--help-formats" command-line option). r)Ú FancyGetopt)ÚARCHIVE_FORMATSúformats=Néz.List of available source distribution formats:)Zdistutils.fancy_getoptrZdistutils.archive_utilrÚkeysÚappendÚsortZ print_help)rrÚformatsÚformat©rútƒ|_| ¡D]}| |¡q| ¡|jr2dS| ¡dS©N)r ÚfilelistZget_sub_commandsZ run_commandÚ get_file_listr4Úmake_distribution)rZcmd_namerrrÚrunŒs  z sdist.runcCs*tdtƒ|j d¡}| ¡| ¡dS)zDeprecated API.zadistutils.command.sdist.check_metadata is deprecated, use the check command insteadr/N)rÚPendingDeprecationWarningÚ distributionZget_command_objZensure_finalizedr@)rr/rrrÚcheck_metadata¢s ÿ zsdist.check_metadatacCs tj |j¡}|s:| ¡r:| ¡|j ¡|j ¡dS|sN|  d|j¡|j  ¡|j rf|  ¡|rr|  ¡|jr€| ¡|j ¡|j ¡| ¡dS)aCFigure 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 (using default file list))ÚosÚpathÚisfiler1Ú_manifest_is_not_generatedÚ read_manifestr=rZremove_duplicatesrÚfindallr3Ú add_defaultsÚ read_templater#Úprune_file_listÚwrite_manifest)rZtemplate_existsrrrr>ªs(   þ   zsdist.get_file_listcCs<| ¡| ¡| ¡| ¡| ¡| ¡| ¡dS)a9Add 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. N)Ú_add_defaults_standardsÚ_add_defaults_optionalÚ_add_defaults_pythonÚ_add_defaults_data_filesÚ_add_defaults_extÚ_add_defaults_c_libsÚ_add_defaults_scriptsrrrrrJÒszsdist.add_defaultscCs:tj |¡sdStj |¡}tj |¡\}}|t |¡vS)z± Case-sensitive path existence check >>> sdist._cs_path_exists(__file__) True >>> sdist._cs_path_exists(__file__.upper()) False F)rDrEÚexistsÚabspathÚsplitÚlistdir)ÚfspathrVZ directoryÚfilenamerrrÚ_cs_path_existsès  zsdist._cs_path_existscCs–|j|jjg}|D]~}t|tƒrj|}d}|D]"}| |¡r,d}|j |¡qPq,|s| dd  |¡¡q| |¡r‚|j |¡q| d|¡qdS)NFTz,standard file not found: should have one of z, zstandard file '%s' not found) ÚREADMESrBZ script_nameÚ isinstanceÚtupler[r=rrÚjoin)rZ standardsÚfnZaltsZgot_itrrrrNùs"   ÿ zsdist._add_defaults_standardscCs4ddg}|D]"}ttjjt|ƒƒ}|j |¡q dS)Nz test/test*.pyz setup.cfg)ÚfilterrDrErFrr=Úextend)rZoptionalÚpatternÚfilesrrrrOszsdist._add_defaults_optionalcCs\| d¡}|j ¡r$|j | ¡¡|jD],\}}}}|D]}|j tj   ||¡¡q:q*dS)NÚbuild_py) Úget_finalized_commandrBZhas_pure_modulesr=rbÚget_source_filesÚ data_filesrrDrEr_)rreZpkgZsrc_dirZ build_dirÚ filenamesrZrrrrPs   zsdist._add_defaults_pythoncCsz|j ¡rv|jjD]b}t|tƒrBt|ƒ}tj |¡rt|j   |¡q|\}}|D]$}t|ƒ}tj |¡rN|j   |¡qNqdSr<) rBZhas_data_filesrhr]Ústrr rDrErFr=r)rÚitemÚdirnamerir(rrrrQ$s     zsdist._add_defaults_data_filescCs(|j ¡r$| d¡}|j | ¡¡dS)NÚ build_ext)rBZhas_ext_modulesrfr=rbrg)rrmrrrrR5s  zsdist._add_defaults_extcCs(|j ¡r$| d¡}|j | ¡¡dS)NÚ build_clib)rBZhas_c_librariesrfr=rbrg)rrnrrrrS:s  zsdist._add_defaults_c_libscCs(|j ¡r$| d¡}|j | ¡¡dS)NÚ build_scripts)rBZ has_scriptsrfr=rbrg)rrorrrrT?s  zsdist._add_defaults_scriptsc Cs¨t d|j¡t|jddddddd}zr| ¡}|dur:qŽz|j |¡Wq(ttfyŠ}z$|  d|j |j |f¡WYd}~q(d}~00q(W|  ¡n |  ¡0dS)zÈRead 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. zreading manifest template '%s'r0)Zstrip_commentsZ skip_blanksZ join_linesZ lstrip_wsZ rstrip_wsZ collapse_joinNz%s, line %d: %s) r Úinfor1rÚreadliner=Zprocess_template_liner Ú ValueErrorrrZZ current_lineÚclose)rr1ÚlineÚmsgrrrrKDs" þ þ"zsdist.read_templatecCsz| d¡}|j ¡}|jjd|jd|jjd|dtjdkrFd}nd}gd¢}d|d  |¡|f}|jj|d d dS) avPrune 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)ÚprefixZwin32z/|\\ú/)ZRCSZCVSz\.svnz\.hgz\.gitz\.bzrZ_darcsz(^|%s)(%s)(%s).*ú|r0)Zis_regex) rfrBÚ get_fullnamer=Zexclude_patternZ build_baseÚsysÚplatformr_)rrvÚbase_dirZsepsZvcs_dirsZvcs_ptrnrrrrLas   zsdist.prune_file_listcCsX| ¡rt d|j¡dS|jjdd…}| dd¡| tj |j|fd|j¡dS)z²Write 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'Nrz*# file GENERATED by distutils, do NOT editzwriting manifest file '%s') rGr rpr2r=rdÚinsertZexecuterZ write_file)rZcontentrrrrMysÿ ÿzsdist.write_manifestcCsDtj |j¡sdSt|jƒ}z| ¡}W| ¡n | ¡0|dkS)NFz+# file GENERATED by distutils, do NOT edit )rDrErFr2Úopenrqrs)rÚfpZ first_linerrrrGˆs  z sdist._manifest_is_not_generatedcCsjt d|j¡t|jƒ>}|D](}| ¡}| d¡s|s:q|j |¡qWdƒn1s\0YdS)zªRead 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. zreading manifest file '%s'ú#N)r rpr2rÚstripÚ startswithr=r)rr2rtrrrrH”s zsdist.read_manifestcCs®| |¡tj|||jdttdƒr4d}d|}n d}d|}|sPt d¡n t |¡|D]<}tj   |¡s|t d|¡q^tj   ||¡}|j |||d q^|j j |¡dS) 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ÚlinkZhardzmaking hard links in %s...Nzcopying files to %s...z)no files to distribute -- empty manifest?z#'%s' not a regular file -- skipping)r†)ZmkpathrZ create_treer…ÚhasattrrDr rrprErFr_Z copy_filerBÚmetadataZwrite_pkg_info)rr}rdr†ruÚfileÚdestrrrÚmake_release_tree¢s      zsdist.make_release_treecCs¶|j ¡}tj |j|¡}| ||jj¡g}d|j vrT|j   |j   |j   d¡¡¡|j D]:}|j ||||j|jd}|  |¡|jj  dd|f¡qZ||_|js²tj||jddS)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()'. Ztar)r}r8r9rÚr„N)rBrzrDrEr_r6r‹r=rdrrÚpopÚindexZ make_archiver8r9Z dist_filesr7r5rZ remove_treer…)rr}Z base_namer7Zfmtr‰rrrr?Ìs    ÿ zsdist.make_distributioncCs|jS)zzReturn the list of archive files created when the command was run, or None if the command hasn't run yet. )r7rrrrÚget_archive_filesêszsdist.get_archive_files)#Ú__name__Ú __module__Ú __qualname__Z descriptionrZ user_optionsZboolean_optionsrZ help_optionsZ negative_optZ sub_commandsr\r:r;r@rCr>rJÚ staticmethodr[rNrOrPrQrRrSrTrKrLrMrGrHr‹r?rrrrrr$sH'ÿÿÿ (  *r)Ú__doc__rDr{rÚwarningsrZdistutils.corerZ distutilsrrrZdistutils.text_filerZdistutils.filelistr r Zdistutils.utilr Zdistutils.errorsr r rrrrrrÚs