U
    aÊ¹jÁ<  ã                   @  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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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„ Z G dd„ dejƒZdd„ Z!G dd„ dƒZ"dS )é    )ÚannotationsN)Úpartial)Úglob)ÚPath)ÚIterableÚIterator)Úunique_everseen)ÚStrPathé   )ÚDistribution)ÚSetuptoolsDeprecationWarning)Úconvert_path)z*.pyizpy.typedc                 C  s   t  | t  | ¡jtjB ¡ d S ©N)ÚosÚchmodÚstatÚst_modeÚS_IWRITE)Útarget© r   úZ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/setuptools/command/build_py.pyÚmake_writable   s    r   c                      s2  e Zd ZU dZded< dZded< dZded	< d
d„ ZdFdddddddœ‡ fdd„Zdd„ Z	ddœdd„Z
dd„ Zdd„ Zdd„ Zdd „ Zd!d"„ ZdGdd#d$œ‡ fd%d&„Zd'd(œd)d*„Zd+d(œd,d-„Zd+d(œd.d/„Zd0d1„ Zd2d3„ Zd4dd5d6œd7d8„Zd9d:„ Zd;d<„ Zd=d>„ Zd?d@„ ZdAdB„ ZedHdDdE„ƒZ‡  ZS )IÚ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
str | NoneÚexisting_egg_info_dirc                 C  s@   t j | ¡ | jj| _| jjp i | _d| jkr6| jd= g | _d S )NÚ
data_files)Úorigr   Úfinalize_optionsr   Úpackage_dataÚexclude_package_dataÚ__dict__Ú_build_py__updated_files©Úselfr   r   r   r   -   s    

zbuild_py.finalize_optionsTé   r	   Úobject)ÚinfileÚoutfileÚpreserve_modeÚpreserve_timesÚlinkÚlevelc                   s:   |r$t t|ƒ ¡ ƒ}t t|ƒ ¡ ƒ}tƒ  ||||||¡S r   )Ústrr   ÚresolveÚsuperÚ	copy_file)r%   r(   r)   r*   r+   r,   r-   ©Ú	__class__r   r   r1   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   Zbuild_modulesZbuild_packagesÚbuild_package_dataÚbyte_compiler   r   Úget_outputsr$   r   r   r   ÚrunF   s    zbuild_py.runr.   )Úattrc                 C  s&   |dkr|   ¡ | _| jS tj | |¡S )zlazily compute data filesr   )Ú_get_data_filesr   r   r   Ú__getattr__)r%   r;   r   r   r   r=   V   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>   ]   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_filesr6   r$   r   r   r   r<   c   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"   Ú
setdefaultrE   rF   rG   r6   r$   r   r   r   Úget_data_files_without_manifesth   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>z   s   ÿz0build_py._get_pkg_data_files.<locals>.<listcomp>)Úget_package_dirr   rL   ÚjoinÚ	build_libÚsplitÚfind_data_files)r%   rB   Ú	build_dirÚ	filenamesr   rP   r   rG   r   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_FILESrF   r   r   Ú	itertoolsÚchainÚfrom_iterableÚfilterr   rL   ÚisfilerH   ÚgetÚexclude_data_files)r%   rB   rQ   ÚpatternsZglobs_expandedZglobs_matchesZ
glob_filesÚfilesr   r   r   rW   €   s    üþzbuild_py.find_data_filesz	list[str])r4   Úreturnc                   s"   | j rt|  ¡  ¡ ƒS tƒ  |¡S )ú1See :class:`setuptools.commands.build.SubCommand`)r   rE   Úget_output_mappingÚkeysr0   r9   )r%   r4   r2   r   r   r9   ’   s    zbuild_py.get_outputszdict[str, str])rg   c                 C  s(   t  |  ¡ |  ¡ ¡}tt|dd„ d�ƒS )rh   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   ri   ˜   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.rK   N)Zfind_all_modulesrV   Zget_module_outfilerU   )r%   rB   r@   rA   Úfilenamer   r   r   rp       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   rL   rT   )r%   rB   rQ   rX   rY   rt   r   Úsrcfiler   r   r   ro   §   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)ro   Úmkpathr   rL   Údirnamer1   r   )r%   r   ru   Z_outfZ_copiedr   r   r   r7   ¯   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|
|k�r|
}tj |
¡\}
}tj ||¡}qÎ|
|kr®||k�r.| |¡�rNq®n | ||
 |¡}|�rN| |¡ | ||
 g ¡ |	¡ q®d S )Nr   r   zSOURCES.txtzutf-8)ÚencodingÚegg_info)rH   r   Zinclude_package_datar6   Úassert_relativerS   Úgetattrr   r   ÚexistsÚ	read_textÚ
