B
    ©»ˆd¤:  ã               @   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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
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)ÚSetuptoolsDeprecationWarningc             C   s   t  | t  | ¡jtjB ¡ d S )N)ÚosÚchmodÚstatÚst_modeÚS_IWRITE)Útarget© r   úM/var/www/html/venv/lib/python3.7/site-packages/setuptools/command/build_py.pyÚmake_writable   s    r   c                   s@  e Zd ZU dZdZeed< dZee	 ed< dd„ Z
d5‡ 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d6ee	 dœ‡ fdd„Zee	e	f dœdd„Zeee	e	f  dœdd„Zeee	e	f  dœd d!„Zd"d#„ Zd$d%„ Zee	 e	ee	 d&œd'd(„Zd)d*„ Zd+d,„ Z d-d.„ Z!d/d0„ Z"d1d2„ Z#e$d3d4„ ƒZ%‡  Z&S )7Ú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k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_optionsé   c                s:   |r$t t|ƒ ¡ ƒ}t t|ƒ ¡ ƒ}tƒ  ||||||¡S )N)Ú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_outputs)r#   r   r   r   Úrun4   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   r8   D   s    
zbuild_py.__getattr__c             C   s.   t j | |||¡\}}|r&| j |¡ ||fS )N)r   r   Úbuild_moduler"   Úappend)r#   ÚmoduleÚmodule_fileÚpackager*   Úcopiedr   r   r   r:   K   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_filesr2   )r#   r   r   r   r7   Q   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!   Ú
setdefaultrA   rB   rC   r2   )r#   r   r   r   Úget_data_files_without_manifestV   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>i   s   z0build_py._get_pkg_data_files.<locals>.<listcomp>)Úget_package_dirr   rH   ÚjoinÚ	build_libÚsplitÚfind_data_files)r#   r>   Ú	build_dirÚ	filenamesr   )rL   r   rC   `   s
    

