o
    ^+)h)K  ã                   @   s¸   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ dd„ ZG dd„ deƒZdS )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)ÚDistutilsOptionErrorÚDistutilsTemplateErrorc                  C   s`   ddl m}  ddlm} g }| ¡ D ]}| d| d|| d f¡ q| ¡  | |ƒ d¡ dS )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:)Zdistutils.fancy_getoptr   Zdistutils.archive_utilr   ÚkeysÚappendÚsortÚ
print_help)r   r   ÚformatsÚformat© r   úbC:\Users\User\Downloads\Proyecto_IoT\venv\Lib\site-packages\setuptools/_distutils/command/sdist.pyÚshow_formats   s   r   c                   @   s  e Zd ZdZdd„ Zg d¢Zg d¢ZdddefgZd	d
dœZ	defgZ
dZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Z d6d7„ Z!d8d9„ Z"dS ):Úsdistz6create a source distribution (tarball, zip file, etc.)c                 C   ó   | j S )zYCallable used for the check sub-command.

        Placed here so user_options can view it)Úmetadata_check©Úselfr   r   r   Úchecking_metadata'   ó   zsdist.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)ÚpruneNz‰specifically 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-onlyÚozEjust regenerate the manifest and then stop (implies --force-manifest))úforce-manifestÚfzkforcibly regenerate the manifest and carry on as usual. Deprecated: now the manifest is always regenerated.)r   Nz6formats for source distribution (comma-separated list))ú	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])úmetadata-checkNz[Ensure that all required elements of meta-data are supplied. Warn if any missing. [default])zowner=Úuz@Owner name used when creating a tar file [default: current user])zgroup=ÚgzAGroup name used when creating a tar file [default: current group])r$   r&   r(   r*   r,   r/   zhelp-formatsNz#list available distribution formatsr$   r&   )r%   r'   Úcheck)ZREADMEz
README.txtz
README.rstc                 C   sT   d | _ d | _d| _d| _d| _d| _dg| _d| _d | _d | _	d| _
d | _d | _d S )Né   r   Úgztar)ÚtemplateÚmanifestÚuse_defaultsr&   Úmanifest_onlyZforce_manifestr   Ú	keep_tempÚdist_dirÚarchive_filesr   ÚownerÚgroupr   r   r   r   Úinitialize_optionsz   s   
zsdist.initialize_optionsc                 C   s^   | j d u rd| _ | jd u rd| _|  d¡ t | j¡}|r#td| ƒ‚| jd u r-d| _d S d S )NZMANIFESTzMANIFEST.inr   zunknown archive format '%s'Údist)r6   r5   Zensure_string_listr   Zcheck_archive_formatsr   r   r:   )r   Z
bad_formatr   r   r   Úfinalize_options‘   s   




ÿzsdist.finalize_optionsc                 C   s>   t ƒ | _|  ¡ D ]}|  |¡ q|  ¡  | jrd S |  ¡  d S ©N)r	   ÚfilelistZget_sub_commandsÚrun_commandÚget_file_listr8   Úmake_distribution)r   Úcmd_namer   r   r   Úrun    s   z	sdist.runc                 C   s*   t dtƒ | j d¡}| ¡  | ¡  dS )zDeprecated API.zadistutils.command.sdist.check_metadata is deprecated,               use the check command insteadr2   N)r   ÚPendingDeprecationWarningÚdistributionZget_command_objZensure_finalizedrG   )r   r2   r   r   r   Úcheck_metadata¶   s   ýzsdist.check_metadatac                 C   s    t j | j¡}|s|  ¡ r|  ¡  | j ¡  | j ¡  dS |s'|  	d| j ¡ | j 
¡  | jr3|  ¡  |r9|  ¡  | jr@|  ¡  | j ¡  | j ¡  |  ¡  dS )aC  Figure 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Úisfiler5   Ú_manifest_is_not_generatedÚread_manifestrB   r   Úremove_duplicatesr   Úfindallr7   Úadd_defaultsÚread_templater&   Úprune_file_listÚwrite_manifest)r   Ztemplate_existsr   r   r   rD   Á   s,   

ÿÿ


zsdist.get_file_listc                 C   s<   |   ¡  |  ¡  |  ¡  |  ¡  |  ¡  |  ¡  |  ¡  dS )a9  Add 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   r   r   r   rR   ê   s   zsdist.add_defaultsc                 C   s:   t j | ¡sdS t j | ¡}t j |¡\}}|t  |¡v S )z±
        Case-sensitive path existence check

        >>> sdist._cs_path_exists(__file__)
        True
        >>> sdist._cs_path_exists(__file__.upper())
        False
        F)rK   rL   ÚexistsÚabspathÚsplitÚlistdir)Úfspathr^   Ú	directoryÚfilenamer   r   r   Ú_cs_path_exists   s
   
zsdist._cs_path_existsc                 C   s–   | j | jjg}|D ]?}t|tƒr5|}d}|D ]}|  |¡r'd}| j |¡  nq|s4|  dd 	|¡ ¡ q	|  |¡rA| j |¡ q	|  d| ¡ q	d S )NFTz,standard file not found: should have one of z, zstandard file '%s' not found)
ÚREADMESrI   Úscript_nameÚ
isinstanceÚtuplerd   rB   r   r   Újoin)r   Z	standardsÚfnZaltsZgot_itr   r   r   rV     s(   

ýÿ€
îzsdist._add_defaults_standardsc                 C   s4   ddg}|D ]}t tjjt|ƒƒ}| j |¡ qd S )Nztest/test*.pyz	setup.cfg)ÚfilterrK   rL   rM   r   rB   Úextend)r   ÚoptionalÚpatternÚfilesr   r   r   rW   '  s
   þzsdist._add_defaults_optionalc                 C   s\   |   d¡}| j ¡ r| j | ¡ ¡ |jD ]\}}}}|D ]}| j tj	 
||¡¡ qqd S )NÚbuild_py)Úget_finalized_commandrI   Zhas_pure_modulesrB   rl   Úget_source_filesÚ
data_filesr   rK   rL   ri   )r   rp   ÚpkgÚsrc_dirÚ	build_dirÚ	filenamesrc   r   r   r   rX   -  s   

ÿÿzsdist._add_defaults_pythonc                 C   s~   | j  ¡ r;| j jD ]3}t|tƒr!t|ƒ}tj |¡r | j	 
|¡ q	|\}}|D ]}t|ƒ}tj |¡r9| j	 
|¡ q'q	d S d S rA   )rI   Zhas_data_filesrs   rg   Ústrr   rK   rL   rM   rB   r   )r   ÚitemÚdirnamerw   r+   r   r   r   rY   =  s    

€€ýözsdist._add_defaults_data_filesc                 C   ó,   | j  ¡ r|  d¡}| j | ¡ ¡ d S d S )NÚ	build_ext)rI   Zhas_ext_modulesrq   rB   rl   rr   )r   r|   r   r   r   rZ   N  ó   

þzsdist._add_defaults_extc                 C   r{   )NÚ
build_clib)rI   Zhas_c_librariesrq   rB   rl   rr   )r   r~   r   r   r   r[   S  r}   zsdist._add_defaults_c_libsc                 C   r{   )NÚbuild_scripts)rI   Zhas_scriptsrq   rB   rl   rr   )r   r   r   r   r   r\   X  r}   zsdist._add_defaults_scriptsc              
   C   s¨   t  d| j¡ t| jddddddd}z;	 | ¡ }|du rn*z| j |¡ W n  ttfyF } z|  	d|j
|j|f ¡ W Y d}~nd}~ww qW | ¡  dS | ¡  w )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.
        zreading manifest template '%s'r3   )Zstrip_commentsZskip_blanksÚ
join_linesZ	lstrip_wsZ	rstrip_wsZcollapse_joinTNz%s, line %d: %s)r
   Úinfor5   r   ÚreadlinerB   Zprocess_template_liner   Ú
ValueErrorr   rc   Úcurrent_lineÚclose)r   r5   ÚlineÚmsgr   r   r   rS   ]  s8   ù
ÿÿ€ÿözsdist.read_templatec                 C   sz   |   d¡}| j ¡ }| jjd|jd | jjd|d tjdkr#d}nd}g d¢}d |d	 	|¡|¡}| jj|d
d dS )av  Prune 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)ÚprefixÚwin32z/|\\ú/)ÚRCSÚCVSz\.svnz\.hgz\.gitz\.bzrÚ_darcsz(^|{})({})({}).*ú|r3   )Zis_regex)
rq   rI   Úget_fullnamerB   Zexclude_patternZ
build_baseÚsysÚplatformr   ri   )r   rˆ   Úbase_dirÚsepsZvcs_dirsZvcs_ptrnr   r   r   rT     s   


zsdist.prune_file_listc                 C   sX   |   ¡ rt d| j ¡ dS | jjdd… }| dd¡ |  tj	| j|fd| j ¡ dS )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'Nr   z*# file GENERATED by distutils, do NOT editzwriting manifest file '%s')
rN   r
   r   r6   rB   ro   ÚinsertÚexecuter   Ú
write_file)r   Úcontentr   r   r   rU   ˜  s   ÿÿýzsdist.write_manifestc                 C   sB   t j | j¡s	dS t| jƒ}z| ¡ }W | ¡  |dkS | ¡  w )NFz+# file GENERATED by distutils, do NOT edit
)rK   rL   rM   r6   Úopenr‚   r…   )r   ÚfpÚ
first_liner   r   r   rN   ¬  s   


ÿz sdist._manifest_is_not_generatedc                 C   sl   t  d| j¡ t| jƒ }|D ]}| ¡ }| d¡s|sq| j |¡ qW d  ƒ dS 1 s/w   Y  dS )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.
        zreading manifest file '%s'ú#N)r
   r   r6   r™   ÚstripÚ
startswithrB   r   )r   r6   r†   r   r   r   rO   ¸  s   û"ÿzsdist.read_manifestc                 C   s®   |   |¡ tj||| jd ttdƒrd}d| }nd}d| }|s(t d¡ nt |¡ |D ]}tj	 
|¡s>t d|¡ q/tj	 ||¡}| j|||d	 q/| jj |¡ dS )
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ÚlinkZhardzmaking hard links in %s...Nzcopying files to %s...z)no files to distribute -- empty manifest?z#'%s' not a regular file -- skipping)r¡   )Zmkpathr   Zcreate_treer    ÚhasattrrK   r
   r   r   rL   rM   ri   Ú	copy_filerI   ÚmetadataZwrite_pkg_info)r   r“   ro   r¡   r‡   ÚfileÚdestr   r   r   Úmake_release_treeÆ  s    

	

zsdist.make_release_treec                 C   sº   | j  ¡ }tj | j|¡}|  || jj¡ g }d| j	v r*| j	 
| j	 | j	 d¡¡¡ | j	D ]}| j|||| j| jd}| 
|¡ | j j 
dd|f¡ q-|| _| js[tj|| jd dS dS )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()'.
        Útar)r“   r<   r=   r   Ú rŸ   N)rI   r   rK   rL   ri   r:   r§   rB   ro   r   r   ÚpopÚindexÚmake_archiver<   r=   Z
dist_filesr;   r9   r   Zremove_treer    )r   r“   Ú	base_namer;   Úfmtr¥   r   r   r   rE   ð  s    



ÿ
ÿzsdist.make_distributionc                 C   r   )zzReturn the list of archive files created when the command
        was run, or None if the command hasn't run yet.
        )r;   r   r   r   r   Úget_archive_files  r!   zsdist.get_archive_files)#Ú__name__Ú
__module__Ú__qualname__Údescriptionr    Zuser_optionsZboolean_optionsr   Zhelp_optionsZnegative_optZsub_commandsre   r>   r@   rG   rJ   rD   rR   Ústaticmethodrd   rV   rW   rX   rY   rZ   r[   r\   rS   rT   rU   rN   rO   r§   rE   r¯   r   r   r   r   r   #   sB    :

ÿ

)
$*r   )Ú__doc__rK   r‘   r   Úwarningsr   Zdistutils.corer   Ú	distutilsr   r   r   Zdistutils.text_filer   Zdistutils.filelistr	   r
   Zdistutils.utilr   Zdistutils.errorsr   r   r   r   r   r   r   r   Ú<module>   s     