U
    Qe.                     @   sV  d Z ddlZddlZddlZddlZddlmZmZm	Z	m
Z
 ddlmZmZ ddlmZmZ ddlmZ ddlmZ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"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l0m1Z1 ddl2m3Z3 e4e5Z6e7dej8Z9e
ee$ ee$ f Z:e;e<dddZ=e$e<e<dddZ>e$e<dddZ?e$e<dd d!Z@e$e	e< dd"d#ZAe$ee;d$d%d&ZBe$e;dd'd(d)ZCe$e;e<ee; ee; e<e	e; d*d+d,ZDe$e;ee; ee; e<e	e; d-d.d/ZEe$ee; e<d0d1d2ZFee$ ee<ee; ee; e:d3d4d5ZGdS )6z;Orchestrator for building wheels from InstallRequirements.
    N)IterableListOptionalTuple)canonicalize_namecanonicalize_version)InvalidVersionVersion)
WheelCache)InvalidWheelFilenameUnsupportedWheel)FilesystemWheelget_wheel_distribution)Link)Wheel)build_wheel_pep517)build_wheel_editable)build_wheel_legacy)InstallRequirement)
indent_log)
ensure_dir	hash_file)make_setuptools_clean_args)call_subprocess)TempDirectory)path_to_url)vcsz([a-z0-9_.]+)-([a-z0-9_.!+-]+))sreturnc                 C   s   t t| S )zjDetermine whether the string looks like an egg_info.

    :param s: The string to parse. E.g. foo-2.1
    )bool_egg_info_research)r    r"   Q/var/www/html/htmlvenv/lib/python3.8/site-packages/pip/_internal/wheel_builder.py_contains_egg_info%   s    r$   )req
need_wheelr   c                 C   sJ   | j r
dS | jr&|r"td| j dS |r.dS | js8dS | jrF|  S dS )zBReturn whether an InstallRequirement should be built into a wheel.Fz(Skipping %s, due to already being wheel.T)
constraintis_wheelloggerinfoname
source_direditablesupports_pyproject_editable)r%   r&   r"   r"   r#   _should_build-   s     r/   )r%   r   c                 C   s   t | ddS )NTr&   r/   r%   r"   r"   r#   should_build_for_wheel_commandN   s    r3   c                 C   s   t | ddS )NFr0   r1   r2   r"   r"   r#    should_build_for_install_commandT   s    r4   c                 C   s   | j s| j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slt| j
 \}}t|rd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.
    FT)r-   r,   linkis_vcsAssertionErrorr   get_backend_for_schemeschemeis_immutable_rev_checkouturlsplitextr$   )r%   vcs_backendbaseextr"   r"   r#   _should_cacheZ   s    


r@   )r%   wheel_cacher   c                 C   s>   t |j}| jst|r.t| r.|| j}n|| j}|S )zdReturn the persistent or temporary cache directory where the built
    wheel need to be stored.
    )r   	cache_dirr5   r7   r@   get_path_for_linkget_ephem_path_for_link)r%   rA   Zcache_availablerB   r"   r"   r#   _get_cache_dirz   s    

rE   )r%   
wheel_pathr   c           	      C   s   t | jp
d}ttj|}t |j|krBtd|d|jtt||}t	|j
}t|t|j
krtd|d|j
|j}|d krtdzt|}W n& tk
r   d| }t|Y nX |tdkrt|j
tstd|dd S )	N z)Wheel has unexpected file name: expected z, got zMissing Metadata-VersionzInvalid Metadata-Version: z1.2z+Metadata 1.2 mandates PEP 440 version, but z is not)r   r+   r   ospathbasenamer   r   r   strversionr   metadata_versionr   r	   r   
isinstance)	r%   rF   canonical_namewdistZdist_verstrZmetadata_version_valuerM   msgr"   r"   r#   _verify_one   s0    


rS   )r%   
output_dirverifybuild_optionsglobal_optionsr-   r   c           	   
   C   s   |rdnd}zt | W n: tk
