a
    Dmg&                     @   sd  d 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 ddlmZ ddlmZmZmZmZmZ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#m$Z$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z, erddl-m.Z. e/e0Z1G dd dZ2ej3ee4 dddZ5G dd dZ6G dd de6Z7dS )z;Build Environment used for isolation during sdist building
    N)OrderedDict)	get_paths)TracebackType)TYPE_CHECKINGIterableIteratorListOptionalSetTupleType)where)Requirement)Version)__file__)open_spinner)get_platlibget_prefixed_libsget_purelib)get_environment)call_subprocess)TempDirectorytempdir_kinds)PackageFinderc                   @   s   e Zd ZeddddZdS )_PrefixN)pathreturnc                 C   s@   || _ d| _ttjdkrdnd||ddd | _t|| _d S )NFntposix_prefix)baseplatbase)varsscripts)r   setupr   osnamebin_dirr   lib_dirs)selfr    r)   N/var/www/html/idle/venv/lib/python3.9/site-packages/pip/_internal/build_env.py__init__"   s    z_Prefix.__init__)__name__
__module____qualname__strr+   r)   r)   r)   r*   r   !   s   r   r   c               	   c   s   t t j} |  s&t| V  dS tdd}tj	
|j	d}i }tjdkrXd|d< tj|dfi |8}| d	D ]}|||| j  qxW d   n1 s0    Y  tj	
|d
V  W d   n1 s0    Y  dS )zCreate a "standalone pip" zip file.

    The zip file's content is identical to the currently-running pip.
    It will be used to install requirements into the build environment.
    Nzstandalone-pip)kindz__env_pip__.zip)      Fstrict_timestampsw*pip)pathlibPathpip_locationresolveparentis_dirr/   r   r$   r   joinsysversion_infozipfileZipFilerglobwriterelative_toas_posix)sourcetmp_dirpip_zipkwargszfchildr)   r)   r*   _create_standalone_pip,   s    

8rM   c                   @   s   e Zd ZdZddddZddddZeee  ee ee	 ddd	d
Z
ee eeeeef  ee f dddZdee eeddddZeedee eeddddZdS )BuildEnvironmentzACreates and manages an isolated environment to install build depsNr0   c                    s   t tjdd t fdddD | _g | _g | _tt| j	 D ] }| j
|j | j|j qDdd t t fD }tj jd| _tj| jst| j ttj| jd	d
,}|tdj|| jd W d    n1 s0    Y  d S )NT)r1   globally_managedc                 3   s&   | ]}|t tj j|fV  qd S N)r   r$   r   r>   .0r%   temp_dirr)   r*   	<genexpr>L   s   z,BuildEnvironment.__init__.<locals>.<genexpr>)normaloverlayc                 S   s   h | ]}t j|qS r)   )r$   r   normcase)rR   siter)   r)   r*   	<setcomp>Z   s   z,BuildEnvironment.__init__.<locals>.<setcomp>rY   zsitecustomize.pyr5   a  
                import os, site, sys

                # First, drop system-sites related paths.
                original_sys_path = sys.path[:]
                known_paths = set()
                for path in {system_sites!r}:
                    site.addsitedir(path, known_paths=known_paths)
                system_paths = set(
                    os.path.normcase(path)
                    for path in sys.path[len(original_sys_path):]
                )
                original_sys_path = [
                    path for path in original_sys_path
                    if os.path.normcase(path) not in system_paths
                ]
                sys.path = original_sys_path

                # Second, add lib directories.
                # ensuring .pth file are processed.
                for path in {lib_dirs!r}:
                    assert not path in sys.path
                    site.addsitedir(path)
                )system_sitesr'   )r   r   	BUILD_ENVr   	_prefixes	_bin_dirs	_lib_dirsreversedlistvaluesappendr&   extendr'   r   r   r$   r   r>   	_site_direxistsmkdiropenrD   textwrapdedentformat)r(   prefixr[   fpr)   rS   r*   r+   I   s.    

zBuildEnvironment.__init__c                 C   sn   dd dD | _ | jd d  }| j d }|r>||tj | jg}tjtj	|dtj	|d d S )Nc                 S   s   i | ]}|t j|d qS rP   )r$   environgetrQ   r)   r)   r*   
<dictcomp>   s   z.BuildEnvironment.__enter__.<locals>.<dictcomp>)PATHPYTHONNOUSERSITE
PYTHONPATHrq   1)
	_save_envr^   rd   splitr$   pathsepre   rn   updater>   )r(   r   old_path
pythonpathr)   r)   r*   	__enter__~   s    


