B Ìtè#Ñ<9ã@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ÚDistutilsOptionErrorcCsdddlm}ddlm}g}x,| ¡D] }| d|d||df¡q&W| ¡||ƒ d¡dS)zoPrint all possible values for the 'formats' option (used by the "--help-formats" command-line option). r)Ú FancyGetopt)ÚARCHIVE_FORMATSzformats=Néz.List of available source distribution formats:)Zdistutils.fancy_getoptrZdistutils.archive_utilrÚkeysÚappendÚsortZ print_help)rrÚformatsÚformat©rúd?„Zd@dA„ZdBdC„ZdDdE„Z dFdG„Z!dHdI„Z"dS)JÚsdistz6create a source distribution (tarball, zip file, etc.)cCs|jS)zYCallable used for the check sub-command. Placed here so user_options can view it)Úmetadata_check)ÚselfrrrÚchecking_metadata(szsdist.checking_metadata)z template=Útz5name of manifest template file [default: MANIFEST.in])z manifest=Úmz)name of manifest file [default: MANIFEST])z use-defaultsNzRinclude the default file set in the manifest [default; disable with --no-defaults])z no-defaultsNz"don't include the default file set)ÚpruneNz‰specifically exclude files/directories that should not be distributed (build tree, RCS/CVS dirs, etc.) [default; disable with --no-prune])zno-pruneNz$don't automatically exclude anything)z manifest-onlyÚozEjust regenerate the manifest and then stop (implies --force-manifest))zforce-manifestÚfzkforcibly regenerate the manifest and carry on as usual. Deprecated: now the manifest is always regenerated.)zformats=Nz6formats for source distribution (comma-separated list))z keep-tempÚkz@keep the distribution tree around after creating archive file(s))z dist-dir=ÚdzFdirectory to put the source distribution archive(s) in [default: dist])zmetadata-checkNz[Ensure that all required elements of meta-data are supplied. Warn if any missing. [default])zowner=Úuz@Owner name used when creating a tar file [default: current user])zgroup=ÚgzAGroup name used when creating a tar file [default: current group]z use-defaultsrz manifest-onlyzforce-manifestz keep-tempzmetadata-checkz help-formatsNz#list available distribution formats)z no-defaultszno-pruneÚcheck)ZREADMEz README.txtz README.rstcCsTd|_d|_d|_d|_d|_d|_dg|_d|_d|_d|_ d|_ d|_ d|_ dS)NérZgztar) ÚtemplateÚmanifestÚ use_defaultsrÚ manifest_onlyZforce_manifestrÚ keep_tempÚdist_dirÚ archive_filesrÚownerÚgroup)rrrrÚinitialize_optionseszsdist.initialize_optionscCsZ|jdkrd|_|jdkr d|_| d¡t |j¡}|rFtd|ƒ‚|jdkrVd|_dS)NZMANIFESTz MANIFEST.inrzunknown archive format '%s'Zdist)r)r(Zensure_string_listrZcheck_archive_formatsrr r-)rZ bad_formatrrrÚfinalize_options|s      zsdist.finalize_optionscCsBtƒ|_x| ¡D]}| |¡qW| ¡|jr6dS| ¡dS)N)r ÚfilelistZget_sub_commandsZ run_commandÚ get_file_listr+Úmake_distribution)rZcmd_namerrrÚrunŒsz 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_finalizedr6)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Úisfiler(Ú_manifest_is_not_generatedÚ read_manifestr3rZremove_duplicatesrÚfindallr*Ú add_defaultsÚ read_templaterÚprune_file_listÚwrite_manifest)rZtemplate_existsrrrr4ª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_scripts)rrrrr@Òszsdist.add_defaultscCs:tj |¡sdStj |¡}tj |¡\}}|t |¡kS)z± Case-sensitive path existence check >>> sdist._cs_path_exists(__file__) True >>> sdist._cs_path_exists(__file__.upper()) False F)r:r;ÚexistsÚabspathÚsplitÚlistdir)ÚfspathrLZ directoryÚfilenamerrrÚ_cs_path_existsès  zsdist._cs_path_existscCsœ|j|jjg}xˆ|D]€}t|tƒrn|}d}x(|D] }| |¡r0d}|j |¡Pq0W|s”| dd  |¡¡q| |¡r†|j |¡q| d|¡qWdS)NFTz,standard file not found: should have one of z, zstandard file '%s' not found) ÚREADMESr8Z script_nameÚ isinstanceÚtuplerQr3rrÚjoin)rZ standardsÚfnZaltsZgot_itrrrrDùs       zsdist._add_defaults_standardscCs8ddg}x*|D]"}ttjjt|ƒƒ}|j |¡qWdS)Nz test/test*.pyz setup.cfg)Úfilterr:r;r<rr3Úextend)rZoptionalÚpatternÚfilesrrrrEs zsdist._add_defaults_optionalcCsd| d¡}|j ¡r$|j | ¡¡x:|jD]0\}}}}x"|D]}|j tj   ||¡¡q>Wq,WdS)NÚbuild_py) Úget_finalized_commandr8Zhas_pure_modulesr3rXÚget_source_filesÚ data_filesrr:r;rU)rr[ZpkgZsrc_dirZ build_dirÚ filenamesrPrrrrFs    zsdist._add_defaults_pythoncCs‚|j ¡r~xr|jjD]f}t|tƒrDt|ƒ}tj |¡rz|j   |¡q|\}}x,|D]$}t|ƒ}tj |¡rR|j   |¡qRWqWdS)N) r8Zhas_data_filesr^rSÚstrr r:r;r<r3r)rÚitemÚdirnamer_r!rrrrG$s     zsdist._add_defaults_data_filescCs(|j ¡r$| d¡}|j | ¡¡dS)NÚ build_ext)r8Zhas_ext_modulesr\r3rXr])rrcrrrrH5s  zsdist._add_defaults_extcCs(|j ¡r$| d¡}|j | ¡¡dS)NÚ build_clib)r8Zhas_c_librariesr\r3rXr])rrdrrrrI:s  zsdist._add_defaults_c_libscCs(|j ¡r$| d¡}|j | ¡¡dS)NÚ build_scripts)r8Z has_scriptsr\r3rXr])rrerrrrJ?s  zsdist._add_defaults_scriptsc Cs¢t d|j¡t|jddddddd}zlxf| ¡}|dkr”s  zsdist.read_manifestcCs²| |¡tj|||jdttdƒr4d}d|}n d}d|}|sPt d¡n t |¡xD|D]<}tj   |¡s~t d|¡q`tj   ||¡}|j |||d q`W|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_treerzÚhasattrr:r rrfr;r<rUZ copy_filer8ZmetadataZwrite_pkg_info)rrsrZr{rkÚfileÚdestrrrÚmake_release_tree£s       zsdist.make_release_treecCsº|j ¡}tj |j|¡}| ||jj¡g}d|j krT|j   |j   |j   d¡¡¡xD|j D]:}|j ||||j|jd}|  |¡|jj  dd|f¡q\W||_|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)rsr/r0rÚ)rzN)r8rpr:r;rUr-rr3rZrrÚpopÚindexZ make_archiver/r0Z dist_filesr.r,rZ remove_treerz)rrsZ base_namer.Zfmtr}rrrr5Í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. )r.)rrrrÚget_archive_filesëszsdist.get_archive_files)#Ú__name__Ú __module__Ú __qualname__Z descriptionrZ user_optionsZboolean_optionsrZ help_optionsZ negative_optZ sub_commandsrRr1r2r6r9r4r@Ú staticmethodrQrDrErFrGrHrIrJrArBrCr=r>rr5rƒrrrrr$s^  (  *r)Ú__doc__r:rqrÚwarningsrZdistutils.corerZ distutilsrrrZdistutils.text_filerZdistutils.filelistr r Zdistutils.utilr Zdistutils.errorsr r rrrrrrÚs