o
    5‘ðiÒ=  ã                   @  s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	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lmZ d	dlmZ d dlm  mZ d dlZ d dl!m"Z" dZ#ddd„Z$G dd„ dejƒZdd„ Z%G dd„ dƒZ&dS )é    )ÚannotationsN)ÚIterableÚIterator)Úpartial)Úglob)ÚPath)ÚAny)Úunique_everseené   )ÚStrPathÚStrPathT)ÚDistribution)ÚSetuptoolsDeprecationWarning)Úconvert_path)z*.pyizpy.typedÚreturnÚNonec                 C  s   t  | t  | ¡jtjB ¡ d S ©N)ÚosÚchmodÚstatÚst_modeÚS_IWRITE)Útarget© r   úZ/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/command/build_py.pyÚmake_writable   s   r   c                      s  e Zd ZU dZded< dZded< dZded	< dRdd„Z				dSdT‡ fdd„ZdRdd„Z	dUd"d#„Z
d$d%„ ZdVd'd(„ZdWd+d,„Zd-d.„ ZdXdY‡ fd1d2„ZdZd4d5„Zd[d7d8„Zd[d9d:„ZdRd;d<„ZdRd=d>„Zd\dCdD„ZdRdEdF„ZdGdH„ ZdIdJ„ Zd]dKdL„ZdMdN„ Zed^dPdQ„ƒZ‡  ZS )_Úbuild_pyaX  Enhanced 'build_py' command that includes data files with packages

    The data files are specified via a 'package_data' argument to 'setup()'.
    See 'setuptools.dist.Distribution' for more details.

    Also, this version of the 'build_py' command allows you to specify both
    'py_modules' and 'packages' in the same setup operation.
    r   ÚdistributionFÚboolÚeditable_modeNzStrPath | NoneÚexisting_egg_info_dirr   r   c                 C  s>   t j | ¡ | jj| _| jjpi | _d| jv r| jd= d S d S )NÚ
data_files)Úorigr   Úfinalize_optionsr   Úpackage_dataÚexclude_package_dataÚ__dict__©Úselfr   r   r   r#   .   s   

ÿzbuild_py.finalize_optionsTé   Úinfiler   Úoutfiler   Úpreserve_modeÚpreserve_timesÚlinkú
str | NoneÚlevelÚobjectútuple[StrPathT | str, bool]c                   s:   |rt t|ƒ ¡ ƒ}t t|ƒ ¡ ƒ}tƒ  ||||||¡S r   )Ústrr   ÚresolveÚsuperÚ	copy_file)r(   r*   r+   r,   r-   r.   r0   ©Ú	__class__r   r   r6   5   s   
ÿzbuild_py.copy_filec                 C  sT   | j s| jr	| jrdS | j r|  ¡  | jr|  ¡  |  ¡  |  tjj	| dd�¡ dS )z?Build modules, packages, and copy data files to build directoryNF)Úinclude_bytecode)
Ú
py_modulesÚpackagesr   Úbuild_modulesÚbuild_packagesÚbuild_package_dataÚbyte_compiler"   r   Úget_outputsr'   r   r   r   ÚrunF   s   zbuild_py.runÚattrr3   r   c                 C  s&   |dkr|   ¡ | _| jS tj | |¡S )zlazily compute data filesr!   )Ú_get_data_filesr!   r"   r   Ú__getattr__)r(   rB   r   r   r   rD   W   s   
zbuild_py.__getattr__c                 C  s   |   ¡  tt| j| jpdƒƒS )z?Generate list of '(package,src_dir,build_dir,filenames)' tuplesr   )Úanalyze_manifestÚlistÚmapÚ_get_pkg_data_filesr;   r'   r   r   r   rC   ^   s   zbuild_py._get_data_filesú%list[tuple[str, str, str, list[str]]]c                 C  s$   | j  di ¡ tt| j| jpdƒƒS )z¡
        Generate list of ``(package,src_dir,build_dir,filenames)`` tuples,
        but without triggering any attempt to analyze or build the manifest.
        Úmanifest_filesr   )r&   Ú