zBuildEnvironment.__enter__exc_typeexc_valexc_tbr   c                 C   s:   | j  D ]*\}}|d u r*tj|d  q
|tj|< q
d S rP   )ru   itemsr$   rn   pop)r(   r}   r~   r   varname	old_valuer)   r)   r*   __exit__   s    zBuildEnvironment.__exit__)reqsr   c           	      C   s   t  }t  }|rt| j}|D ]t}t|}||j}|sF|| qt|jt	rf|j d|j }n|j d|j }|j|j
vr|||f q||fS )zReturn 2 sets:
        - conflicting requirements: set of (installed, wanted) reqs tuples
        - missing requirements: set of reqs
        z==z===)setr   r_   r   get_distributionr%   add
isinstanceversionr   	specifier)	r(   r   missingconflictingenvreq_strreqdistinstalled_req_strr)   r)   r*   check_requirements   s     

z#BuildEnvironment.check_requirementsr   finderrequirementsprefix_as_stringmessager   c                 C   s   | j | }|jrJ d|_|s"d S t F}tjdk rDtjt	}n|
t }| ||||| W d    n1 sv0    Y  d S )NT)r2      )r]   r#   
contextlib	ExitStackr?   r@   r$   r   dirnamer:   enter_contextrM   _install_requirements)r(   r   r   r   r   rl   ctxpip_runnabler)   r)   r*   install_requirements   s     



z%BuildEnvironment.install_requirements)r   r   r   rl   r   r   c                 C   sh  t j| dddd|jdg}t tjkr0|d dD ]:}t|j	|}|
d|d	d
 dt|pddhf q4|j}|r|
d|d g |dd  D ]}	|
d|	g qn
|d |jD ]}
|
d|
g q|jD ]}|
d|g q|jr|d |jr|d |d |
| dt i}t|}t|||d W d    n1 sZ0    Y  d S )Ninstallz--ignore-installedz	--no-userz--prefixz--no-warn-script-locationz-v)	no_binaryonly_binaryz--_-,z:none:z-ir      z--extra-index-urlz
--no-indexz--find-linksz--trusted-hostz--prez--prefer-binary_PIP_STANDALONE_CERT)spinnerextra_environ)r?   
executabler   loggergetEffectiveLevelloggingDEBUGrc   getattrformat_controlrd   replacer>   sorted
index_urls
find_linkstrusted_hostsallow_all_prereleasesprefer_binaryr   r   r   )r   r   r   rl   r   argsr   formatsr   extra_indexlinkhostr   r   r)   r)   r*   r      sJ    	










z&BuildEnvironment._install_requirements)r,   r-   r.   __doc__r+   r{   r	   r   BaseExceptionr   r   r   r/   r   r
   r   r   staticmethodr   r   r)   r)   r)   r*   rN   F   s2   5
rN   c                   @   sx   e Zd ZdZddddZddddZeee  ee ee	 ddd	d
Z
ddddZdee eeddddZdS )NoOpBuildEnvironmentz0A no-op drop-in replacement for BuildEnvironmentNr0   c                 C   s   d S rP   r)   r(   r)   r)   r*   r+     s    zNoOpBuildEnvironment.__init__c                 C   s   d S rP   r)   r   r)   r)   r*   r{     s    zNoOpBuildEnvironment.__enter__r|   c                 C   s   d S rP   r)   )r(   r}   r~   r   r)   r)   r*   r     s    zNoOpBuildEnvironment.__exit__c                 C   s   d S rP   r)   r   r)   r)   r*   cleanup  s    zNoOpBuildEnvironment.cleanupr   r   c                 C   s
   t  d S rP   )NotImplementedError)r(   r   r   r   r   r)   r)   r*   r     s    z)NoOpBuildEnvironment.install_requirements)r,   r-   r.   r   r+   r{   r	   r   r   r   r   r   r   r/   r   r)   r)   r)   r*   r   
  s   
r   )8r   r   r   r$   r8   r?   ri   rA   collectionsr   	sysconfigr   typesr   typingr   r   r   r   r	   r
   r   r   pip._vendor.certifir   Z"pip._vendor.packaging.requirementsr   Zpip._vendor.packaging.versionr   r7   r   r:   pip._internal.cli.spinnersr   pip._internal.locationsr   r   r   pip._internal.metadatar   pip._internal.utils.subprocessr   pip._internal.utils.temp_dirr   r   "pip._internal.index.package_finderr   	getLoggerr,   r   r   contextmanagerr/   rM   rN   r   r)   r)   r)   r*   <module>   s:   (
 E