rR } ztd|| j| W Y dS d}~X Y nX | j t| ||||}W 5 Q R X |r|rzt| | W n> tt	fk
r } ztd|| j| W Y dS d}~X Y nX |S )zaBuild one wheel.

    :return: The filename of the built wheel, or None if the build failed.
    r-   wheelzBuilding %s for %s failed: %sNzBuilt %s for %s is invalid: %s)
r   OSErrorr)   warningr+   	build_env_build_one_inside_envrS   r   r   )	r%   rT   rU   rV   rW   r-   ZartifacterF   r"   r"   r#   
_build_one   s4        r^   )r%   rT   rV   rW   r-   r   c                 C   s|  t ddf}| jst| jr| js(t| js2t|rDtd| j |rVtd| j |rtt| j| j| j|j	d}qt
| j| j| j|j	d}nt| j| j| j|||j	d}|d k	rRtj	|}tj	||}zNt|\}	}
t|| td| j||
|	  td| |W W  5 Q R  S  tk
rP } ztd	| j| W 5 d }~X Y nX | jsdt| | W 5 Q R  d S Q R X d S )
NrX   )kindz7Ignoring --global-option when building %s using PEP 517z6Ignoring --build-option when building %s using PEP 517)r+   backendmetadata_directorytempd)r+   setup_py_pathr,   rW   rV   rb   z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %sz Building wheel for %s failed: %s)r   r+   r7   
use_pep517ra   pep517_backendr)   rZ   r   rI   r   r   rc   unpacked_source_directoryrH   rJ   joinr   shutilmover*   	hexdigest	Exception_clean_one_legacy)r%   rT   rV   rW   r-   temp_dirrF   
wheel_name	dest_pathZ
wheel_hashlengthr]   r"   r"   r#   r\      sx    


  	

r\   )r%   rW   r   c                 C   s\   t | j|d}td| j zt|d| jd W dS  tk
rV   td| j Y dS X d S )N)rW   zRunning setup.py clean for %szpython setup.py clean)command_desccwdTz Failed cleaning build dir for %sF)	r   rc   r)   r*   r+   r   r,   rk   error)r%   rW   Z
clean_argsr"   r"   r#   rl     s      rl   )requirementsrA   rU   rV   rW   r   c           
   	   C   s  | sg g fS t dddd | D  t  g g  }}| D ]}|jsLtt||}t||||||jol|j	}	|	r|j
dk	r|||j
 tt|	|_|jj|_|jjst|| q>|| q>W 5 Q R X |rt dddd	 |D  |rt d
ddd	 |D  ||fS )zBuild 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>7  s     zbuild.<locals>.<genexpr>NzSuccessfully built %s c                 S   s   g | ]
}|j qS r"   ru   rv   r"   r"   r#   
<listcomp>Z  s     zbuild.<locals>.<listcomp>zFailed to build %sc                 S   s   g | ]
}|j qS r"   ru   rv   r"   r"   r#   rz   _  s     )r)   r*   rg   r   r+   r7   rE   r^   r-   permit_editable_wheelsdownload_inforecord_download_originr   r   r5   	file_pathlocal_file_pathr(   append)
rt   rA   rU   rV   rW   Zbuild_successesbuild_failuresr%   rB   Z
wheel_filer"   r"   r#   build%  sL    





r   )H__doc__loggingos.pathrH   rerh   typingr   r   r   r   Zpip._vendor.packaging.utilsr   r   Zpip._vendor.packaging.versionr   r	   pip._internal.cacher
   pip._internal.exceptionsr   r   pip._internal.metadatar   r   pip._internal.models.linkr   pip._internal.models.wheelr   Z$pip._internal.operations.build.wheelr   Z-pip._internal.operations.build.wheel_editabler   Z+pip._internal.operations.build.wheel_legacyr   pip._internal.req.req_installr   pip._internal.utils.loggingr   pip._internal.utils.miscr   r   $pip._internal.utils.setuptools_buildr   pip._internal.utils.subprocessr   pip._internal.utils.temp_dirr   pip._internal.utils.urlsr   pip._internal.vcsr   	getLogger__name__r)   compile
IGNORECASEr    ZBuildResultrK   r   r$   r/   r3   r4   r@   rE   rS   r^   r\   rl   r   r"   r"   r"   r#   <module>   s   
	"!'G