setdefaultrF   rG   rH   r;   r'   r   r   r   Úget_data_files_without_manifestc   s   z(build_py.get_data_files_without_manifestÚpackageútuple[str, str, str, list[str]]c                   sJ   |   |¡‰ tjj| jg| d¡ Ž }‡ fdd„|  |ˆ ¡D ƒ}|ˆ ||fS )NÚ.c                   s   g | ]	}t j |ˆ ¡‘qS r   )r   ÚpathÚrelpath)Ú.0Úfile©Úsrc_dirr   r   Ú
<listcomp>u   s    ÿÿz0build_py._get_pkg_data_files.<locals>.<listcomp>)Úget_package_dirr   rP   ÚjoinÚ	build_libÚsplitÚfind_data_files)r(   rM   Ú	build_dirÚ	filenamesr   rT   r   rH   m   s   


þzbuild_py._get_pkg_data_filesc                 C  sd   | j | j||td�}tttdd�|ƒ}tj |¡}t	t
jj|ƒ}t | j |g ¡|¡}|  |||¡S )z6Return filenames for package's data files in 'src_dir')Úextra_patternsT)Ú	recursive)Ú_get_platform_patternsr$   Ú_IMPLICIT_DATA_FILESrG   r   r   Ú	itertoolsÚchainÚfrom_iterableÚfilterr   rP   ÚisfilerJ   ÚgetÚexclude_data_files)r(   rM   rU   ÚpatternsÚglobs_expandedÚglobs_matchesÚ
glob_filesÚfilesr   r   r   r[   {   s   üþzbuild_py.find_data_filesr9   ú	list[str]c                   s"   | j rt|  ¡  ¡ ƒS tƒ  |¡S )ú1See :class:`setuptools.commands.build.SubCommand`)r   rF   Úget_output_mappingÚkeysr5   r@   )r(   r9   r7   r   r   r@   �   s   zbuild_py.get_outputsúdict[str, str]c                 C  s*   t  |  ¡ |  ¡ ¡}tt|t d¡d�ƒS )ro   r   )Úkey)rb   rc   Ú _get_package_data_output_mappingÚ_get_module_mappingÚdictÚsortedÚoperatorÚ
itemgetter)r(   Úmappingr   r   r   rp   “   s
   þzbuild_py.get_output_mappingúIterator[tuple[str, str]]c                 c  s>   � |   ¡ D ]\}}}| d¡}|  | j||¡}||fV  qdS )z5Iterate over all modules producing (dest, src) pairs.rO   N)Úfind_all_modulesrZ   Úget_module_outfilerY   )r(   rM   ÚmoduleÚmodule_fileÚfilenamer   r   r   ru   ›   s   €
ýzbuild_py._get_module_mappingc                 c  sJ   � | j D ]\}}}}|D ]}tj ||¡}tj ||¡}||fV  qqdS )z6Iterate over package data producing (dest, src) pairs.N)r!   r   rP   rX   )r(   rM   rU   r\   r]   r€   r   Úsrcfiler   r   r   rt   ¢   s   €ýÿz)build_py._get_package_data_output_mappingc                 C  s@   |   ¡ D ]\}}|  tj |¡¡ |  ||¡\}}t|ƒ qdS )z$Copy data files into build directoryN)rt   Úmkpathr   rP   Údirnamer6   r   )r(   r   r�   Ú_outfÚ_copiedr   r   r   r>   ª   s
   
ýzbuild_py.build_package_datac                 C  sh  i | _ | jjs	d S i }| jpdD ]}||t|  |¡ƒ< q| jr8t| jdƒ ¡ r8| j}t|dƒ}|j	dd� 
¡ }n|  d¡ |  d¡}|j}|jj}tƒ }|  ||¡D ]_}tj t|ƒ¡\}	}
d }|
}|	r‡|	|kr‡|	|vr‡|	}tj |	¡\}	}tj ||
¡}
|	r‡|	|kr‡|	|vsl|	|v r±|
|kr–| |
¡r•qRn| ||	 |
¡}|r¥| |¡ | j  ||	 g ¡ |¡ qRd S )Nr   zSOURCES.txtzutf-8)ÚencodingÚegg_info)rJ   r   Úinclude_package_datar;   Úassert_relativerW   r    r   ÚexistsÚ	read_textÚ
splitlinesÚrun_commandÚget_finalized_commandr‡   Úfilelistrm   Ú_IncludePackageDataAbuseÚ_filter_build_filesr   rP   rZ   rX   Ú	is_moduleÚimportable_subpackageÚwarnrK   Úappend)r(   Úsrc_dirsrM   Úegg_info_dirÚmanifestrm   Úei_cmdÚcheckrP   ÚdÚfÚprevÚoldfÚdfÚ
importabler   r   r   rE   ±   sL   ÿþ


ý
ÿ
€ðzbuild_py.analyze_manifestrm   úIterable[str]r‡   úIterator[str]c                 #  sn   � |   d¡}|| j|j|jf}dd„ |D ƒ}|D ]}tj |¡‰ tj |¡r1t‡ fdd„|D ƒƒr4|V  qdS )a}  
        ``build_meta`` may try to create egg_info outside of the project directory,
        and this can be problematic for certain plugins (reported in issue #3500).

        Extensions might also include between their sources files created on the
        ``build_lib`` and ``build_temp`` directories.

        This function should filter this case of invalid files out.
        Úbuildc                 S  s   g | ]
}|rt j |¡‘qS r   )r   rP   Únormpath)rR   Úpr   r   r   rV   è   s    z0build_py._filter_build_files.<locals>.<listcomp>c                 3  s   � | ]}|ˆ vV  qd S r   r   )rR   r›   ©Ú	norm_pathr   r   Ú	<genexpr>ì   s   € z/build_py._filter_build_files.<locals>.<genexpr>N)	rŽ   rY   Ú
build_tempÚ
build_baser   rP   r¤   ÚisabsÚall)r(   rm   r‡   r£   Ú
build_dirsÚ	norm_dirsrS   r   r¦   r   r‘   Ú   s   €
"€ýzbuild_py._filter_build_filesc                 C  s   d S r   r   r'   r   r   r   Úget_data_filesï   s   zbuild_py.get_data_filesc                 C  sÈ   z| j | W S  ty   Y nw tj | ||¡}|| j |< |r#| jjs%|S | jjD ]}||ks6| |d ¡r8 nq)|S t|dƒ�}| 	¡ }W d  ƒ n1 sOw   Y  d|vrbt
j d|› d�¡‚|S )z8Check namespace packages' __init__ for declare_namespacerO   ÚrbNs   declare_namespacezNamespace package problem: z¤ is a namespace package, but its
__init__.py does not call declare_namespace()! Please fix it.
(See the setuptools manual under "Namespace Packages" for details.)
")Úpackages_checkedÚKeyErrorr"   r   Úcheck_packager   Únamespace_packagesÚ
startswithÚopenÚreadÚ	distutilsÚerrorsÚDistutilsError)r(   rM   Úpackage_dirÚinit_pyÚpkgrœ   Úcontentsr   r   r   r³   ò   s,   ÿ
ÿ
ÿ
ÿzbuild_py.check_packagec                 C  s"   i | _ tj | ¡ d| _d | _d S )NF)r±   r"   r   Úinitialize_optionsr   r    r'   r   r   r   r¿     s   
zbuild_py.initialize_optionsc                 C  s0   t j | |¡}| jjd urtj | jj|¡S |S r   )r"   r   rW   r   Úsrc_rootr   rP   rX   )r(   rM   Úresr   r   r   rW     s   zbuild_py.get_package_dirc                   s\   t ˆƒ‰|  | j||¡}‡fdd„|D ƒ}tj |¡}t|ƒ‰ ‡ fdd„ˆD ƒ}t t|ƒƒS )z6Filter filenames for package's data files in 'src_dir'c                 3  s   � | ]	}t  ˆ |¡V  qd S r   )Úfnmatchre   ©rR   Úpattern)rm   r   r   r¨   $  ó   € z.build_py.exclude_data_files.<locals>.<genexpr>c                 3  s   � | ]	}|ˆ vr|V  qd S r   r   )rR   Úfn)Úbadr   r   r¨   (  rÅ   )rF   r`   r%   rb   rc   rd   Úsetr	   )r(   rM   rU   rm   ri   Úmatch_groupsÚmatchesÚkeepersr   )rÇ   rm   r   rh     s   ýzbuild_py.exclude_data_filesr   c                   s0   t  ||  dg ¡|  |g ¡¡}‡ fdd„|D ƒS )zÜ
        yield platform-specific path patterns (suitable for glob
        or fn_match) from a glob-based spec (such as
        self.package_data or self.exclude_package_data)
        matching package in src_dir.
        Ú c                 3  s"   � | ]}t j ˆ t|ƒ¡V  qd S r   )r   rP   rX   r   rÃ   rT   r   r   r¨   9  s
   € ÿ
