a
    ñ»jY;  ã                   @  sÞ   d dl mZ 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 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 )é    )Úannotations)Úpartial)Úglob)Úconvert_pathN)ÚPath)ÚIterableÚIteratoré   )Ú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   úAE:\soccer\ml_env\Lib\site-packages\setuptools/command/build_py.pyÚmake_writable   s    r   c                      s  e Zd ZU dZdZded< dZded< dd	„ Zd?‡ 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d@ddœ‡ fdd„Zd dœd!d"„Zd#dœd$d%„Zd#dœd&d'„Zd(d)„ Zd*d+„ Zd,d-d.d/œd0d1„Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ ZedAd=d>„ƒZ‡  ZS )BÚ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ÚboolÚeditable_modeNz
str | NoneÚexisting_egg_info_dirc                 C  s@   t j | ¡ | jj| _| jjp i | _d| jv r6| 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_optionsTé   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(   0   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   Zbuild_modulesZbuild_packagesÚbuild_package_dataÚbyte_compiler   r   Úget_outputsr"   r   r   r   ÚrunA   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   r9   Q   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*   Úcopiedr   r   r   r;   X   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_filesr3   r"   r   r   r   r8   ^   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    Ú
setdefaultrB   rC   rD   r3   r"   r   r   r   Úget_data_files_without_manifestc   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>u   s   ÿz0build_py._get_pkg_data_files.<locals>.<listcomp>)Úget_package_dirr   rI   ÚjoinÚ	build_libÚsplitÚfind_data_files)r#   r?   Ú	build_dirÚ	filenamesr   rM   r   rD   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_FILESrC   r   r   Ú	itertoolsÚchainÚfrom_iterableÚfilterr   rI   ÚisfilerE   ÚgetÚexclude_data_files)r#   r?   rN   ÚpatternsZglobs_expandedZglobs_matchesZ
glob_filesÚfilesr   r   r   rT   {   s    üþzbuild_py.find_data_filesz	list[str])Úreturnc                   s"   | j rt|  ¡  ¡ ƒS tƒ  |¡S )ú1See :class:`setuptools.commands.build.SubCommand`)r   rB   Úget_output_mappingÚkeysr'   r6   )r#   r1   r/   r   r   r6   �   s    zbuild_py.get_outputszdict[str, str]c                 C  s(   t  |  ¡ |  ¡ ¡}tt|dd„ d�ƒS )re   c                 S  s   | d S )Nr   r   )Úxr   r   r   Ú<lambda>™   ó    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   rf   “   s
    þzbuild_py.get_output_mappingzIterator[tuple[str, str]]c                 c  s<   |   ¡ D ].\}}}| d¡}|  | j||¡}||fV  qdS )z5Iterate over all modules producing (dest, src) pairs.rH   N)Zfind_all_modulesrS   Zget_module_outfilerR   )r#   r?   r=   r>   Úfilenamer   r   r   rm   ›   s    
zbuild_py._get_module_mappingc                 c  sH   | j D ]<\}}}}|D ]*}tj ||¡}tj ||¡}||fV  qqdS )z6Iterate over package data producing (dest, src) pairs.N)r   r   rI   rQ   )r#   r?   rN   rU   rV   rq   r   Úsrcfiler   r   r   rl   ¢   s
    z)build_py._get_package_data_output_mappingc                 C  s@   |   ¡ D ]2\}}|  tj |¡¡ |  ||¡\}}t|ƒ qdS )z$Copy data files into build directoryN)rl   Úmkpathr   rI   Údirnamer(   r   )r#   r   rr   Z_outfZ_copiedr   r   r   r4   ª   s    zbuild_py.build_package_datac                 C  sj  i  | _ }| jjsd S i }| jp"dD ]}||t|  |¡ƒ< q$t| dd ƒrzt| jdƒ 	¡ rz| 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 ||¡}qÎ|
|v r®||k�r.| |¡�rNq®n | ||
 |¡}|�rN| |¡ | ||
 g ¡ |	¡ q®d S )Nr   r   zSOURCES.txtzutf-8)ÚencodingÚegg_info)rE   r   Zinclude_package_datar3   Úassert_relativerP   Úgetattrr   r   ÚexistsÚ	read_textÚ
