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 Cs2|dkst|tst|||_||_| |_|dkrwsz.InstallRequirement.__init__..F)% isinstancerAssertionErrorreq 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) selfrCrDrFrKrNrSr`rZrYZ wheel_cacherErPr;r;r?__init__TsJ    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)) rCstrrNr#rMrTrlocationrDrAr string_types from_pathrasrDr;r;r?__str__s     zInstallRequirement.__str__cCsd|jjt||jfS)Nz<%s object: %s editable=%r>) __class____name__rcrKrar;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)varssortedrnrjrkjoin)ranamesrsr;rpr? 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)rNZ package_namesupported_tagszUsing cached wheel link: %s) rNZfind_requirementrLr Z get_supportedgetrrloggerdebug)rafinderZupgradeZrequire_hashesZold_linkryr;r;r? populate_links  z InstallRequirement.populate_linkcCs |jdkrdStt|jjSN)rCrrZ safe_namerrrlr;r;r?rrs zInstallRequirement.namecCs|jjSr)rC specifierrlr;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)raZ specifiersr;r;r? is_pinneds zInstallRequirement.is_pinnedcCs t|jSr)r!rrrlr;r;r?installed_versionsz$InstallRequirement.installed_versioncs0|sd}jdk r(tfdd|DSdSdS)N)c3s|]}jd|iVqdS)r>N)rSZevaluater<rlr;r?rqsz3InstallRequirement.match_markers..T)rSany)raZextras_requestedr;rlr? 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)boolrYrzrlr;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) rYrzcopyrNrOhash setdefaultZ hash_nameappendr)raZtrust_internetZ good_hashesrNr;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->)rCrcrDrArrerfrgr;r;r?rf9s    zInstallRequirement.from_pathcCs|dk s t|jdk r*|jjs"t|jjS|jdkrNtdd|_||_|jjS|jr`|j}n|j}t j |st d|t |t j||S)Nz req-buildkindzCreating directory %s)rBrVrHrCr)rWrKrrlowerrGexistsr{r|rrv)ra build_dirrrr;r;r?ensure_build_locationIs        z(InstallRequirement.ensure_build_locationcCs|jdk rdS|jdk st|js&t|jdk r8|jjsCannot update repository at %s; repository location is unknownfile+z bad url: %rr)rMrz+Unexpected version control type (in %s): %s)rNr{r|rFrKrBZschemerMrr,Z get_backendr"obtainZexport)rarZvc_typerMZ 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) rr{rrrrTrUrZ from_distremove)raZ auto_confirmverboserZdistZuninstalled_pathsetr;r;r? uninstalls    zInstallRequirement.uninstallcCsJ||tjjs"td||f|t|dd}|tjjd}|S)Nz$name %r doesn't start with prefix %rr/) startswithrGrHrrBrreplace)rarrrr;r;r?_clean_zip_names  z"InstallRequirement._clean_zip_namecCs(tj||}|||}|jd|S)Nr)rGrHrvrrr)rarH parentdirrootdirrrr;r;r?_get_archive_names z$InstallRequirement._get_archive_namec Cs|js td}d|j|jdf}tj||}tj|rtdt |d}|dkr\d}nj|dkrt 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]>}|tkrxqf|j|| |d}tj| |}|||qfqW5QRXt dt |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) rFrBrrrrGrHrvrrrr{rrrrrrexitzipfileZZipFileZ ZIP_DEFLATEDnormcaserJrwalkrZZipInfoZ external_attrZwritestrrwriter)rarZcreate_archiveZ archive_nameZ archive_pathZresponseZ dest_fileZ zip_outputdirdirpathZdirnames filenamesdirnameZ dir_arcnameZzipdirfilenameZ file_arcnamer;r;r?archivesz        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)rGrHisabsr)rHrr;r? prepend_rootsz0InstallRequirement.install..prepend_rootrz;Could not find .egg-info directory in install record for %szinstalled-files.txtr )&rKrrr Z wheel_versionrFZcheck_compatibilityrrrrXrrYrzr)rGrHrvget_install_argsr(rnrr[rrr{r|openrrrstripisdirrrrsortr r)rarrrrrrrrrZtemp_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&rrZr+ sysconfigZget_python_versionrGrHrvrrrr)rarrrrrrZ py_ver_strr;r;r?rs0       z#InstallRequirement.get_install_args) NFNNNFNNFr;)N)T)NNNTFT)r;N)T)FFF)NNNNTFT)*rk __module__ __qualname____doc__rbrirmrxr~propertyrrrrrrrrrfrrrrrrrrrrrrrrrrrrrrrrrrr;r;r;r?r:Ms  W      8 +     %     B `r:)eZ __future__rrZloggingrGrrrrZdistutils.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 getLoggerrkr{objectr:r;r;r;r?sV               8      $