o g &@sbdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZmZmZddlmZddlmZdd lmZdd lmZdd l m!Z!dd l"m#Z#m$Z$m%Z%dd l&m'Z'ddl(m)Z)ddl*m+Z+m,Z,erddl-m.Z.e/e0Z1GdddZ2ej3dee4fddZ5GdddZ6Gddde6Z7dS)z;Build Environment used for isolation during sdist building N) OrderedDict) get_paths) TracebackType) TYPE_CHECKINGIterableIteratorListOptionalSetTupleType)where) Requirement)Version)__file__) open_spinner) get_platlibget_prefixed_libs get_purelib)get_environment)call_subprocess) TempDirectory tempdir_kinds) PackageFinderc@seZdZdeddfddZdS)_PrefixpathreturnNcCs@||_d|_ttjdkrdnd||ddd|_t||_dS)NFnt posix_prefix)baseplatbase)varsscripts)rsetuprosnamebin_dirrlib_dirs)selfrr)9/usr/lib/python3/dist-packages/pip/_internal/build_env.py__init__"sz_Prefix.__init__)__name__ __module__ __qualname__strr+r)r)r)r*r!srrc csttj}|st|VdStddR}tj |j d}i}t j dkr-d|d<t j|dfi|}|d D]}||||jq=Wdn1sVwYtj |d VWddS1snwYdS) 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. Nzstandalone-pipkindz__env_pip__.zip)Fstrict_timestampsw*pip)pathlibPath pip_locationresolveparentis_dirr/rr$rjoinsys version_infozipfileZipFilerglobwrite relative_toas_posix)sourcetmp_dirpip_zipkwargszfchildr)r)r*_create_standalone_pip,s"   "rMc @seZdZdZdddZdddZdeeed eed ee ddfd d Z d e e de ee e e fee ffddZddde e de de ddf ddZede ddde e dede ddf ddZdS)BuildEnvironmentzACreates and manages an isolated environment to install build depsrNcsttjddtfdddD|_g|_g|_tt|j D]}|j |j |j |j q"ddttfD}tjjd|_tj|jsTt|jttj|jd d d d }|td j||jdWddS1s{wYdS)NT)r1globally_managedc3s(|]}|ttjj|fVqdSN)rr$rr>.0r%temp_dirr)r* Ls  z,BuildEnvironment.__init__..)normaloverlaycSsh|]}tj|qSr))r$rnormcase)rRsiter)r)r* Zs z,BuildEnvironment.__init__..rYzsitecustomize.pyr5zutf-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')rr BUILD_ENVr _prefixes _bin_dirs _lib_dirsreversedlistvaluesappendr&extendr'rrr$rr> _site_direxistsmkdiropenrDtextwrapdedentformat)r(prefixr\fpr)rSr*r+Is6    "zBuildEnvironment.__init__cCsndddD|_|jdd}|jd}|r||tj|jg}tjtj |dtj |ddS)NcSsi|] }|tj|dqSrP)r$environgetrQr)r)r* sz.BuildEnvironment.__enter__..)PATHPYTHONNOUSERSITE PYTHONPATHrr1) _save_envr_resplitr$pathseprfroupdater>)r(rold_path pythonpathr)r)r* __enter__s   zBuildEnvironment.__enter__exc_typeexc_valexc_tbcCs:|jD]\}}|durtj|dq|tj|<qdSrP)rvitemsr$ropop)r(r}r~rvarname old_valuer)r)r*__exit__s  zBuildEnvironment.__exit__reqsc Cst}t}|rJt|j}|D]:}t|}||j}|s#||qt|jt r3|jd|j}n |jd|j}|j|j vrI|||fq||fS)zReturn 2 sets: - conflicting requirements: set of (installed, wanted) reqs tuples - missing requirements: set of reqs z==z===) setrr`rget_distributionr%add isinstanceversionr specifier) r(rmissing conflictingenvreq_strreqdistinstalled_req_strr)r)r*check_requirementss"     z#BuildEnvironment.check_requirementsfinderr requirementsprefix_as_stringr1cCsp|j|}|jr Jd|_|sdSt}|t}|j|||||dWddS1s1wYdS)NTr0)r^r# contextlib ExitStack enter_contextrM_install_requirements)r(rrrr1rmctx pip_runnabler)r)r*install_requirementss    "z%BuildEnvironment.install_requirementsrrmcCsttj|dddd|jdg}ttjkr|ddD]}t|j |}| d| d d d t |p2d hfq|j}|rW| d |dg|ddD] } | d| gqLn|d|jD] } | d| gq_|jD] } | d| gql|jr~|d|jr|d|d| |dti} td|} t|d|| | dWddS1swYdS)Ninstallz--ignore-installedz --no-userz--prefixz--no-warn-script-locationz-v) no_binary only_binaryz--_-,z:none:z-irz--extra-index-urlz --no-indexz --find-linksz--trusted-hostz--prez--prefer-binary_PIP_STANDALONE_CERTz Installing zpip subprocess to install ) command_descspinner extra_environ)r? executablerloggergetEffectiveLevelloggingDEBUGrdgetattrformat_controlrereplacer>sorted index_urls find_links trusted_hostsallow_all_prereleases prefer_binaryr rr)rrrrmr1argsrformatsr extra_indexlinkhostrrr)r)r*rsX           "z&BuildEnvironment._install_requirementsrN)r,r-r.__doc__r+r|r r BaseExceptionrrrr/r r rr staticmethodrrr)r)r)r*rNFsV  7     rNc @szeZdZdZdddZdddZdeeed eed ee ddfd d Z dd dZ ddde e de de ddf ddZdS)NoOpBuildEnvironmentz0A no-op drop-in replacement for BuildEnvironmentrNcCdSrPr)r(r)r)r*r+zNoOpBuildEnvironment.__init__cCrrPr)rr)r)r*r|rzNoOpBuildEnvironment.__enter__r}r~rcCrrPr))r(r}r~rr)r)r*rszNoOpBuildEnvironment.__exit__cCrrPr)rr)r)r*cleanuprzNoOpBuildEnvironment.cleanuprrrrr1cCstrP)NotImplementedError)r(rrrr1r)r)r*r sz)NoOpBuildEnvironment.install_requirementsr)r,r-r.rr+r|r r rrrrrr/rr)r)r)r*r s2    r)8rrrr$r8r?rjrA collectionsr sysconfigrtypesrtypingrrrrr r r r pip._vendor.certifir "pip._vendor.packaging.requirementsrpip._vendor.packaging.versionrr7rr:pip._internal.cli.spinnersrpip._internal.locationsrrrpip._internal.metadatarpip._internal.utils.subprocessrpip._internal.utils.temp_dirrr"pip._internal.index.package_finderr getLoggerr,rrcontextmanagerr/rMrNrr)r)r)r*s<   (          G