o
    Ee 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=Nz.List of available source distribution formats:)fancy_getoptr   r   r   keysappendsort
print_help)r   r   formatsformat r   d/var/www/bmteknikk.ddns.net/venv/lib/python3.10/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)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-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-   r0   zhelp-formatsNz#list available distribution formatsr%   r'   )r&   r(   check)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_onlyforce_manifestr   	keep_tempdist_dirarchive_filesr   ownergroupr   r   r   r   initialize_optionsy   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 )NMANIFESTzMANIFEST.inr   zunknown archive format '%s'dist)r8   r7   ensure_string_listr   check_archive_formatsr   r   r=   )r    
bad_formatr   r   r   finalize_options   s   




zsdist.finalize_optionsc                 C   s>   t  | _|  D ]}| | q|   | jrd S |   d S N)r
   filelistget_sub_commandsrun_commandget_file_listr:   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 insteadr3   N)r   PendingDeprecationWarningdistributionget_command_objensure_finalizedrO   )r    r3   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isfiler7   _manifest_is_not_generatedread_manifestrI   r   remove_duplicatesr   findallr9   add_defaultsread_templater'   prune_file_listwrite_manifest)r    template_existsr   r   r   rL      s,   




zsdist.get_file_listc                 C   s<   |    |   |   |   |   |   |   dS )aL  Add 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   r   r   r   r\      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)rU   rV   existsabspathsplitlistdir)fspathri   	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)
READMESrQ   script_name
isinstancetuplero   rI   r   r   join)r    	standardsfnaltsgot_itr   r   r   ra     s(   


zsdist._add_defaults_standardsc                 C   s4   g d}|D ]}t tjjt|}| j| qd S )N)ztests/test*.pyztest/test*.pyz	setup.cfg)filterrU   rV   rW   r   rI   extend)r    optionalpatternfilesr   r   r   rb   &  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_commandrQ   has_pure_modulesrI   rz   get_source_files
data_filesr   rU   rV   rt   )r    r~   pkgsrc_dir	build_dir	filenamesrn   r   r   r   rc   ,  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 rH   )rQ   has_data_filesr   rr   strr   rU   rV   rW   rI   r   )r    itemdirnamer   r,   r   r   r   rd   <  s    

zsdist._add_defaults_data_filesc                 C   ,   | j  r| d}| j|  d S d S )N	build_ext)rQ   has_ext_modulesr   rI   rz   r   )r    r   r   r   r   re   M     

zsdist._add_defaults_extc                 C   r   )N
build_clib)rQ   has_c_librariesr   rI   rz   r   )r    r   r   r   r   rf   R  r   zsdist._add_defaults_c_libsc                 C   r   )Nbuild_scripts)rQ   has_scriptsr   rI   rz   r   )r    r   r   r   r   rg   W  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 )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.
        zreading manifest template '%s'r5   )strip_commentsskip_blanks
join_lines	lstrip_ws	rstrip_wscollapse_joinTNz%s, line %d: %s)r   infor7   r	   readlinerI   process_template_liner   
ValueErrorr   rn   current_lineclose)r    r7   linemsgr   r   r   r]   \  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(^|{})({})({}).*|r5   )is_regex)
r   rQ   get_fullnamerI   exclude_pattern
build_basesysplatformr   rt   )r    r   base_dirsepsvcs_dirsvcs_ptrnr   r   r   r^     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 )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'Nr   z*# file GENERATED by distutils, do NOT editzwriting manifest file '%s')
rX   r   r   r8   rI   r}   insertexecuter   
write_file)r    contentr   r   r   r_     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
)rU   rV   rW   r8   openr   r   )r    fp
first_liner   r   r   rX     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 )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.
        zreading manifest file '%s'#N)r   r   r8   r   strip
startswithrI   r   )r    r8   r   r   r   r   rY     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link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   )mkpathr   create_treer   hasattrrU   r   warningr   rV   rW   rt   	copy_filerQ   metadatawrite_pkg_info)r    r   r}   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)rQ   r   rU   rV   rt   r=   r   rI   r}   r   r   popindexmake_archiver?   r@   
dist_filesr>   r<   r   remove_treer   )r    r   	base_namer>   fmtr   r   r   r   rM     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!   user_optionsboolean_optionsr   help_optionsnegative_optsub_commandsrp   rA   rG   rO   rT   rL   r\   staticmethodro   ra   rb   rc   rd   re   rf   rg   r]   r^   r_   rX   rY   r   rM   r   r   r   r   r   r   #   sB    :



)
$*r   )__doc__rU   r   r   warningsr   corer   	distutilsr   r   r   	text_filer	   rI   r
   distutils._logr   utilr   errorsr   r   r   r   r   r   r   r   <module>   s     