splitlinesÚrun_commandÚget_finalized_commandry   Úfilelistrf   Ú_IncludePackageDataAbuseÚ_filter_build_filesr   rL   rV   rT   Ú	is_moduleÚimportable_subpackageÚwarnrI   r?   )r%   ÚmfZsrc_dirsrB   Úegg_info_dirÚmanifestrf   Zei_cmdÚcheckrL   ÚdÚfÚprevZoldfZdfÚ
importabler   r   r   rD   ¶   sD    

ÿþ




zbuild_py.analyze_manifestzIterable[str]zIterator[str])rf   ry   rg   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   rL   Únormpath)rN   Úpr   r   r   rR   ë   s      z0build_py._filter_build_files.<locals>.<listcomp>c                 3  s   | ]}|ˆ kV  qd S r   r   )rN   r‹   ©Z	norm_pathr   r   Ú	<genexpr>ï   s     z/build_py._filter_build_files.<locals>.<genexpr>N)	r€   rU   Ú
build_tempÚ
build_baser   rL   r�   ÚisabsÚall)r%   rf   ry   r�   Z
build_dirsZ	norm_dirsrO   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k
r    Y nX tj | ||¡}|| j |< |rH| jjsL|S | jjD ]}||ksn| |d ¡rT qxqT|S t|dƒ�}| 	¡ }W 5 Q R X d|kr°t
j d|f ¡‚|S )z8Check namespace packages' __init__ for declare_namespacerK   Úrbs   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%   rB   Ú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 k	r,tj | jj|¡S |S r   )r   r   rS   r   Zsrc_rootr   rL   rT   )r%   rB   Úresr   r   r   rS     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   )Úfnmatchra   ©rN   Úpattern)rf   r   r   r“   '  s     z.build_py.exclude_data_files.<locals>.<genexpr>c                 3  s   | ]}|ˆ kr|V  qd S r   r   )rN   Úfn)Úbadr   r   r“   +  s      )rE   r\   r!   r^   r_   r`   Úsetr   )r%   rB   rQ   rf   re   Zmatch_groupsÚmatchesZkeepersr   )r­   rf   r   rd     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   rL   rT   r   rª   rP   r   r   r“   <  s   ÿz2build_py._get_platform_patterns.<locals>.<genexpr>)r^   r_   rc   )ÚspecrB   rQ   rZ   Zraw_patternsr   rP   r   r\   /  s    

ý
ýzbuild_py._get_platform_patterns)TTNr&   )T)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r   r1   r:   r=   r>   r<   rJ   rG   rW   r9   ri   rp   ro   r7   rD   rƒ   r˜   rœ   r§   rS   rd   Ústaticmethodr\   Ú__classcell__r   r   r2   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   rL   r–   Údistutils.errorsr¹   ÚtextwrapÚdedentÚlstrip)rL   r¹   Úmsgr   r   r   rz   C  s    ÿ
öÿrz   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   Ú_Warning[  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%   rO   r   r   r   r„   ‰  s    z"_IncludePackageDataAbuse.is_modulec                 C  s6   t |ƒj}tt tj|j¡ƒ}|r2d |f|•¡S d S )NrK   )	r   ÚparentrE   r^   Ú	takewhiler.   rÄ   ÚpartsrT   )r%   rÅ   rO   r¥   rÇ   r   r   r   r…   Œ  s
    
z._IncludePackageDataAbuse.importable_subpackagec                 C  s(   || j k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‚   X  s   +r‚   )#Ú
__future__r   r©   r^   r   r   r»   Ú	functoolsr   r   Úpathlibr   Útypingr   r   Zmore_itertoolsr   Zsetuptools._pathr	   Údistr   Úwarningsr   Zdistutils.command.build_pyÚcommandr   r   rº   r¡   Údistutils.utilr   r]   r   rz   r‚   r   r   r   r   Ú<module>   s.     &