3 Pf@s0ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZddlmZddlmZmZddlmZddlmZdd lmZmZdd lmZdd lmZmZ dd l!m"Z"ddl#Z$dd l%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGddlHmIZIddlJmKZKddlLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUddl#mVZVmWZWejXeYZZej[j\j]Z^ddZ_ddZ`GdddeaZbd d!Zcd$d"d#ZddS)%)absolute_importN) sysconfig) change_root) FeedParser) pkg_resourcessix) specifiers)Marker)InvalidRequirement Requirement)canonicalize_name)Versionparse) configparser) native_str get_stdlibWINDOWS)is_url url_to_path path_to_urlis_archive_file)InstallationErrorUninstallationError)bin_pyrunning_under_virtualenvPIP_DELETE_MARKER_FILENAMEbin_user) display_pathrmtreeask_path_exists backup_diris_installable_dirdist_in_usersitedist_in_site_packagesdist_in_install_path egg_link_pathcall_subprocessread_text_fileFakeFile_make_build_dir ensure_dirget_installed_versionnormalize_path dist_is_local)Hashes)RemovedInPip10Warning) indent_log)SETUPTOOLS_SHIM) open_spinner)UninstallPathSet)vcs)move_wheel_filesWheelcCs6tjd|}d}|r*|jd}|jd}n|}||fS)Nz^(.+)(\[[^\]]+\])$)rematchgroup)pathmextrasZpath_no_extrasr?!/usr/lib/python3.6/req_install.py _strip_extras9s   rAcCstdd|DS)Ncss|]}tj|VqdS)N)rZ safe_extra).0extrar?r?r@ Fsz_safe_extras..)set)r>r?r?r@ _safe_extrasEsrFc @seZdZdQddZedRddZedSdd Zd d Zd d ZddZ e ddZ e ddZ ddZ ddZddZe ddZe ddZe ddZd d!Zd"d#Zd$d%Zd&d'Zejd(Ze d)d*Zd+d,ZdTd-d.ZdUd/d0Zd1d2Zd3d4Zd5d6Z d7d8Z!dVd9d:Z"gdddfd;d<Z#d=d>Z$d?d@Z%dAdBZ&fdfdCdDZ'dEdFZ(e dGdHZ)dWdIdJZ*dKdLZ+e dMdNZ,dXdOdPZ-dS)YInstallRequirementNFTc sJf|_ttjry tWndtk rtjjkr@d}n.dkrft fddt D rfd}nt j }t d|fYnXtj|_|_||_| |_||_||_| |_||_|_||_| dk r| |_n oވj|_d|_d|_d|_d|_d|_||_d|_ d|_!d|_"d|_#d|_$| r.| ni|_%||_&d|_'| |_(dS)Nz%It looks like a path. Does it exist ?=c3s|]}|kVqdS)Nr?)rBop)reqr?r@rDVsz.InstallRequirement.__init__..z,= is not a valid operator. Did you mean == ?zInvalid requirement: '%s' %sF))r> isinstancer string_typesr r osr<sepany operators traceback format_excrrFrJ comes_from constraint source_direditable _wheel_cachelink original_linkas_eggmarkersmarker_egg_info_path satisfied_byconflicts_with_temp_build_dir_ideal_build_dirupdateinstall_succeeded uninstallednothing_to_uninstall use_user_site target_diroptions pycompileZpreparedisolated)selfrJrSrUrVrXrZrbrir[rjrh wheel_cacherTadd_msgr?)rJr@__init__KsN       zInstallRequirement.__init__c Cspddlm}t||\} } } | jdr0t| } nd} || || d|| |||rP|ni|d } | dk rlt| | _| S)Nr)Linkzfile:T)rUrVrXrTrjrhrl) pip.indexroparse_editable startswithrrFr>)cls editable_reqrS default_vcsrjrhrlrTronameurlZextras_overriderUresr?r?r@ from_editables      z InstallRequirement.from_editablec Csddlm}t|rd}nd}||krR|j|d\}} | j} | sHd} qVt| } nd} |j}d} tjjtjj |} d} d} t|r||} nt | \}} tjj |rtjj |ks|j drt|std||t|} n0t|rtjj|stjd ||t|} | r|| jd krPtjd | jrP|ttjjtjj | j} | jrtt| j}d |j|jf} n| j} n|} |r|ni}|| || | ||||d }| rtt d| j!|_!|S)zCreates an InstallRequirement from a name, which might be a requirement, directory containing 'setup.py', filename, or URL. r)roz; ;r7N.z;Directory %r is not installable. File 'setup.py' not found.zARequirement %r looks like a filename, but the file does not existfilez\.\./z%s==%s)rXr[rjrhrlrT placeholder)"rprorsplitstripr rMr<normpathabspathrAisdirrNrrr!rrrisfileloggerwarningschemer9searchrwis_wheelr6filenamervversion egg_fragmentrFr r>)rsrvrSrjrhrlrTroZ marker_sepr[rJr<rXr>pwheelrxr?r?r@ from_linesb          zInstallRequirement.from_linecCs|jr(t|j}|jr:|d|jj7}n|jr6|jjnd}|jdk rX|dt|jj7}|jrt|jt j rt|j}n |jj }|r|d|7}|S)Nz from %sz in %sz (from %s)) rJstrrXrwr^rlocationrSrKrrL from_path)rksrSr?r?r@__str__s    zInstallRequirement.__str__cCsd|jjt||jfS)Nz<%s object: %s editable=%r>) __class____name__rrV)rkr?r?r@__repr__szInstallRequirement.__repr__cCs^|jdkr|j|||_|jdk rZ| rZ|j}|jj|j|j|_||jkrZtjd|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. NzUsing cached wheel link: %s)rXZfind_requirementrWZ cached_wheelrvrdebug)rkfinderZupgradeZrequire_hashesZold_linkr?r?r@ populate_link s  z InstallRequirement.populate_linkcCs|jjS)N)rJ specifier)rkr?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. r7=====)rr)rlennextiteroperator)rkrr?r?r@ is_pinned!s zInstallRequirement.is_pinnedcCsR|jdkrdSt|j}|jrNt|jtjr4|j}n |jj}|rN|d|7}|S)Nz->)rJrrSrKrrLr)rkrrSr?r?r@r+s    zInstallRequirement.from_pathcCs|jdk r|jS|jdkrsz4InstallRequirement.egg_info_path..cSsg|]}|jdr|qS)z .egg-info)endswith)rBfr?r?r@rsz$No files/directories in %s (from %s)r7cSs(|jtjjtjjr"|jtjjp$dS)Nr)countrMr<rNaltsep)xr?r?r@ s z2InstallRequirement.egg_info_path..)keyr)r]rVrUrMr<rrlistdirwalkr4dirnamesremovelistlexistsrextendrrsort)rkrbase filenamesdirsfilesrr?)rr@rs>     z InstallRequirement.egg_info_pathcCs@t}|jd}|s*tjdt|jd|j|p4d|jS)NzPKG-INFOzNo PKG-INFO file found in %sr)rrrrrrZfeedclose)rkrrr?r?r@rs zInstallRequirement.pkg_infoz \[(.*?)\]cCs t|jS)N)r+rv)rkr?r?r@installed_version sz$InstallRequirement.installed_versioncCsL|jd}|jjr2||jjkr2tjd||jntjdt|j||dS)Nrz'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s) rrJrrrrrrrU)rkrr?r?r@assert_source_matches_version$s  z0InstallRequirement.assert_source_matches_versioncCs|jstjd|jdS|jjdkr(dS|js2dS|jjjdd\}}tj |}|r||jj}|rr|j |jq|j |jndS)Nz>Cannot update repository at %s; repository location is unknownr|+r7) rXrrrUrrbrwr~r4 get_backendobtainZexport)rkrvc_typerwbackendZ vcs_backendr?r?r@update_editable5s"   z"InstallRequirement.update_editablec sT|jstd|jf|jp"|j}t|j}t|sTtj d|j |t j d|_ dS|tkrxtj d|j |d|_ dSt|}t|}djtj|j}|jotjj|j}t|jdd}|o|jjdo|jj| r|j|j|jd r2x|jd jD](} tjj tjj!|j| } |j| qWn|jd r|jd rV|jd ngxjfd d |jd jDD]J} tjj!|j| } |j| |j| d|j| d|j| dqxWn$|rt"j#dj|jt$|j|n|jjdrF|j|jtjj%|jd} tjj!tjj&|jd} |j'| d| n|r~|jjdr~xt(j)j*|D]} |j| qhWnp|rt+|d}tjj,|j-j.}WdQRX|j|tjj!tjj&|d} |j'| |jntj/d||j|jdrb|j0drbxZ|j1dD]L}t2|r&t3}nt4}|jtjj!||t5r|jtjj!||dqW|jdr@t6j7r|i}ndd"i}t8j9f|}|j:t;|jdD]\}}t2|rt3}nt4}|jtjj!||t5r|jtjj!||d|jtjj!||d |jtjj!||d!qW|j?|||_@dS)#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.Cannot uninstall requirement %s, not installedz1Not uninstalling %s at %s, outside environment %sTNz.z.pyz.pycz.pyozUninstalling a distutils installed project ({0}) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.z.eggr7zeasy-install.pthz./z .dist-inforz)Not sure how to uninstall: %s - Check: %sscriptsz.batzentry_points.txtZ delimitersrHZconsole_scriptsz.exez .exe.manifestz -script.py)rH)Acheck_if_existsrrvr^r_r,rr-rinforrprefixrerr3r%formatrZ to_filename project_namerrMr<rgetattrZ _providerraddrr splitlinesrrwarningswarnr/r~dirnameZadd_pthpiprZuninstallation_pathsopennormcasereadlinerrZmetadata_isdirZmetadata_listdirr"rrrrrrZSafeConfigParserZreadfpr(Zget_metadata_linesZ has_sectionitemsrrd)rkZ auto_confirmZdistZ dist_pathZpaths_to_removeZdevelop_egg_linkZdevelop_egg_link_egg_infoZegg_info_existsZdistutils_egg_infoZinstalled_filer<Z top_level_pkgZeasy_install_eggZeasy_install_pthZfhZ link_pointerrZbin_dirrhconfigrvvaluer?)rr@ uninstallRs                      zInstallRequirement.uninstallcCs$|jr|jjntjd|jdS)Nz'Can't rollback %s, nothing uninstalled.)rdZrollbackrerrorrv)rkr?r?r@rollback_uninstalls z%InstallRequirement.rollback_uninstallcCs*|jr|jjn|js&tjd|jdS)Nz%Can't commit %s, nothing uninstalled.)rdZcommitrerrrv)rkr?r?r@commit_uninstalls  z#InstallRequirement.commit_uninstallcCsd}d|j|jdf}tjj||}tjj|rtdt|d}|dkrTd }nj|dkrxtj d t|tj |nF|dkrt |}tj d t|t|t j ||n|dkrtjd|rtj|dtjdd }tjjtjj|j}xtj|D]\} } } d| kr| j dxR| D]J} tjj| | } |j| |} tj|jd| d}d|_|j|dqWxL| D]D}|tkrqrtjj| |}|j||} |j||jd| qrWqW|jtjdt|dS)NTz %s-%s.ziprz8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort iwbaFz Deleting %szBacking up %s to %sr7)Z allowZip64z pip-egg-info/irzSaved %s)rrrri)rvrrMr<rrrrrrrr rrrexitzipfileZZipFileZ ZIP_DEFLATEDrrrr_clean_zip_nameZZipInfoZ external_attrZwritestrrwriterr)rkrZcreate_archiveZ archive_nameZ archive_pathZresponseZ dest_fileziprdirpathrrrrvZzipdirrr?r?r@archivesV           "zInstallRequirement.archivecCs(|t|dd}|jtjjd}|S)Nr7r)rreplacerMr<rN)rkrvrr?r?r@r5sz"InstallRequirement._clean_zip_namecs0|sd}jdk r(tfdd|DSdSdS)Nrc3s|]}jjd|iVqdS)rCN)r[Zevaluate)rBrC)rkr?r@rDDsz3InstallRequirement.match_markers..T)r)r[rO)rkZextras_requestedr?)rkr@ match_markers=s   z InstallRequirement.match_markersc,s`|jr|j|||ddS|jr\tjj|j}tjj||j|j |j||dd|_ dS||j j dg7}||j j dg7}|j rt|dg}tjdd}tjj|d }z|j|||} d |jf} t| .} tt| ||jd | d WdQRXWdQRXtjj|s(tjd |dSd|_ |jr:dSfdd} t|H} x@| D](}tjj|}|jdrV| |}PqVWtj d|dSWdQRXg}t|P} xH| D]@}|j!}tjj"|r|tjj#7}|j$tjj%| ||qWWdQRXtjj|d}t|d} | j&dj|dWdQRXWdtjj|rRtj'|t(|XdS)N)r)rrstrip_file_prefixTglobal_optionsinstall_optionsz --no-user-cfgz-recordzpip-zinstall-record.txtzRunning setup.py install for %sF)rrspinnerzRecord file %s not foundcs(dkstjj| r|St|SdS)N)rMr<isabsr)r<)rr?r@ prepend_root~sz0InstallRequirement.install..prepend_rootz .egg-infoz;Could not find .egg-info directory in install record for %szinstalled-files.txtr ))rVinstall_editablerrrZ wheel_versionrUZcheck_compatibilityrvr5rcrhgetrjrrrrMr<rget_install_argsr2r0r&rrrrrZrrrrrrrNappendrelpathr rr)rkrrrrrrZ temp_locationrecord_filename install_argsmsgrrrlineZ directoryrZ new_linesrZinst_files_pathr?)rr@installIs~               " zInstallRequirement.installcCs|jdkr|j||_|jS)aAEnsure that a source_dir is set. This will create a temporary build dir if the name of the requirement isn't known yet. :param parent_dir: The ideal pip parent_dir for the source_dir. Generally src_dir for editables and build_dir for sdists. :return: self.source_dir N)rUr)rkZ parent_dirr?r?r@ensure_has_source_dirs  z(InstallRequirement.ensure_has_source_dircCstjdg}|jd|jt|j|t|dd|g7}|jsJ|dg7}|dk r^|d|g7}|dk rr|d|g7}|jr|dg7}n |d g7}trd t j }|d t j j tjd d ||jg7}|S)Nz-uz-crz--recordz#--single-version-externally-managedz--rootz--prefixz --compilez --no-compilerz--install-headersincludeZsite)rrrr1rrrZrirrget_python_versionrMr<rrrv)rkrrrrrZ py_ver_strr?r?r@rs(        z#InstallRequirement.get_install_argscCsd|jr6tjjtjj|jtr6tjd|jt|jd|_|j rZtjj|j rZt|j d|_ dS)zVRemove the source files from this requirement, if they are marked for deletionzRemoving source in %sN) rUrMr<rrrrrrr`)rkr?r?r@remove_temporary_sources   z*InstallRequirement.remove_temporary_sourcec Cstjd|j|jr"t|dg}|r>dj|g}t||}t<ttj dt |j gt|ddgt||j ddWdQRXd |_ dS) NzRunning setup.py develop for %sz --no-user-cfgz --prefix={0}z-cZdevelopz --no-depsF)rrT)rrrvrjrrr0r&rrr1rrrc)rkrrrZ prefix_paramr?r?r@rs   z#InstallRequirement.install_editablec Cs|jdkrdSyFtt|j}d|_tjt||_|jrR|jrR|j|_d|_dSWntj k rjdStj k rtj|jj }|j rt |r||_qtrt|rtd|j|jfnt|r||_YnXdS)zFind an installed distribution that satisfies or conflicts with this requirement, and set self.satisfied_by or self.conflicts_with appropriately. NFTzVWill not install to the user site because it will lack sys.path precedence to %s in %s)rJr rr\rZget_distributionr^rVr_ZDistributionNotFoundZVersionConflictrvrfr"rr#rrrr$)rkZ no_markerZ existing_distr?r?r@rs4    z"InstallRequirement.check_if_existscCs|jo |jjS)N)rXr)rkr?r?r@r szInstallRequirement.is_wheelc Cs,t|j|j||j|j|||j|j|d dS)N)userhomerrrirjr)r5rvrJrfrgrirj)rkZwheeldirrrrr?r?r@r5$s z#InstallRequirement.move_wheel_filescCsX|jdjd}tjj|}tj||}tjjtjj|d}tj tjj|||dS)zAReturn a pkg_resources.Distribution built from self.egg_info_pathrrr)rmetadata) rrstriprMr<rrZ PathMetadatasplitextbasenameZ Distribution)rkrZbase_dirr&Z dist_namer?r?r@get_dist0s   zInstallRequirement.get_distcCst|jjdiS)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)boolrhr)rkr?r?r@has_hash_options;sz#InstallRequirement.has_hash_optionscCsJ|jjdij}|r|jn|j}|rB|jrB|j|jgj|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+) rhrcopyrXrYhash setdefaultZ hash_namerr.)rkZtrust_internetZ good_hashesrXr?r?r@r+Es  zInstallRequirement.hashes) NFNFTTNFNNF)NNFNNF)NFNNF)T)F)N)NNN)T).r __module__ __qualname__rn classmethodryrrrrpropertyrrrrrrvrrrrrrr9compileZ_requirements_section_rerrrrrrr rrrr rr#rrrr5r*r-r+r?r?r?r@rGIs` ;  M      : 6    $0 \ )   rGcCstjd|}|r|jd}|S)z2 Strip req postfix ( -dev, 0.2, etc ) z^(.*?)(?:-dev|-\d.*)$r7)r9rr;)rJr:r?r?r@_strip_postfix[s  r6c Csddlm}|}d}tjd|}|r:|jd}|jd}n|}tjj|rttjjtjj |dslt d|t |}|j j d r||j}|r||td |j jfS||dfSx,tD]$}|j j d |rd ||f}PqWd |kr|r tjdt|d |}n t d||jd ddj } tj| s`d|dj ddtjDd} t | ||j}|sxt d|st d|t||dfS)aParses an editable requirement into: - a requirement name - an URL - extras - editable options Accepted requirements: svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir .[some_extra] r)roNz^(.+)(\[[^\]]+\])$r7r8zsetup.pyz;Directory %r is not installable. File 'setup.py' not found.zfile:r}z%s:z%s+%srzD--default-vcs has been deprecated and will be removed in the future.zb%s should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+zFor --editable=%s only z, cSsg|]}|jdqS)z+URL)rv)rBrr?r?r@rsz"parse_editable..z is currently supportedz@Could not detect requirement name, please specify one with #egg=z@--editable=%s is not the right format; it must have #egg=Package)rpror9r:r;rMr<rrrrrrrrrr r>r4rrr/r~rZbackendsr6) rtrurorwr>r=Z url_no_extrasZ package_nameZversion_controlrZ error_messager?r?r@rqgs`            rq)N)eZ __future__rZloggingrMr9rrrrQrrZ distutilsrZdistutils.utilrZ email.parserrZ pip._vendorrrZpip._vendor.packagingrZpip._vendor.packaging.markersr Z"pip._vendor.packaging.requirementsr r Zpip._vendor.packaging.utilsr Zpip._vendor.packaging.versionr rrZpip._vendor.six.movesrZ pip.wheelrZ pip.compatrrrZ pip.downloadrrrrZpip.exceptionsrrZ pip.locationsrrrrZ pip.utilsrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-Zpip.utils.hashesr.Zpip.utils.deprecationr/Zpip.utils.loggingr0Zpip.utils.setuptools_buildr1Z pip.utils.uir2Zpip.req.req_uninstallr3Zpip.vcsr4r5r6Z getLoggerrrZ SpecifierZ _operatorskeysrPrArFobjectrGr6rqr?r?r?r@s`        L