U
    ißŽiá$  ã                   @   sˆ  d 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 ddlmZ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 e�rddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' ddl(m)Z) e e)ge*f Z+e%e"e) e"e) f Z,e -e.¡Z/e 0dej1¡fdd„Z2dd„ Z3dd„ Z4dd„ Z5dd„ Z6dd„ Z7dd„ Z8d d!„ Z9d"d#„ Z:d$d%„ Z;d&d'„ Z<dS )(z;Orchestrator for building wheels from InstallRequirements.
é    N)ÚLink)Úbuild_wheel_pep517)Úbuild_wheel_legacy)Ú
indent_log)Ú
ensure_dirÚ	hash_fileÚis_wheel_installed)Úmake_setuptools_clean_args)Úcall_subprocess)ÚTempDirectory)ÚMYPY_CHECK_RUNNING)Úpath_to_url)Úvcs)ÚAnyÚCallableÚIterableÚListÚOptionalÚPatternÚTuple)Ú
WheelCache)ÚInstallRequirementz([a-z0-9_.]+)-([a-z0-9_.!+-]+)c                 C   s   t | | ¡ƒS )zjDetermine whether the string looks like an egg_info.

    :param s: The string to parse. E.g. foo-2.1
    )ÚboolÚsearch)ÚsZ_egg_info_re© r   úY/var/www/html/IITS/school/venv/lib/python3.8/site-packages/pip/_internal/wheel_builder.pyÚ_contains_egg_info&   s    r   c                 C   sl   | j r
dS | jr&|r"t d| j¡ dS |r.dS | js>tƒ s>dS | jsJ| jsNdS || ƒsht d| j¡ dS dS )zBReturn whether an InstallRequirement should be built into a wheel.Fz(Skipping %s, due to already being wheel.TzCSkipping wheel build for %s, due to binaries being disabled for it.)	Ú
constraintÚis_wheelÚloggerÚinfoÚnameÚ
use_pep517r   ÚeditableÚ
source_dir)ÚreqÚ
need_wheelÚcheck_binary_allowedr   r   r   Ú_should_build0   s,     ÿþr)   c                 C   s   t | dtd�S )NT©r'   r(   )r)   Ú_always_true)r&   r   r   r   Úshould_build_for_wheel_commandY   s
      ÿr,   c                 C   s   t | d|d�S )NFr*   )r)   )r&   r(   r   r   r   Ú should_build_for_install_commandb   s
      ÿr-   c                 C   s€   t | td�sdS | jrb| jjrb| jr(t‚| js2t‚t | jj	¡}|sHt‚| 
| jj| j¡r^dS dS | j ¡ \}}t|ƒr|dS dS )zÍ
    Return whether a built InstallRequirement can be stored in the persistent
    wheel cache, assuming the wheel cache is available, and _should_build()
    has determined a wheel needs to be built.
    )r(   FT)r-   r+   ÚlinkÚis_vcsr$   ÚAssertionErrorr%   r   Úget_backend_for_schemeÚschemeÚis_immutable_rev_checkoutÚurlÚsplitextr   )r&   Úvcs_backendÚbaseÚextr   r   r   Ú_should_cachel   s"    	 ÿ

r9   c                 C   s4   t |jƒ}|r$t| ƒr$| | j¡}n| | j¡}|S )zdReturn the persistent or temporary cache directory where the built
    wheel need to be stored.
    )r   Ú	cache_dirr9   Úget_path_for_linkr.   Úget_ephem_path_for_link)r&   Úwheel_cacheZcache_availabler:   r   r   r   Ú_get_cache_dir�   s
    
r>   c                 C   s   dS )NTr   )Ú_r   r   r   r+   Ÿ   s    r+   c              
   C   sr   zt |ƒ W n8 tk
rD } zt d| j|¡ W Y ¢dS d}~X Y nX | j� t| |||ƒW  5 Q R £ S Q R X dS )zaBuild one wheel.

    :return: The filename of the built wheel, or None if the build failed.
    ú Building wheel for %s failed: %sN)r   ÚOSErrorr    Úwarningr"   Ú	build_envÚ_build_one_inside_env)r&   Ú
