o
    4ôj;  ã                   @   sâ   d dl 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
Z
d dlZd dlZd dlZd dlZd dlmZ d dlmZmZmZmZmZmZ ddlmZ dd	lmZ d
Zdd„ ZG dd„ dejƒZdd„ ZG dd„ dƒZ dS )é    )Úpartial)Úglob)Úconvert_pathN)ÚPath)ÚDictÚIterableÚIteratorÚListÚOptionalÚTupleé   )Úunique_everseen)ÚSetuptoolsDeprecationWarning)z*.pyizpy.typedc                 C   s   t  | t  | ¡jtjB ¡ d S ©N)ÚosÚchmodÚstatÚst_modeÚS_IWRITE)Útarget© r   ún/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/setuptools/command/build_py.pyÚmake_writable   s   r   c                       sH  e Zd ZU dZdZeed< dZee	 ed< dd„ Z
	d7‡ fd	d
„	Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd8dee	 f‡ fdd„Zdee	e	f fdd„Zdeee	e	f  fdd„Zdeee	e	f  fd d!„Zd"d#„ Zd$d%„ Zd&ee	 d'e	dee	 fd(d)„Zd*d+„ Zd,d-„ Z d.d/„ Z!d0d1„ Z"d2d3„ Z#e$d9d5d6„ƒ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.
    FÚeditable_modeNÚexisting_egg_info_dirc                 C   s@   t j | ¡ | jj| _| jjpi | _d| jv r| jd= g | _d S )NÚ
data_files)Úorigr   Úfinalize_optionsÚdistributionÚpackage_dataÚexclude_package_dataÚ__dict__Ú_build_py__updated_files©Úselfr   r   r   r   &   s   


zbuild_py.finalize_optionsé   c                    s:   |rt t|ƒ ¡ ƒ}t t|ƒ ¡ ƒ}tƒ  ||||||¡S r   )Ústrr   ÚresolveÚsuperÚ	copy_file)r%   ÚinfileÚoutfileÚpreserve_modeÚpreserve_timesÚlinkÚlevel©Ú	__class__r   r   r*   .   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 directoryNr   )Úinclude_bytecode)
Ú
py_modulesÚpackagesr   Zbuild_modulesZbuild_packagesÚbuild_package_dataÚbyte_compiler   r   Úget_outputsr$   r   r   r   Úrun9   s   zbuild_py.runc                 C   s&   |dkr|   ¡ | _| jS tj | |¡S )zlazily compute data filesr   )Ú_get_data_filesr   r   r   Ú__getattr__)r%   Úattrr   r   r   r;   I   s   
zbuild_py.__getattr__c                 C   s.   t j | |||¡\}}|r| j |¡ ||fS r   )r   r   Úbuild_moduler#   Úappend)r%   ÚmoduleÚmodule_fileÚpackager,   Zcopiedr   r   r   r=   P   s   zbuild_py.build_modulec                 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_filesr5   r$   r   r   r   r:   V   s   zbuild_py._get_data_filesc                 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"   Ú
setdefaultrC   rD   rE   r5   r$   r   r   r   Úget_data_files_without_manifest[   s   z(build_py.get_data_files_without_manifestc                    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>m   s    ÿÿz0build_py._get_pkg_data_files.<locals>.<listcomp>)Úget_package_dirr   rJ   ÚjoinÚ	build_libÚsplitÚfind_data_files)r%   rA   Ú	build_dirÚ	filenamesr   rN   r   rE   e   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_FILESrD   r   r   Ú	itertoolsÚchainÚfrom_iterableÚfilterr   rJ   ÚisfilerF   ÚgetÚexclude_data_files)r%   rA   rO   ÚpatternsZglobs_expandedZglobs_matchesZ
glob_filesÚfilesr   r   r   rU   s   s   üþzbuild_py.find_data_filesÚreturnc                    s"   | j rt|  ¡  ¡ ƒS tƒ  |¡S )ú1See :class:`setuptools.commands.build.SubCommand`)r   rC   Úget_output_mappingÚkeysr)   r8   )r%   r3   r1   r   r   r8   …   s   zbuild_py.get_outputsc                 C   s(   t  |  ¡ |  ¡ ¡}tt|dd„ d�ƒS )rf   c                 S   s   | d S )Nr   r   )Úxr   r   r   Ú<lambda>‘   s    z-build_py.get_output_mapping.<locals>.<lambda>)Úkey)r\   r]   Ú _get_package_data_output_mappingÚ_get_module_mappingÚdictÚsorted)r%   Úmappingr   r   r   rg   ‹   s
   þzbuild_py.get_output_mappingc                 c   s>   � |   ¡ D ]\}}}| d¡}|  | j||¡}||fV  qdS )z5Iterate over all modules producing (dest, src) pairs.rI   N)Zfind_all_modulesrT   Zget_module_outfilerS   )r%   rA   r?   r@   Úfilenamer   r   r   rm   “   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   rJ   rR   )r%   rA   rO   rV   rW   rq   r   Úsrcfiler   r   r   rl   š   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)rl   Úmkpathr   rJ   Údirnamer*   r   )r%   r   rr   Z_outfZ_copiedr   r   r   r6   ¢   s
   
