o bc=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:)distutils.fancy_getoptrdistutils.archive_utilrkeysappendsort print_help)rrformatsformatr./usr/lib/python3.10/distutils/command/sdist.py show_formatss     rc@seZdZdZddZgdZgdZdddefgZd d d Z d efgZ d Z ddZ ddZ ddZddZddZddZeddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Z d6d7Z!d8d9Z"dS):sdistz6create a source distribution (tarball, zip file, etc.)cC|jS)zYCallable used for the check sub-command. Placed here so user_options can view it)metadata_checkselfrrrchecking_metadata(zsdist.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.r1z help-formatsNz#list available distribution formatsr&r()r'r)check)READMEz README.txtz README.rstcCsTd|_d|_d|_d|_d|_d|_dg|_d|_d|_d|_ d|_ d|_ d|_ dS)Nrgztar) templatemanifest use_defaultsr( manifest_onlyforce_manifestr keep_tempdist_dir archive_filesrownergroupr rrrinitialize_optionses zsdist.initialize_optionscCs^|jdurd|_|jdurd|_|dt|j}|r#td||jdur-d|_dSdS)NMANIFESTz MANIFEST.inrzunknown archive format '%s'dist)r9r8ensure_string_listrcheck_archive_formatsrr r>)r! bad_formatrrrfinalize_options|s      zsdist.finalize_optionscCs>t|_|D]}||q||jrdS|dSN)r filelistget_sub_commands run_command get_file_listr;make_distribution)r!cmd_namerrrruns   z sdist.runcCs*tdt|jd}||dS)zDeprecated API.zadistutils.command.sdist.check_metadata is deprecated, use the check command insteadr4N)rPendingDeprecationWarning distributionget_command_objensure_finalizedrP)r!r4rrrcheck_metadatas   zsdist.check_metadatacCstj|j}|s|r||j|jdS|s'| d|j|j |j r3| |r9| |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))ospathisfiler8_manifest_is_not_generated read_manifestrJrremove_duplicatesrfindallr: add_defaults read_templater(prune_file_listwrite_manifest)r!template_existsrrrrMs(       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_scriptsr rrrr]s zsdist.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)rVrWexistsabspathsplitlistdir)fspathrj directoryfilenamerrr_cs_path_existss  zsdist._cs_path_existscCs|j|jjg}|D]?}t|tr5|}d}|D]}||r'd}|j|nq|s4|dd |q ||rA|j|q |d|q dS)NFTz,standard file not found: should have one of z, zstandard file '%s' not found) READMESrR script_name isinstancetuplerprJrrjoin)r! standardsfnaltsgot_itrrrrbs(    zsdist._add_defaults_standardscCs4ddg}|D]}ttjjt|}|j|qdS)Nz test/test*.pyz setup.cfg)filterrVrWrXrrJextend)r!optionalpatternfilesrrrrcs zsdist._add_defaults_optionalcCs\|d}|jr|j||jD]\}}}}|D] }|jtj ||qqdS)Nbuild_py) get_finalized_commandrRhas_pure_modulesrJr{get_source_files data_filesrrVrWru)r!rpkgsrc_dir build_dir filenamesrorrrrds  zsdist._add_defaults_pythoncCs~|jr;|jjD]3}t|tr!t|}tj|r |j |q |\}}|D]}t|}tj|r9|j |q'q dSdSrI) rRhas_data_filesrrsstrr rVrWrXrJr)r!itemdirnamerr-rrrre$s       zsdist._add_defaults_data_filescC,|jr|d}|j|dSdS)N build_ext)rRhas_ext_modulesrrJr{r)r!rrrrrf5  zsdist._add_defaults_extcCr)N build_clib)rRhas_c_librariesrrJr{r)r!rrrrrg:rzsdist._add_defaults_c_libscCr)N build_scripts)rR has_scriptsrrJr{r)r!rrrrrh?rzsdist._add_defaults_scriptsc Cstd|jt|jddddddd}z; |}|durn*z|j|Wn ttfyF}z| d|j |j |fWYd}~nd}~wwqW| dS| w)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'r6)strip_comments skip_blanks join_lines lstrip_ws rstrip_ws collapse_joinTNz%s, line %d: %s) r infor8rreadlinerJprocess_template_liner ValueErrorrro current_lineclose)r!r8linemsgrrrr^Ds,   zsdist.read_templatecCsz|d}|j}|jjd|jd|jjd|dtjdkr#d}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)prefixwin32z/|\\/)RCSCVSz\.svnz\.hgz\.gitz\.bzr_darcsz(^|%s)(%s)(%s).*|r6)is_regex) rrR get_fullnamerJexclude_pattern build_basesysplatformru)r!rbase_dirsepsvcs_dirsvcs_ptrnrrrr_as   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') rYr rr9rJr~insertexecuter write_file)r!contentrrrr`ys zsdist.write_manifestcCsBtj|js dSt|j}z |}W||dkS|w)NFz+# file GENERATED by distutils, do NOT edit )rVrWrXr9openrr)r!fp first_linerrrrYs   z sdist._manifest_is_not_generatedcCsltd|jt|j }|D]}|}|ds|sq|j|qWddS1s/wYdS)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 rr9rstrip startswithrJr)r!r9rrrrrZs "zsdist.read_manifestcCs||tj|||jdttdrd}d|}nd}d|}|s(tdnt||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_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_treerhasattrrVr rrrWrXru copy_filerRmetadatawrite_pkg_info)r!rr~rrfiledestrrrmake_release_trees      zsdist.make_release_treecCs|j}tj|j|}|||jjg}d|j vr*|j |j |j d|j D]}|j ||||j|jd}| ||jj dd|fq-||_|js[tj||jddSdS)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)rr@rArrN)rRrrVrWrur>rrJr~rrpopindex make_archiver@rA dist_filesr?r=r remove_treer)r!r base_namer?fmtrrrrrNs     zsdist.make_distributioncCr)zzReturn the list of archive files created when the command was run, or None if the command hasn't run yet. )r?r rrrget_archive_filesr#zsdist.get_archive_files)#__name__ __module__ __qualname__ descriptionr" user_optionsboolean_optionsr help_options negative_opt sub_commandsrqrBrHrPrUrMr] staticmethodrprbrcrdrerfrgrhr^r_r`rYrZrrNrrrrrr$sJ' (  * r)__doc__rVrrwarningsrdistutils.corer distutilsrrrdistutils.text_filerdistutils.filelistr r distutils.utilr distutils.errorsr r rrrrrrs