o
    
j6h&                     @   sb  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rddl-m.Z. e/e0Z1G dd dZ2ej3dee4 f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deddfddZdS )_PrefixpathreturnNc                 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)   f/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/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R}tj	
|j	d}i }tjdkr-d|d< tj|dfi |}| d	D ]}|||| j  q=W d   n1 sVw   Y  tj	
|d
V  W d   dS 1 snw   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"   

"rM   c                   @   s   e Zd ZdZdddZdddZdeee  d	ee d
ee	 ddfddZ
dee deeeeef  ee f fddZdddee dededdf
ddZededddee dededdfddZdS )BuildEnvironmentzACreates and manages an isolated environment to install build depsr   Nc                    s  t tjdd t fdddD | _g | _g | _tt| j	 D ]}| j
|j | j|j q"dd t t fD }tj jd| _tj| jsTt| j ttj| jd	d
dd}|tdj|| jd W d    d S 1 s{w   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   zutf-8)encodinga  
                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   s6   

"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
PYTHONPATHrr   1)
	_save_envr_   re   splitr$   pathseprf   ro   updater>   )r(   r   old_path
pythonpathr)   r)   r*   	__enter__   s   


zBuildEnvironment.__enter__exc_typeexc_valexc_tbc                 C   s:   | j  D ]\}}|d u rtj|d  q|tj|< qd S rP   )rv   itemsr$   ro   pop)r(   r}   r~   r   varname	old_valuer)   r)   r*   __exit__   s
   zBuildEnvironment.__exit__reqsc           	      C   s   t  }t  }|rJt| j}|D ]:}t|}||j}|s#|| qt|jt	r3|j d|j }n	|j d|j }|j|j
vrI|||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_requirementsfinderr   requirementsprefix_as_stringr1   c                C   sp   | j | }|jr
J d|_|sd S t }|t }| j|||||d W d    d S 1 s1w   Y  d S )NTr0   )r^   r#   
contextlib	ExitStackenter_contextrM   _install_requirements)r(   r   r   r   r1   rm   ctxpip_runnabler)   r)   r*   install_requirements   s   


"z%BuildEnvironment.install_requirementsr   rm   c                C   st  t j| dddd|jdg}t tjkr|d dD ]}t|j	|}|
d|d	d
 dt|p2dhf q|j}|rW|
d|d g |dd  D ]	}	|
d|	g qLn|d |jD ]	}
|
d|
g q_|jD ]	}|
d|g ql|jr~|d |jr|d |d |
| dt i}td| }t|d| ||d W d    d S 1 sw   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_CERTzInstalling zpip subprocess to install )command_descspinnerextra_environ)r?   
executabler   loggergetEffectiveLevelloggingDEBUGrd   getattrformat_controlre   replacer>   sorted
index_urls
find_linkstrusted_hostsallow_all_prereleasesprefer_binaryr   r   r   )r   r   r   rm   r1   argsr   formatsr   extra_indexlinkhostr   r   r)   r)   r*   r      sX   










"z&BuildEnvironment._install_requirementsr   N)r,   r-   r.   __doc__r+   r|   r	   r   BaseExceptionr   r   r   r/   r   r
   r   r   staticmethodr   r   r)   r)   r)   r*   rN   F   sV    

7



rN   c                
   @   sz   e Zd ZdZdddZdddZdeee  d	ee d
ee	 ddfddZ
dddZdddee dededdf
ddZdS )NoOpBuildEnvironmentz0A no-op drop-in replacement for BuildEnvironmentr   Nc                 C      d S rP   r)   r(   r)   r)   r*   r+        zNoOpBuildEnvironment.__init__c                 C   r   rP   r)   r   r)   r)   r*   r|     r   zNoOpBuildEnvironment.__enter__r}   r~   r   c                 C   r   rP   r)   )r(   r}   r~   r   r)   r)   r*   r     s   zNoOpBuildEnvironment.__exit__c                 C   r   rP   r)   r   r)   r)   r*   cleanup  r   zNoOpBuildEnvironment.cleanupr   r   r   r   r1   c                C   s   t  rP   )NotImplementedError)r(   r   r   r   r1   r)   r)   r*   r      s   z)NoOpBuildEnvironment.install_requirementsr   )r,   r-   r.   r   r+   r|   r	   r   r   r   r   r   r   r/   r   r)   r)   r)   r*   r     s2    




r   )8r   r   r   r$   r8   r?   rj   rA   collectionsr   	sysconfigr   typesr   typingr   r   r   r   r	   r
   r   r   pip._vendor.certifir   "pip._vendor.packaging.requirementsr   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<    (
 G