output_dirÚbuild_optionsÚglobal_optionsÚer   r   r   Ú
_build_one¤   s      þ   ÿrI   c                 C   s  t dd���}| jr0t| j| j| j||jd�}nt| j| j| j	|||jd�}|d k	rðt
j |¡}t
j ||¡}zNt|ƒ\}}	t ||¡ t d| j||	| ¡ ¡ t d|¡ |W W  5 Q R £ S  tk
rî }
 zt d| j|
¡ W 5 d }
~
X Y nX | j�st| |ƒ W 5 Q R £ d S Q R X d S )NÚwheel)Úkind)r"   ÚbackendÚmetadata_directoryrF   Útempd)r"   Úsetup_py_pathr%   rG   rF   rN   z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %sr@   )r   r#   r   r"   Úpep517_backendrM   Úpathr   rO   Úunpacked_source_directoryÚosÚbasenameÚjoinr   ÚshutilÚmover    r!   Ú	hexdigestÚ	ExceptionrB   Ú_clean_one_legacy)r&   rE   rF   rG   Útemp_dirÚ
wheel_pathÚ
wheel_nameZ	dest_pathZ
wheel_hashÚlengthrH   r   r   r   rD   ¿   sP    ûú	  ý þ
rD   c                 C   sZ   t | j|d�}t d| j¡ zt|| jd� W dS  tk
rT   t d| j¡ Y dS X d S )N)rG   zRunning setup.py clean for %s)ÚcwdTz Failed cleaning build dir for %sF)	r	   rO   r    r!   r"   r
   r%   rY   Úerror)r&   rG   Z
clean_argsr   r   r   rZ   ð   s    þrZ   c           	   	   C   sì   | sg g fS t  dd dd„ | D ƒ¡¡ tƒ �p g g  }}| D ]Z}t||ƒ}t||||ƒ}|rŽtt|ƒƒ|_|jj	|_
|jjs‚t‚| |¡ q>| |¡ q>W 5 Q R X |rÄt  dd dd„ |D ƒ¡¡ |rät  d	d d
d„ |D ƒ¡¡ ||fS )z˜Build wheels.

    :return: The list of InstallRequirement that succeeded to build and
        the list of InstallRequirement that failed to build.
    z*Building wheels for collected packages: %sz, c                 s   s   | ]}|j V  qd S )N©r"   ©Ú.0r&   r   r   r   Ú	<genexpr>  s     zbuild.<locals>.<genexpr>zSuccessfully built %sú c                 S   s   g | ]
}|j ‘qS r   ra   rb   r   r   r   Ú
<listcomp>)  s     zbuild.<locals>.<listcomp>zFailed to build %sc                 S   s   g | ]
}|j ‘qS r   ra   rb   r   r   r   rf   .  s     )r    r!   rU   r   r>   rI   r   r   r.   Ú	file_pathÚlocal_file_pathr   r0   Úappend)	Úrequirementsr=   rF   rG   Zbuild_successesÚbuild_failuresr&   r:   Z
wheel_filer   r   r   Úbuild   sB    þ

   ÿ
þþrl   )=Ú__doc__ÚloggingÚos.pathrS   ÚrerV   Úpip._internal.models.linkr   Z$pip._internal.operations.build.wheelr   Z+pip._internal.operations.build.wheel_legacyr   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   r   Ú$pip._internal.utils.setuptools_buildr	   Úpip._internal.utils.subprocessr
   Úpip._internal.utils.temp_dirr   Úpip._internal.utils.typingr   Úpip._internal.utils.urlsr   Úpip._internal.vcsr   Útypingr   r   r   r   r   r   r   Úpip._internal.cacher   Úpip._internal.req.req_installr   r   ÚBinaryAllowedPredicateZBuildResultÚ	getLoggerÚ__name__r    ÚcompileÚIr   r)   r,   r-   r9   r>   r+   rI   rD   rZ   rl   r   r   r   r   Ú<module>   sD   $
ÿ

)	
#1