ýzbuild_py.build_package_datac                 C   sp  i  | _ }| jjsd S i }| jpdD ]}||t|  |¡ƒ< qt| dd ƒr=t| jdƒ 	¡ r=| 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sq|
|v rµ||kr›| |¡ršqWn| ||
 |¡}|rª| |¡ | ||
 g ¡ |	¡ qWd S )Nr   r   zSOURCES.txtzutf-8)ÚencodingÚegg_info)rF   r   Úinclude_package_datar5   Úassert_relativerQ   Úgetattrr   r   ÚexistsÚ	read_textÚ
splitlinesÚrun_commandÚget_finalized_commandrv   Úfilelistrd   Ú_IncludePackageDataAbuseÚ_filter_build_filesr   rJ   rT   rR   Ú	is_moduleÚimportable_subpackageÚwarnrG   r>   )r%   ZmfZsrc_dirsrA   Zegg_info_dirÚmanifestrd   Úei_cmdÚcheckrJ   ÚdÚfÚprevZoldfZdfÚ
importabler   r   r   rB   ©   sL   

ÿþ


ý
ÿ
€ðzbuild_py.analyze_manifestrd   rv   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   rJ   Únormpath)rL   Úpr   r   r   rP   Þ   s    z0build_py._filter_build_files.<locals>.<listcomp>c                 3   s   � | ]}|ˆ vV  qd S r   r   )rL   rˆ   ©Z	norm_pathr   r   Ú	<genexpr>â   s   € z/build_py._filter_build_files.<locals>.<genexpr>N)	r~   rS   Ú
build_tempÚ
build_baser   rJ   r�   ÚisabsÚall)r%   rd   rv   rŒ   Z
build_dirsZ	norm_dirsrM   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rat
j d|f ¡‚|S )z8Check namespace packages' __init__ for declare_namespacerI   ÚrbNs   declare_namespacezÁNamespace package problem: %s 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%   rA   Úpackage_dirZinit_pyÚpkgr‰   Úcontentsr   r   r   r™   è   s0   ÿ
ÿ
ÿýÿ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   rQ   r   Úsrc_rootr   rJ   rR   )r%   rA   Úresr   r   r   rQ     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   )Úfnmatchr_   ©rL   Úpattern)rd   r   r   r�     ó   € z.build_py.exclude_data_files.<locals>.<genexpr>c                 3   s   � | ]	}|ˆ vr|V  qd S r   r   )rL   Úfn)Úbadr   r   r�     rª   )rC   rZ   r!   r\   r]   r^   Úsetr   )r%   rA   rO   rd   rc   Zmatch_groupsÚmatchesZkeepersr   )r¬   rd   r   rb     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   rJ   rR   r   r¨   rN   r   r   r�   /  s
   € ÿ
þz2build_py._get_platform_patterns.<locals>.<genexpr>)r\   r]   ra   )ÚspecrA   rO   rX   Zraw_patternsr   rN   r   rZ   "  s   

ý
ýzbuild_py._get_platform_patterns)r&   r&   Nr&   )r&   )r   )'Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r
   r'   r   r*   r9   r;   r=   r:   rH   rE   rU   r	   r8   r   rg   r   r   rm   rl   r6   rB   r   r�   r•   r™   r¤   rQ   rb   ÚstaticmethodrZ   Ú__classcell__r   r   r1   r   r      s8   
 		ÿ
)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   rJ   r“   Údistutils.errorsr¹   ÚtextwrapÚdedentÚlstrip)rJ   r¹   Úmsgr   r   r   rx   6  s   ÿ	öÿrx   c                   @   s@   e Zd ZdZG dd„ deƒZ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   Ú_WarningN  s    rÁ   c                 C   s   t ƒ | _d S r   )r­   Ú_already_warnedr$   r   r   r   Ú__init__y  s   z!_IncludePackageDataAbuse.__init__c                 C   s    |  d¡o|d tdƒ …  ¡ S )Nz.py)ÚendswithÚlenÚisidentifier)r%   rM   r   r   r   r‚   |  s    z"_IncludePackageDataAbuse.is_modulec                 C   s6   t |ƒj}tt tj|j¡ƒ}|rd |g|¢¡S d S )NrI   )	r   ÚparentrC   r\   Ú	takewhiler'   rÆ   ÚpartsrR   )r%   rÇ   rM   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.warnN)
r±   r²   r³   r´   r   rÁ   rÃ   r‚   rƒ   r„   r   r   r   r   r€   K  s    +r€   )!Ú	functoolsr   r   Údistutils.utilr   Zdistutils.command.build_pyÚcommandr   r   r   r§   r»   rº   rž   r\   r   Úpathlibr   Útypingr   r   r   r	   r
   r   Zextern.more_itertoolsr   Úwarningsr   r[   r   rx   r€   r   r   r   r   Ú<module>   s*       