þz2build_py._get_platform_patterns.<locals>.<genexpr>)rb   rc   rg   )ÚspecrM   rU   r^   Úraw_patternsr   rT   r   r`   ,  s   

ý
ýzbuild_py._get_platform_patterns©r   r   )TTNr)   )r*   r   r+   r   r,   r   r-   r   r.   r/   r0   r1   r   r2   )rB   r3   r   r   )r   rI   )rM   r3   r   rN   )T)r9   r   r   rn   )r   rr   )r   r{   )rm   r¡   r‡   r   r   r¢   )rM   r3   r   r3   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r    r#   r6   rA   rD   rC   rL   rH   r[   r@   rp   ru   rt   r>   rE   r‘   r¯   r³   r¿   rW   rh   Ústaticmethodr`   Ú__classcell__r   r   r7   r   r       s>   
 	
ù










)

r   c                 C  s6   t j | ¡s| S ddlm} t d¡ ¡ |  }||ƒ‚)Nr   )ÚDistutilsSetupErrorzÓ
        Error: setup script specifies an absolute path:

            %s

        setup() arguments must *always* be /-separated paths relative to the
        setup.py directory, *never* absolute paths.
        )r   rP   r«   Údistutils.errorsr×   ÚtextwrapÚdedentÚlstrip)rP   r×   Úmsgr   r   r   r‰   @  s   ÿ	öÿr‰   c                   @  sB   e Zd ZdZG dd„ deƒZddd„Zdd	„ Zd
