U ,a=J@sdZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd l m Z dd lmZdd lmZdd lmZdd lmZmZddZGdddeZdS)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)DistutilsTemplateErrorDistutilsOptionErrorcCs`ddlm}ddlm}g}|D] }|d|d||dfq$|||ddS)zoPrint all possible values for the 'formats' option (used by the "--help-formats" command-line option). r) FancyGetopt)ARCHIVE_FORMATSformats=Nz.List of available source distribution formats:)Zdistutils.fancy_getoptrZdistutils.archive_utilrkeysappendsortZ print_help)rrformatsformatrd?Zd@dAZdBdCZdDdEZ dFdGZ!dHdIZ"dS)Jsdistz6create 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_checkselfrrrchecking_metadata(szsdist.checking_metadata)z template=tz5name of manifest template file [default: MANIFEST.in])z manifest=mz)name of manifest file [default: MANIFEST]) use-defaultsNzRinclude the default file set in the manifest [default; disable with --no-defaults]) no-defaultsNz"don't include the default file set)pruneNzspecifically exclude files/directories that should not be distributed (build tree, RCS/CVS dirs, etc.) [default; disable with --no-prune])no-pruneNz$don't automatically exclude anything) manifest-onlyozEjust regenerate the manifest and then stop (implies --force-manifest))force-manifestfzkforcibly regenerate the manifest and carry on as usual. Deprecated: now the manifest is always regenerated.)rNz6formats for source distribution (comma-separated list)) keep-tempkz@keep the distribution tree around after creating archive file(s))z dist-dir=dzFdirectory to put the source distribution archive(s) in [default: dist])metadata-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]r!r#r%r'r)r,z help-formatsNz#list available distribution formats)r"r$check)ZREADMEz README.txtz README.rstcCsTd|_d|_d|_d|_d|_d|_dg|_d|_d|_d|_ d|_ d|_ d|_ dS)NrZgztar) templatemanifest use_defaultsr# manifest_onlyZforce_manifestr keep_tempdist_dir archive_filesrownergrouprrrrinitialize_optionseszsdist.initialize_optionscCsZ|jdkrd|_|jdkr d|_|dt|j}|rFtd||jdkrVd|_dS)NZMANIFESTz MANIFEST.inrzunknown archive format '%s'Zdist)r2r1Zensure_string_listrZcheck_archive_formatsrr r6)rZ bad_formatrrrfinalize_options|s     zsdist.finalize_optionscCs>t|_|D]}||q||jr2dS|dSN)r filelistZget_sub_commandsZ run_command get_file_listr4make_distribution)rZcmd_namerrrruns  z sdist.runcCs*tdt|jd}||dS)zDeprecated API.zadistutils.command.sdist.check_metadata is deprecated, use the check command insteadr/N)rPendingDeprecationWarning distributionZget_command_objZensure_finalizedr@)rr/rrrcheck_metadatas  zsdist.check_metadatacCstj|j}|s:|r:||j|jdS|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))ospathisfiler1_manifest_is_not_generated read_manifestr=rZremove_duplicatesrfindallr3 add_defaults read_templater#prune_file_listwrite_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_scriptsrrrrrJszsdist.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)rDrEexistsabspathsplitlistdir)fspathrVZ directoryfilenamerrr_cs_path_existss  zsdist._cs_path_existscCs|j|jjg}|D]~}t|trj|}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 isinstancetupler[r=rrjoin)rZ standardsfnZaltsZgot_itrrrrNs"    zsdist._add_defaults_standardscCs4ddg}|D]"}ttjjt|}|j|q dS)Nz test/test*.pyz setup.cfg)filterrDrErFrr=extend)rZoptionalpatternfilesrrrrOszsdist._add_defaults_optionalcCs\|d}|jr$|j||jD],\}}}}|D]}|jtj ||q:q*dS)Nbuild_py) get_finalized_commandrBZhas_pure_modulesr=rbget_source_files data_filesrrDrEr_)rreZpkgZsrc_dirZ build_dir filenamesrZrrrrPs   zsdist._add_defaults_pythoncCsz|jrv|jjD]b}t|trBt|}tj|rt|j |q|\}}|D]$}t|}tj|rN|j |qNqdSr<) rBZhas_data_filesrhr]strr rDrErFr=r)ritemdirnamerir(rrrrQ$s     zsdist._add_defaults_data_filescCs(|jr$|d}|j|dS)N build_ext)rBZhas_ext_modulesrfr=rbrg)rrmrrrrR5s  zsdist._add_defaults_extcCs(|jr$|d}|j|dS)N build_clib)rBZhas_c_librariesrfr=rbrg)rrnrrrrS:s  zsdist._add_defaults_c_libscCs(|jr$|d}|j|dS)N build_scripts)rBZ has_scriptsrfr=rbrg)rrorrrrT?s  zsdist._add_defaults_scriptsc Cstd|jt|jddddddd}zh|}|dkr:qz|j|Wq(tt fk r}z| d|j |j |fW5d}~XYq(Xq(W5|XdS)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. zreading manifest template '%s'r0)Zstrip_commentsZ skip_blanksZ join_linesZ lstrip_wsZ rstrip_wsZ collapse_joinNz%s, line %d: %s) r infor1rclosereadliner=Zprocess_template_liner ValueErrorrrZZ current_line)rr1linemsgrrrrKDs&   zsdist.read_templatecCs|d}|j}|jjd|jd|jjd|dtjdkrFd}nd}ddd d d d d g}d|d||f}|jj|dddS)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_basesysplatformr_)rrvbase_dirZsepsZvcs_dirsZvcs_ptrnrrrrLas    zsdist.prune_file_listcCsX|rtd|jdS|jjdd}|dd|tj |j|fd|jdS)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'Nrz*# file GENERATED by distutils, do NOT editzwriting manifest file '%s') rGr rpr2r=rdinsertZexecuterZ write_file)rZcontentrrrrMys zsdist.write_manifestcCs<tj|jsdSt|j}z |}W5|X|dkS)NFz+# file GENERATED by distutils, do NOT edit )rDrErFr2openrqrr)rfpZ first_linerrrrGs   z sdist._manifest_is_not_generatedc CsVtd|jt|j4}|D](}|}|ds|s:q|j|qW5QRXdS)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. zreading manifest file '%s'#N)r rpr2rstrip startswithr=r)rr2rtrrrrHs zsdist.read_manifestcCs||tj|||jdttdr4d}d|}n d}d|}|sPtdn t||D]<}tj |s|td|q^tj ||}|j |||d q^|j j|dS) aCreate 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_runlinkZhardzmaking 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_treerhasattrrDr rrprErFr_Z copy_filerBZmetadataZwrite_pkg_info)rr}rdrrufiledestrrrmake_release_trees      zsdist.make_release_treecCs|j}tj|j|}|||jjg}d|j krT|j |j |j d|j D]:}|j ||||j|jd}| ||jj dd|fqZ||_|jstj||jddS)aCreate 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}r8r9rrN)rBrzrDrEr_r6rr=rdrrpopindexZ make_archiver8r9Z dist_filesr7r5rZ remove_treer)rr}Z base_namer7Zfmtrrrrr?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. )r7rrrrget_archive_filesszsdist.get_archive_files)#__name__ __module__ __qualname__Z descriptionrZ user_optionsZboolean_optionsrZ help_optionsZ negative_optZ sub_commandsr\r:r;r@rCr>rJ staticmethodr[rNrOrPrQrRrSrTrKrLrMrGrHrr?rrrrrr$sp' (  *r)__doc__rDr{rwarningsrZdistutils.corerZ distutilsrrrZdistutils.text_filerZdistutils.filelistr r Zdistutils.utilr Zdistutils.errorsr r rrrrrrs