U .e]@sdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z mZddlmZddlmZdd lmZdd lmZdd lmZerdd lmZmZmZmZmZdd l m!Z!e"e#Z$GdddZ%Gddde&Z'Gddde'Z(dS)z;Build Environment used for isolation during sdist building N) OrderedDict)get_python_lib) get_paths) RequirementVersionConflict WorkingSet)__file__)call_subprocess) TempDirectory)MYPY_CHECK_RUNNING) open_spinner)TupleSetIterableOptionalList) PackageFinderc@seZdZddZdS)_PrefixcCsj||_d|_ttjdkrdnd||ddd|_td|d}td|d}||kr\|g|_n ||g|_dS) NFntZ posix_prefix)baseZplatbase)varsZscripts) plat_specificprefixT)pathsetuprosnamebin_dirrlib_dirs)selfrZpurelibZplatlibr ;/usr/lib/python3.8/site-packages/pip/_internal/build_env.py__init__!s   z_Prefix.__init__N)__name__ __module__ __qualname__r"r r r r!rsrc@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)BuildEnvironmentzFCreates and manages an isolated environment to install build deps c stdd_tfdddD_g_g_ttjD] }j |j j |j qBddt dd t d d fD}tjjjd _tjjstjttjjd d "}|tdj|jdW5QRXdS)Nz build-env)Zkindc3s(|] }|ttjjj|fVqdSN)rrrjoin _temp_dir.0rrr r! ;sz,BuildEnvironment.__init__..)ZnormalZoverlaycSsh|]}tj|qSr )rrnormcase)r+siter r r! Isz,BuildEnvironment.__init__..F)rTr/zsitecustomize.pywa 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)r _prefixes _bin_dirs _lib_dirsreversedlistvaluesappendrextendrrrrr( _site_direxistsmkdiropenwritetextwrapdedentformat)rrr2fpr r,r!r"7s0    zBuildEnvironment.__init__cCsndddD|_|jdd}|jd}|r>||tj|jg}tjtj |dtj |ddS)NcSsi|]}|tj|dqSr')renvirongetr*r r r! osz.BuildEnvironment.__enter__..)PATHZPYTHONNOUSERSITEZ PYTHONPATHrG1) _save_envr4r:splitrpathsepr;rDupdater()rrZold_pathZ pythonpathr r r! __enter__ns   zBuildEnvironment.__enter__cCs:|jD]*\}}|dkr*tj|dq |tj|<q dSr')rIitemsrrDpop)rexc_typeexc_valexc_tbZvarname old_valuer r r!__exit__szBuildEnvironment.__exit__cCs|jdSr')r)cleanupr,r r r!rUszBuildEnvironment.cleanupc Cst}t}|rt|j}|D]p}z"|t|dkrB||Wqtk r}z*|t|j d t|j dfW5d}~XYqXq||fS)zReturn 2 sets: - conflicting requirements: set of (installed, wanted) reqs tuples - missing requirements: set of reqs Nr) setrr5findrparseaddrstrargsZas_requirement)rZreqsZmissingZ conflictingZwsZreqer r r!check_requirementss  z#BuildEnvironment.check_requirementsc CsV|j|}d|_|sdStjtjtdddd|jdg}t t j krP| ddD]:}t |j|}|d |d d d t|pd hfqT|j} | r|d| dg| ddD]} |d| gqn | d|jD]} |d| gq|jD]} |d| gq|jr| d| d ||t|} t|| dW5QRXdS)NTZinstallz--ignore-installedz --no-userz--prefixz--no-warn-script-locationz-v)Z no_binaryZ only_binaryz--_-,z:none:z-irrVz--extra-index-urlz --no-indexz --find-linksz--trusted-hostz--pre)spinner)r3rsys executablerrdirname pip_locationloggerZgetEffectiveLevelloggingDEBUGr9getattrformat_controlr:replacer(sorted index_urlsZ find_linksZ trusted_hostsZallow_all_prereleasesr r )rfinder requirementsZprefix_as_stringmessagerr\rkZformatsrnZ extra_indexlinkZhostrbr r r!install_requirementssH           z%BuildEnvironment.install_requirementsN) r#r$r%__doc__r"rMrTrUr^rsr r r r!r&3s7r&c@s8eZdZdZddZddZddZdd Zd d Zd S) NoOpBuildEnvironmentz5A no-op drop-in replacement for BuildEnvironment cCsdSr'r r,r r r!r"szNoOpBuildEnvironment.__init__cCsdSr'r r,r r r!rMszNoOpBuildEnvironment.__enter__cCsdSr'r )rrPrQrRr r r!rTszNoOpBuildEnvironment.__exit__cCsdSr'r r,r r r!rUszNoOpBuildEnvironment.cleanupcCs tdSr')NotImplementedError)rrorprrqr r r!rssz)NoOpBuildEnvironment.install_requirementsN) r#r$r%rtr"rMrTrUrsr r r r!rus ru))rtrhrrcr@ collectionsrZdistutils.sysconfigrZ sysconfigrZpip._vendor.pkg_resourcesrrrZpiprrfZpip._internal.utils.subprocessr Zpip._internal.utils.temp_dirr Zpip._internal.utils.typingr Zpip._internal.utils.uir typingr rrrrZpip._internal.indexrZ getLoggerr#rgrobjectr&rur r r r!s*