_d KdZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd l m Z dd lmZdd lmZdd lmZddlmZmZdZGddeZy)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)DistutilsOptionErrorDistutilsTemplateErrorcddlm}ddlm}g}|j D]}|j d|zd||df!|j ||jdy)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:) fancy_getoptrr rkeysappendsort print_help)rrformatsformats E/usr/lib/python3/dist-packages/setuptools/_distutils/command/sdist.py show_formatsrsh+.G!&&(P V+T?63J13MNOP LLN##$TUceZdZdZdZgdZgdZdddefgZdd d Z d efgZ d Z d Z dZ dZdZdZdZedZdZdZdZdZdZdZdZdZdZdZdZdZd Z d!Z!d"Z"y)#sdistz6create a source distribution (tarball, zip file, etc.)c|jS)zYCallable used for the check sub-command. Placed here so user_options can view it)metadata_checkselfs rchecking_metadatazsdist.checking_metadata&s"""r))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/r2z help-formatsNz#list available distribution formatsr'r))r(r*check)READMEz README.txtz README.rstcd|_d|_d|_d|_d|_d|_dg|_d|_d|_d|_ d|_ d|_ d|_ y)Nrgztar) templatemanifest use_defaultsr) manifest_onlyforce_manifestr keep_tempdist_dir archive_filesr!ownergroupr"s rinitialize_optionszsdist.initialize_optionsysh   y  !  rc|jd|_|jd|_|jdtj|j }|rt d|z|jd|_yy)NMANIFESTz MANIFEST.inrzunknown archive format '%s'dist)r;r:ensure_string_listr check_archive_formatsrrr@)r# bad_formats rfinalize_optionszsdist.finalize_optionssp == &DM == )DM  *!77 E &'Dz'QR R == "DM !rct|_|jD]}|j||j |j ry|j yN)r filelistget_sub_commands run_command get_file_listr=make_distribution)r#cmd_names rrunz sdist.runs_!  --/ 'H   X & '       rctdt|jjd}|j |j y)zDeprecated API.zadistutils.command.sdist.check_metadata is deprecated, use the check command insteadr5N)rPendingDeprecationWarning distributionget_command_objensure_finalizedrT)r#r5s rcheck_metadatazsdist.check_metadatas?  - % !!11':   rctjj|j}|sU|j rE|j |j j|j jy|s|jd|jz|j j|jr|j|r|j|jr|j|j j|j j|j!y)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))ospathisfiler:_manifest_is_not_generated read_manifestrNrremove_duplicatesrfindallr< add_defaults read_templater)prune_file_listwrite_manifest)r#template_existss rrQzsdist.get_file_lists''..74#B#B#D    MM   MM + + -  IIW--               ::  "  '') rc|j|j|j|j|j |j |j y)aLAdd all the default files to self.filelist: - README or README.txt - setup.py - tests/test*.py and 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_scriptsr"s rrczsdist.add_defaultssX $$& ##% !!# %%'   !!# ""$rctjj|sytjj|}tjj |\}}|tj |vS)z Case-sensitive path existence check >>> sdist._cs_path_exists(__file__) True >>> sdist._cs_path_exists(__file__.upper()) False F)r\r]existsabspathsplitlistdir)fspathrr directoryfilenames r_cs_path_existszsdist._cs_path_existssTww~~f%''//&) ggmmG4 82::i000rc|j|jjg}|D]}t|trb|}d}|D]2}|j |sd}|j j|n|rQ|jddj|zu|j |r|j j||jd|zy)NFTz,standard file not found: should have one of z, zstandard file '%s' not found) READMESrW script_name isinstancetuplerxrNrrjoin)r# standardsfnaltsgot_its rrizsdist._add_defaults_standardss\\4#4#4#@#@A  CB"e$B++B/!% ,,R0  IIFSWX''+MM((,II>4=9E MM  ' (rcX|jd}|jjr)|jj |j |j D]G\}}}}|D];}|jjtjj||=Iy)Nbuild_py) get_finalized_commandrWhas_pure_modulesrNrget_source_files data_filesrr\r]r~)r#rpkgsrc_dir build_dir filenamesrws rrkzsdist._add_defaults_python,s--j9    - - / MM !:!:!< =3;2E2E F .C)Y% F $$RWW\\'8%DE F Frc|jjr|jjD]}t|trGt |}t jj|s>|jj|Z|\}}|D]H}t |}t jj|s.|jj|JyyrM) rWhas_data_filesrr|strr r\r]r^rNr)r#itemdirnamerr.s rrlzsdist._add_defaults_data_files<s    + + -))44 4dC('-Dww~~d+ ,,T2*.&GY&4(O77>>!, MM0034 4 .rc|jjr;|jd}|jj |j yy)N build_ext)rWhas_ext_modulesrrNrr)r#rs rrmzsdist._add_defaults_extMsD    , , .22;?I MM !;!;!= > /rc|jjr;|jd}|jj |j yy)N build_clib)rWhas_c_librariesrrNrr)r#rs rrnzsdist._add_defaults_c_libsRsD    , , .33LAJ MM ! ? /rc|jjr;|jd}|jj |j yy)N build_scripts)rW has_scriptsrrNrr)r#rs rrozsdist._add_defaults_scriptsWsD    ( ( * 66GM MM !?!?!A B +rc tjd|jt|jdddddd} |j }|n |j j |0 |jy#ttf$r5}|jd|j|j|fzYd}~Rd}~wwxYw#|jwxYw)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'r8)strip_comments skip_blanks join_lines lstrip_ws rstrip_ws collapse_joinNz%s, line %d: %s) r infor:r readlinerNprocess_template_liner ValueErrorrrw current_lineclose)r#r:linemsgs rrdzsdist.read_template\s 14==A MM  ((*< MM77=  NN  / ;II)#,,h.C.CSIJ NN s5CB.CC+C;CCCCc|jd}|jj}|jj d|j |jj d|t jdk(rd}nd}gd}dj|d j||}|jj |d y) 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)prefixwin32z/|\\/)RCSCVSz\.svnz\.hgz\.gitz\.bzr_darcsz(^|{})({})({}).*|r8)is_regex) rrW get_fullnamerNexclude_pattern build_basesysplatformrr~)r#rbase_dirsepsvcs_dirsvcs_ptrns rrezsdist.prune_file_lists**73$$113 %%d53C3C%D %%d8%< <<7 "DDR&--dCHHX4FM %%h%;rc4|jr#tjd|jzy|jj dd}|j dd|jtj|j|fd|jzy)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') r_r rr;rNrinsertexecuter write_file)r#contents rrfzsdist.write_manifests  * * , HH%'+}}5  --%%a(qFG  ]]G $ (4== 8 rctjj|jsyt |j} |j }|j |dk7S#|j wxYw)NFz+# file GENERATED by distutils, do NOT edit )r\r]r^r;openrr)r#fp first_lines rr_z sdist._manifest_is_not_generatedsYww~~dmm, $--  J HHJKKK HHJs A&&A8c&tjd|jt|j5}|D]A}|j }|j ds|s'|j j|C dddy#1swYyxYw)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 rr;rstrip startswithrNr)r#r;rs rr`zsdist.read_manifestsw -t}}= $--  +H  +zz|??3't $$T*  + + + +s ABBc.|j|tj|||jt t drd}d|z}nd}d|z}|st jdnt j||D]l}t jj|st jd|9t jj||}|j||| n|jjj|y) 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_runlinkhardzmaking hard links in %s...Nzcopying files to %s...z)no files to distribute -- empty manifest?z#'%s' not a regular file -- skipping)r)mkpathr create_treerhasattrr\r warningrr]r^r~ copy_filerWmetadatawrite_pkg_info)r#rrrrfiledests rmake_release_treezsdist.make_release_trees HXudllC 2v D.9CD*X5C KKC D HHSM 6D77>>$' A4Hww||Hd3tT5  6 ""11(;rc|jj}tjj |j |}|j ||jjg}d|jvrM|jj|jj|jjd|jD]e}|j||||j|j}|j||jj jdd|fg||_|j$s"t'j(||j*yy)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()'. tar)rrBrCrrN)rWrr\r]r~r@rrNrrrpopindex make_archiverBrC dist_filesrAr?r remove_treer)r#r base_namerAfmtrs rrRzsdist.make_distributions#$$113GGLL9  x)<)<= DLL LL   0 01C1CE1J K L<< EC$$34::%D   &    ( ( / /"d0C D  E+~~  4<< @rc|jS)zzReturn the list of archive files created when the command was run, or None if the command hasn't run yet. )rAr"s rget_archive_fileszsdist.get_archive_filess!!!r)#__name__ __module__ __qualname__ descriptionr$ user_optionsboolean_optionsr help_options negative_opt sub_commandsrzrDrKrTrZrQrc staticmethodrxrirjrkrlrmrnrordrerfr_r`rrRrrrrr#sJK# 8LtO DlSL$2wGL/01L4G. #!, 'R%,11 C,( F 4"? @ C "H<. ( L +("rr)__doc__r\rrwarningsrcorer distutilsrrr text_filer rNr distutils._logr utilr errorsrrrrrrrrsHL " A Vo"Go"r