U .e@sLddlmZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z ddlmZddlmZddlmZddlmZdd lmZdd lmZmZdd lmZdd lmZdd lm Z ddl!m"Z"ddl#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mm?Z?ddl@mAZAddlBmCZCmDZDddlEmFZFddlGmHZHddlImJZJddlKmLZLeHr.ddlMmNZNmOZOmPZPmQZQmRZRmSZSmTZTddlmUZUddlVmWZWdd lXmYZYdd!lZm[Z[dd"l\m]Z]dd#l^m_Z_e`eaZbGd$d%d%ecZddS)&)absolute_importN) change_root) pkg_resourcessix) Requirement)canonicalize_name)Version)parse)Pep517HookCaller) pep425tagswheel)NoOpBuildEnvironment)InstallationError)Link)get_metadata_generator)load_pyproject_tomlmake_pyproject_path)UninstallPathSet) native_str)Hashes) indent_log)PIP_DELETE_MARKER_FILENAMEhas_delete_marker_file) _make_build_dirask_path_exists backup_dir display_pathdist_in_install_pathdist_in_site_packagesdist_in_usersite ensure_dirget_installed_versionhide_urlredact_auth_from_urlrmtree) get_metadata)make_setuptools_shim_args)call_subprocessrunner_with_spinner_message) TempDirectory)MYPY_CHECK_RUNNING)running_under_virtualenv)vcs)AnyDictIterableListOptionalSequenceUnion)BuildEnvironment) WheelCache) PackageFinder) Distribution) SpecifierSet)Markerc @speZdZdZdPddZddZd d Zd d Zd dZe ddZ e ddZ e ddZ e ddZ dQddZe ddZdRddZddZd d!Zd"d#Zd$d%Zd&d'Ze d(d)ZdSd*d+Ze d,d-Ze d.d/Ze d0d1Zd2d3Zd4d5Zd6d7Ze d8d9Zd:d;Zdd?Z!dTd@dAZ"dUdBdCZ#dVdDdEZ$dFdGZ%dHdIZ&dJdKZ'dWdLdMZ(dNdOZ)dS)XInstallRequirementz Represents something that may be installed later on, may have information about where to fetch the relevant requirement and also contains logic for installing the said requirement. NFc Cs||_||_| |_|dkr"d|_ntjtj||_||_| |_ |dkr`|r`|j r`t |j }||_ |_ | rx| |_n |rdd|jD|_nt|_|dkr|r|j}||_d|_d|_d|_d|_d|_| r| ni|_d|_d|_||_t|_d|_d|_g|_d|_ ||_!dS)NcSsh|]}t|qSr;)rZ safe_extra.0extrar;r;A/usr/lib/python3.8/site-packages/pip/_internal/req/req_install.py wsz.InstallRequirement.__init__..F)"req comes_from constraint source_dirospathnormpathabspatheditable _wheel_cacheurlrlink original_linkextrassetmarkermarkers satisfied_byconflicts_with_temp_build_dir_ideal_build_dirinstall_succeededoptionsZpreparedZ is_directisolatedr build_envmetadata_directorypyproject_requiresrequirements_to_checkpep517_backend use_pep517) selfrArBrDrIrLrQr^rXrWZ wheel_cacherCrNr;r;r?__init__TsH    zInstallRequirement.__init__cCs|jr,t|j}|jrD|dt|jj7}n|jr@t|jj}nd}|jdk rb|dt|jj7}|jrt |jt j r~|j}n |j }|r|d|7}|S)Nz from %szz in %sz (from %s)) rAstrrLr#rKrRrlocationrB isinstancer string_types from_pathr_srBr;r;r?__str__s     zInstallRequirement.__str__cCsd|jjt||jfS)Nz<%s object: %s editable=%r>) __class____name__rarIr_r;r;r?__repr__s zInstallRequirement.__repr__cs>t|t}fddt|D}dj|jjd|dS)z>An un-tested helper for getting state, for debugging. c3s|]}d||VqdS)z{}={!r}N)format)r=attrZ attributesr;r? sz2InstallRequirement.format_debug..z<{name} object: {{{state}}}>z, )namestate)varssortedrmrirjjoin)r_namesrrr;ror? format_debugs zInstallRequirement.format_debugcCsh|jdkr||||_|jdk rd|sd|j}t}|jj|j|j|d|_||jkrdtd|jdS)aEnsure that if a link can be found for this, that it is found. Note that self.link may still be None - if Upgrade is False and the requirement is already installed. If require_hashes is True, don't use the wheel cache, because cached wheels, always built locally, have different hashes than the files downloaded from the index server and thus throw false hash mismatches. Furthermore, cached wheels at present have undeterministic contents due to file modification times. N)rLZ package_namesupported_tagszUsing cached wheel link: %s) rLZfind_requirementrJr Z get_supportedgetrqloggerdebug)r_finderZupgradeZrequire_hashesZold_linkrxr;r;r? populate_links  z InstallRequirement.populate_linkcCs |jdkrdStt|jjSN)rArrZ safe_namerqrkr;r;r?rqs zInstallRequirement.namecCs|jjSr~)rA specifierrkr;r;r?rszInstallRequirement.specifiercCs$|j}t|dko"tt|jdkS)zReturn whether I am pinned to an exact version. For example, some-package==1.2 is pinned; some-package>1.2 is not. >=====)rlennextiteroperator)r_Z specifiersr;r;r? is_pinneds zInstallRequirement.is_pinnedcCs t|jSr~)r!rqrkr;r;r?installed_versionsz$InstallRequirement.installed_versioncs0|sd}jdk r(tfdd|DSdSdS)N)c3s|]}jd|iVqdS)r>N)rQZevaluater<rkr;r?rpsz3InstallRequirement.match_markers..T)rQany)r_Zextras_requestedr;rkr? match_markers s  z InstallRequirement.match_markerscCst|jdiS)zReturn whether any known-good hashes are specified as options. These activate --require-hashes mode; hashes specified as part of a URL do not. hashes)boolrWryrkr;r;r?has_hash_optionss z#InstallRequirement.has_hash_optionsTcCsJ|jdi}|r|jn|j}|rB|jrB||jg|jt |S)aReturn a hash-comparer that considers my option- and URL-based hashes to be known-good. Hashes in URLs--ones embedded in the requirements file, not ones downloaded from an index server--are almost peers with ones from flags. They satisfy --require-hashes (whether it was implicitly or explicitly activated) but do not activate it. md5 and sha224 are not allowed in flags, which should nudge people toward good algos. We always OR all hashes together, even ones from URLs. :param trust_internet: Whether to trust URL-based (#md5=...) hashes downloaded from the internet, as by populate_link() r) rWrycopyrLrMhash setdefaultZ hash_nameappendr)r_Ztrust_internetZ good_hashesrLr;r;r?r#s  zInstallRequirement.hashescCsR|jdkrdSt|j}|jrNt|jtjr4|j}n |j}|rN|d|7}|S)z@Format a nice indicator to show where this "comes from" Nz->)rArarBrcrrdrerfr;r;r?re9s    zInstallRequirement.from_pathcCs||jdk r|jjS|jdkr6tdd|_||_|jjS|jrH|j}n|j}tj |snt d|t |tj ||S)Nz req-buildkindzCreating directory %s)rTrFrAr)rUrIrqlowerrEexistsrzr{rru)r_ build_dirrqr;r;r?ensure_build_locationIs      z(InstallRequirement.ensure_build_locationcCs|jdk rdS|j}d|_||j}tj|rBtdt|t d|t|jt|t |j|tj tj||_t|dd|_|jr|j}tjj||jd}tj||}tj tj|}||_d|_dS)aMove self._temp_build_dir to "self._ideal_build_dir/self.req.name" For some requirements (e.g. a path to a directory), the name of the package is not available until we run egg_info, so the build_location will return a temporary directory and store the _ideal_build_dir. This is only called to "fix" the build directory after generating metadata. NzCannot update repository at %s; repository location is unknownfile+r)rK) rLrzr{rDZschemerKrr,Z get_backendr"obtainZexport)r_rZvc_typerKZ vcs_backendZ hidden_urlr;r;r?update_editables    z"InstallRequirement.update_editablecCsB||std|jdS|jp&|j}t|}||||S)a Uninstall the distribution currently satisfying this requirement. Prompts before removing or modifying files unless ``auto_confirm`` is True. Refuses to delete or modify files outside of ``sys.prefix`` - thus uninstallation within a virtual environment can only modify that virtual environment, even if the virtualenv is linked to global site-packages. z#Skipping %s as it is not installed.N) rrzrrqrRrSrZ from_distremove)r_Z auto_confirmverboserZdistZuninstalled_pathsetr;r;r? uninstalls    zInstallRequirement.uninstallcCs(|t|dd}|tjjd}|S)Nr/)rreplacerErFr)r_rqrr;r;r?_clean_zip_namesz"InstallRequirement._clean_zip_namecCs(tj||}|||}|jd|S)Nr)rErFrurrq)r_rF parentdirrootdirrqr;r;r?_get_archive_names z$InstallRequirement._get_archive_namec Csd}d|j|jdf}tj||}tj|rtdt|d}|dkrRd}nj|dkrvt d t|t |nF|d krt |}t d t|t|t ||n|d krtd |sdStj|dtjdd}|tjtj|j}t|D]\} } } d| kr| d| D]6} |j| | |d} t| d}d|_||dq | D]>}|tkrnq\|j|| |d}tj| |}|||q\qW5QRXtdt|dS)z}Saves archive to provided build_dir. Used for saving downloaded VCS requirements as part of `pip download`. Tz %s-%s.ziprz8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort )iwbarFrz Deleting %srzBacking up %s to %srN)Z allowZip64z pip-egg-info)rrrirzSaved %s)rqrrErFrurrrrzrrrrrrexitzipfileZZipFileZ ZIP_DEFLATEDnormcaserHrwalkrZZipInfoZ external_attrZwritestrrwriter)r_rZcreate_archiveZ archive_nameZ archive_pathZresponseZ dest_fileZ zip_outputdirdirpathZdirnames filenamesdirnameZ dir_arcnameZzipdirfilenameZ file_arcnamer;r;r?archivesx       zInstallRequirement.archivec  sh|dk r |ng}|jr*|j|||ddS|jrnt|j} t| |j|j|j|||||dd|_ dSt ||j dg}t ||j dg}t dd} tj| jd} ||| ||} td |j} t*|j| | ||jd W5QRXW5QRXtj| s8td | W5QRdSd|_ fd d }t| \}|D],}tj|}|drX||}qqXtd|W5QRW5QRdSW5QRXg}t| L}|D]@}|}tj|r|tjj 7}|!tj"|||qW5QRX|#t$|tj|d}t|d}|%d|dW5QRXW5QRXdS)N)r)rrrrrrTrrrecordrzinstall-record.txtzRunning setup.py install for {})cmdrzRecord file %s not foundcs&dkstj|s|St|SdSr~)rErFisabsr)rFrr;r? prepend_rootsz0InstallRequirement.install..prepend_rootrz;Could not find .egg-info directory in install record for %szinstalled-files.txtr )&rIrrr Z wheel_versionrDZcheck_compatibilityrqrrVrrWryr)rErFruget_install_argsr(rmrrYrrrzr{openrrrstripisdirrrrsortr r)r_rrrrrrrrrZtemp_dirrecord_filename install_argsrrflineZ directoryZ egg_info_dirZ new_linesrZinst_files_pathr;rr?installEs           "   zInstallRequirement.installc Cst|j||jdd}|dd|g7}|dg7}|dk r@|d|g7}|dk rT|d|g7}|rd|dg7}n |d g7}trd t}|d tjt j d d ||j g7}|S)NT)rrZunbuffered_outputrz--recordz#--single-version-externally-managedz--rootz--prefixz --compilez --no-compilepythonz--install-headersZincludeZsite) r&rrXr+ sysconfigZget_python_versionrErFrurrrq)r_rrrrrrZ py_ver_strr;r;r?rs0       z#InstallRequirement.get_install_args) NFNNNFNNFr;)N)T)NNNTFT)r;N)T)FFF)NNNNTFT)*rj __module__ __qualname____doc__r`rhrlrwr}propertyrqrrrrrrrerrrrrrrrrrrrrrrrrrrrrrrrr;r;r;r?r:Ms  W      8 +     %     B `r:)eZ __future__rrZloggingrErrrrZdistutils.utilrZ pip._vendorrrZ"pip._vendor.packaging.requirementsrZpip._vendor.packaging.utilsrZpip._vendor.packaging.versionrr rZpip._vendor.pep517.wrappersr Z pip._internalr r Zpip._internal.build_envr Zpip._internal.exceptionsrZpip._internal.models.linkrZ*pip._internal.operations.generate_metadatarZpip._internal.pyprojectrrZpip._internal.req.req_uninstallrZpip._internal.utils.compatrZpip._internal.utils.hashesrZpip._internal.utils.loggingrZ pip._internal.utils.marker_filesrrZpip._internal.utils.miscrrrrrrrr r!r"r#r$Zpip._internal.utils.packagingr%Z$pip._internal.utils.setuptools_buildr&Zpip._internal.utils.subprocessr'r(Zpip._internal.utils.temp_dirr)Zpip._internal.utils.typingr*Zpip._internal.utils.virtualenvr+Zpip._internal.vcsr,typingr-r.r/r0r1r2r3r4Zpip._internal.cacher5Zpip._internal.indexr6Zpip._vendor.pkg_resourcesr7Z pip._vendor.packaging.specifiersr8Zpip._vendor.packaging.markersr9Z getLoggerrjrzobjectr:r;r;r;r?sV               8      $