d„ Zdd„ Z	dS )r�   z>Inform users that package or module is included as 'data file'c                   @  s   e Zd ZdZdZdS )z!_IncludePackageDataAbuse._WarningzU
        Package {importable!r} is absent from the `packages` configuration.
        a|  
        ############################
        # Package would be ignored #
        ############################
        Python recognizes {importable!r} as an importable package[^1],
        but it is absent from setuptools' `packages` configuration.

        This leads to an ambiguous overall configuration. If you want to distribute this
        package, please make sure that {importable!r} is explicitly added
        to the `packages` configuration field.

        Alternatively, you can also rely on setuptools' discovery methods
        (for example by using `find_namespace_packages(...)`/`find_namespace:`
        instead of `find_packages(...)`/`find:`).

        You can read more about "package discovery" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/package_discovery.html

        If you don't want {importable!r} to be distributed and are
        already explicitly excluding {importable!r} via
        `find_namespace_packages(...)/find_namespace` or `find_packages(...)/find`,
        you can try to use `exclude_package_data`, or `include-package-data=False` in
        combination with a more fine grained `package-data` configuration.

        You can read more about "package data files" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/datafiles.html


        [^1]: For Python, any directory (with suitable naming) can be imported,
              even if it does not contain any `.py` files.
              On the other hand, currently there is no concept of package data
              directory, all directories are treated like packages.
        N)rÐ   rÑ   rÒ   Ú_SUMMARYÚ_DETAILSr   r   r   r   Ú_WarningX  s    rß   r   r   c                 C  s   t t ƒ | _d S r   )rÈ   r3   Ú_already_warnedr'   r   r   r   Ú__init__ƒ  s   z!_IncludePackageDataAbuse.__init__c                 C  s    |  d¡o|d tdƒ …  ¡ S )Nz.py)ÚendswithÚlenÚisidentifier)r(   rS   r   r   r   r’   †  s    z"_IncludePackageDataAbuse.is_modulec                 C  s6   t |ƒj}tt tj|j¡ƒ}|rd |g|¢¡S d S )NrO   )	r   ÚparentrF   rb   Ú	takewhiler3   rä   ÚpartsrX   )r(   rå   rS   r½   rç   r   r   r   r“   ‰  s
   
z._IncludePackageDataAbuse.importable_subpackagec                 C  s,   || j vr| jj|d� | j  |¡ d S d S )N)r    )rà   rß   ÚemitÚadd)r(   r    r   r   r   r”   �  s   
þz_IncludePackageDataAbuse.warnNrÏ   )
rÐ   rÑ   rÒ   rÓ   r   rß   rá   r’   r“   r”   r   r   r   r   r�   U  s    
+r�   rÏ   )'Ú
__future__r   rÂ   rb   rx   r   r   rÙ   Úcollections.abcr   r   Ú	functoolsr   r   Úpathlibr   Útypingr   Úmore_itertoolsr	   Ú_pathr   r   Údistr   Úwarningsr   Údistutils.command.build_pyÚcommandr   r"   rØ   r¸   Údistutils.utilr   ra   r   r‰   r�   r   r   r   r   Ú<module>   s4    
  "