splitlinesÚrun_commandÚget_finalized_commandrv   Úfilelistrc   Ú_IncludePackageDataAbuseÚ_filter_build_filesr   rI   rS   rQ   Ú	is_moduleÚimportable_subpackageÚwarnrF   r<   )r#   ÚmfZsrc_dirsr?   Zegg_info_dirÚmanifestrc   Zei_cmdÚcheckrI   ÚdÚfÚprevZoldfZdfÚ
importabler   r   r   rA   ±   sD    

ÿþ




zbuild_py.analyze_manifestzIterable[str]r%   zIterator[str])rc   rv   rd   c                 #  sl   |   d¡}|| j|j|jf}dd„ |D ƒ}|D ]8}tj |¡‰ tj |¡r`t‡ fdd„|D ƒƒr.|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   rI   Únormpath)rK   Úpr   r   r   rO   æ   rj   z0build_py._filter_build_files.<locals>.<listcomp>c                 3  s   | ]}|ˆ vV  qd S r   r   )rK   r‡   ©Z	norm_pathr   r   Ú	<genexpr>ê   rj   z/build_py._filter_build_files.<locals>.<genexpr>N)	r}   rR   Ú
build_tempÚ
build_baser   rI   rŒ   ÚisabsÚall)r#   rc   rv   r‹   Z
build_dirsZ	norm_dirsrL   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0 tj | ||¡}|| j |< |rF| jjsJ|S | jjD ]}||ksl| |d ¡rR qvqR|S t|dƒ�}| 	¡ }W d  ƒ n1 sž0    Y  d|vrÂt
j d|f ¡‚|S )z8Check namespace packages' __init__ for declare_namespacerH   Ú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#   r?   Úpackage_dirZ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   rP   r   Zsrc_rootr   rI   rQ   )r#   r?   Úresr   r   r   rP     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^   ©rK   Úpattern)rc   r   r   r�   "  rj   z.build_py.exclude_data_files.<locals>.<genexpr>c                 3  s   | ]}|ˆ vr|V  qd S r   r   )rK   Úfn)Úbadr   r   r�   &  rj   )rB   rY   r   r[   r\   r]   Úsetr
   )r#   r?   rN   rc   rb   Zmatch_groupsÚmatchesZkeepersr   )r©   rc   r   ra     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   rI   rQ   r   r¦   rM   r   r   r�   7  s   ÿz2build_py._get_platform_patterns.<locals>.<genexpr>)r[   r\   r`   )Úspecr?   rN   rW   Zraw_patternsr   rM   r   rY   *  s    

ý
ýzbuild_py._get_platform_patterns)TTNr$   )T)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   r(   r7   r9   r;   r8   rG   rD   rT   r6   rf   rm   rl   r4   rA   r€   r”   r˜   r£   rP   ra   ÚstaticmethodrY   Ú__classcell__r   r   r/   r   r      s<   
	    ù
)r   c                 C  s:   t j | ¡s| S ddlm} t d¡ ¡ |  }||ƒ‚d S )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   rI   r’   Údistutils.errorsrµ   ÚtextwrapÚdedentÚlstrip)rI   rµ   Úmsgr   r   r   rw   >  s    ÿ
öÿrw   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°   Z_SUMMARYZ_DETAILSr   r   r   r   Ú_WarningV  s   r»   c                 C  s   t ƒ | _d S r   )rª   Ú_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#   rL   r   r   r   r�   „  s    z"_IncludePackageDataAbuse.is_modulec                 C  s6   t |ƒj}tt tj|j¡ƒ}|r2d |g|¢¡S d S )NrH   )	r   ÚparentrB   r[   Ú	takewhiler%   rÀ   ÚpartsrQ   )r#   rÁ   rL   r¡   rÃ   r   r   r   r‚   ‡  s
    
z._IncludePackageDataAbuse.importable_subpackagec                 C  s(   || j vr$| jj|d� | j  |¡ 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   S  s   +r   )Ú
__future__r   Ú	functoolsr   r   Údistutils.utilr   Zdistutils.command.build_pyÚcommandr   r   r   r¥   r·   r¶   r�   r[   r   Úpathlibr   Útypingr   r   Zextern.more_itertoolsr
   Úwarningsr   rZ   r   rw   r   r   r   r   r   Ú<module>   s*     %