zbuild_py._get_pkg_data_filesc             C   s`   |   | j||¡}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'T)Ú	recursive)Ú_get_platform_patternsr   rB   r   r   Ú	itertoolsÚchainÚfrom_iterableÚfilterr   rH   ÚisfilerD   ÚgetÚexclude_data_files)r#   r>   rL   ÚpatternsZglobs_expandedZglobs_matchesZ
glob_filesÚfilesr   r   r   rR   n   s    zbuild_py.find_data_files)Úreturnc                s"   | j rt|  ¡  ¡ ƒS tƒ  |¡S )z1See :class:`setuptools.commands.build.SubCommand`)r   rA   Úget_output_mappingÚkeysr'   r5   )r#   r0   )r/   r   r   r5      s    zbuild_py.get_outputsc             C   s(   t  |  ¡ |  ¡ ¡}tt|dd„ dƒS )z1See :class:`setuptools.commands.build.SubCommand`c             S   s   | d S )Nr   r   )Úxr   r   r   Ú<lambda>‹   ó    z-build_py.get_output_mapping.<locals>.<lambda>)Úkey)rW   rX   Ú _get_package_data_output_mappingÚ_get_module_mappingÚdictÚsorted)r#   Úmappingr   r   r   ra   …   s    
zbuild_py.get_output_mappingc             c   s@   x:|   ¡ D ].\}}}| d¡}|  | j||¡}||fV  q
W dS )z5Iterate over all modules producing (dest, src) pairs.rG   N)Zfind_all_modulesrQ   Zget_module_outfilerP   )r#   r>   r<   r=   Úfilenamer   r   r   rh      s    
zbuild_py._get_module_mappingc             c   sP   xJ| j D ]@\}}}}x2|D ]*}tj ||¡}tj ||¡}||fV  qW qW dS )z6Iterate over package data producing (dest, src) pairs.N)r   r   rH   rO   )r#   r>   rL   rS   rT   rl   r   Úsrcfiler   r   r   rg   ”   s
    
z)build_py._get_package_data_output_mappingc             C   sD   x>|   ¡ D ]2\}}|  tj |¡¡ |  ||¡\}}t|ƒ q
W dS )z$Copy data files into build directoryN)rg   Úmkpathr   rH   Údirnamer(   r   )r#   r   rm   Z_outfZ_copiedr   r   r   r3   œ   s    zbuild_py.build_package_datac             C   sv  i  | _ }| jjsd S i }x$| jp$dD ]}||t|  |¡ƒ< q&W t| dd ƒr~t| jdƒ 	¡ r~| j}t|dƒ}|j
dd ¡ }n"|  d¡ |  d¡}|j}|jj}tƒ }xÊ|  ||¡D ]º}	tj t|	ƒ¡\}
}d }|}x@|
r|
|kr|
|kr|
}tj |
¡\}
}tj ||¡}qÖW |
|kr´||kr8| |¡rXq´n | ||
 |¡}|rX| |¡ | ||
 g ¡ |	¡ q´W d S )Nr   r   zSOURCES.txtzutf-8)ÚencodingÚegg_info)rD   r   Zinclude_package_datar2   Úassert_relativerN   Úgetattrr   r   ÚexistsÚ	read_textÚ
splitlinesÚrun_commandÚget_finalized_commandrq   Úfilelistr_   Ú_IncludePackageDataAbuseÚ_filter_build_filesr   rH   rQ   rO   Ú	is_moduleÚimportable_subpackageÚwarnrE   r;   )r#   ÚmfZsrc_dirsr>   Úegg_info_dirÚmanifestr_   Zei_cmdÚcheckrH   ÚdÚfÚprevZoldfZdfÚ
importabler   r   r   r@   £   s@    





zbuild_py.analyze_manifest)r_   rq   r`   c             #   sp   |   d¡}|| j|j|jf}dd„ |D ƒ}x@|D ]8}tj |¡‰ tj |¡rbt‡ fdd„|D ƒƒr0|V  q0W 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   rH   Únormpath)rJ   Úpr   r   r   rM   Ø   s    z0build_py._filter_build_files.<locals>.<listcomp>c             3   s   | ]}|ˆ kV  qd S )Nr   )rJ   rƒ   )Ú	norm_pathr   r   ú	<genexpr>Ü   s    z/build_py._filter_build_files.<locals>.<genexpr>N)	rx   rP   Ú
build_tempÚ
build_baser   rH   rˆ   ÚisabsÚall)r#   r_   rq   r‡   Z
build_dirsZ	norm_dirsrK   r   )rŠ   r   r{   Ì   s    


"zbuild_py._filter_build_filesc             C   s   d S )Nr   )r#   r   r   r   Úget_data_filesß   s    zbuild_py.get_data_filesc          	   C   s¶   y
| j | S  tk
r   Y nX tj | ||¡}|| j |< |rF| jjsJ|S x,| jjD ]}||ksn| |d ¡rTP qTW |S t 	|d¡}| 
¡ }W dQ R X d|kr²tj d|f ¡‚|S )z8Check namespace packages' __init__ for declare_namespacerG   Ú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ÚioÚ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 k	r,tj | jj|¡S |S )N)r   r   rN   r   Zsrc_rootr   rH   rO   )r#   r>   Úresr   r   r   rN     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 )N)ÚfnmatchrZ   )rJ   Úpattern)r_   r   r   r‹     s    z.build_py.exclude_data_files.<locals>.<genexpr>c             3   s   | ]}|ˆ kr|V  qd S )Nr   )rJ   Úfn)Úbadr   r   r‹     s    )rA   rV   r    rW   rX   rY   Úsetr   )r#   r>   rL   r_   r^   Zmatch_groupsÚmatchesZkeepersr   )r¥   r_   r   r]     s    zbuild_py.exclude_data_filesc                s.   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 )N)r   rH   rO   r   )rJ   r£   )rL   r   r   r‹   *  s   z2build_py._get_platform_patterns.<locals>.<genexpr>)rW   rX   r\   )Úspecr>   rL   Zraw_patternsr   )rL   r   rV     s
    

zbuild_py._get_platform_patterns)r$   r$   Nr$   )r$   )'Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r
   r%   r   r(   r6   r8   r:   r7   rF   rC   rR   r	   r5   r   ra   r   r   rh   rg   r3   r@   r   r{   r   r”   r    rN   r]   ÚstaticmethodrV   Ú__classcell__r   r   )r/   r   r      s4   
 
)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   rH   rŽ   Údistutils.errorsr²   ÚtextwrapÚdedentÚlstrip)rH   r²   Úmsgr   r   r   rr   /  s    rr   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 )rz   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   Ú_WarningG  s   $r¸   c             C   s   t ƒ | _d S )N)r¦   Ú_already_warned)r#   r   r   r   Ú__init__r  s    z!_IncludePackageDataAbuse.__init__c             C   s    |  d¡o|d tdƒ …  ¡ S )Nz.py)ÚendswithÚlenÚisidentifier)r#   rK   r   r   r   r|   u  s    z"_IncludePackageDataAbuse.is_modulec             C   s6   t |ƒj}tt tj|j¡ƒ}|r2d |f|•¡S d S )NrG   )	r   ÚparentrA   rW   Ú	takewhiler%   r½   ÚpartsrO   )r#   r¾   rK   rž   rÀ   r   r   r   r}   x  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   rz   D  s   +rz   )!Ú	functoolsr   r   Údistutils.utilr   Zdistutils.command.build_pyÚcommandr   r   r   r¢   r´   r—   r³   rš   rW   r   Úpathlibr   Útypingr   r   r   r	   r
   r   Zextern.more_itertoolsr   Úwarningsr   r   rr   rz   r   r   r   r   Ú<module>   s(      