3 ]@s,ddlmZddlZddlZddlZddlZddlZddlZddlZddl 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@mAZAmBZBmCZCmDZDmEZEmFZFddlGmHZHddlImJZJddlKmLZLddlMmNZNddlOmPZPddlQmRZRddlSmTZTddl#mUZUmVZVejWeXZYejZj[j\Z]ddZ^ddZ_Gddde`Zad d!Zbd$d"d#ZcdS)%)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_packages 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)pathmextraspath_no_extrasr?2/tmp/pip-build-8jg9gmni/pip/pip/req/req_install.py _strip_extras9s   rAcCstdd|DS)Ncss|]}tj|VqdS)N)r safe_extra).0extrar?r?r@ Fsz_safe_extras..)set)r=r?r?r@ _safe_extrasEsrGc @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"gddfd;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?)rCop)reqr?r@rEVsz.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_excrrGrK 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 pycompilepreparedisolated)selfrKrTrVrWrYr[rcrjr\rlri wheel_cacherUadd_msgr?)rKr@__init__KsN       zInstallRequirement.__init__c Cspddlm}t||\} } } | jdr0t| } nd} || || d|| |||rP|ni|d } | dk rlt| | _| S)Nr)Linkzfile:T)rVrWrYrUrlrirn) pip.indexrqparse_editable startswithrrGr=)cls editable_reqrT default_vcsrlrirnrUrqnameurlextras_overriderVresr?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)rqz; ;r6N.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)rYr\rlrirnrU placeholder)"rrrqrsplitstripr rNr;normpathabspathrAisdirrOrtr!rrrisfileloggerwarningschemer8searchryis_wheelr5filenamerxversion egg_fragmentrGr r=)rurxrTrlrirnrUrq marker_sepr\rKr;rYr=pwheelr{r?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)) rKstrrYryr_rlocationrTrLrrM from_path)rmsrTr?r?r@__str__s    zInstallRequirement.__str__cCsd|jjt||jfS)Nz<%s object: %s editable=%r>) __class____name__rrW)rmr?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)rYfind_requirementrX cached_wheelrxrdebug)rmfinderupgraderequire_hashesold_linkr?r?r@ populate_link s  z InstallRequirement.populate_linkcCs|jjS)N)rK specifier)rmr?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. r6=====)rr)rlennextiteroperator)rmrr?r?r@ is_pinned!s zInstallRequirement.is_pinnedcCsR|jdkrdSt|j}|jrNt|jtjr4|j}n |jj}|rN|d|7}|S)Nz->)rKrrTrLrrMr)rmrrTr?r?r@r+s    zInstallRequirement.from_pathcCs|jdk r|jS|jdkrsz4InstallRequirement.egg_info_path..cSsg|]}|jdr|qS)z .egg-info)endswith)rCfr?r?r@rsz$No files/directories in %s (from %s)r6cSs(|jtjjtjjr"|jtjjp$dS)Nr)countrNr;rOaltsep)xr?r?r@ s z2InstallRequirement.egg_info_path..)keyr)r^rWrVrNr;rrlistdirwalkr3dirnamesremovelistlexistsrextendrrrsort)rmrbase filenamesdirsfilesrr?)rr@rsB     z InstallRequirement.egg_info_pathcCs@t}|jd}|s*tjdt|jd|j|p4d|jS)NzPKG-INFOzNo PKG-INFO file found in %sr)rrrrrrfeedclose)rmrrr?r?r@rs zInstallRequirement.pkg_infoz \[(.*?)\]cCs t|jS)N)r*rx)rmr?r?r@installed_version sz$InstallRequirement.installed_versioncCsV|js t|jd}|jjr<||jjkrCannot update repository at %s; repository location is unknownr+z bad url: %rr6rz+Unexpected version control type (in %s): %s)rYrrrVrWrrryrcrr3 get_backendobtainexport)rmrvc_typerybackend vcs_backendr?r?r@update_editable5s,     z"InstallRequirement.update_editablec sx|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| dqxWnH|rt"j#dj|jt$|j|n |jjdrH|j|jtjj%|jd} tjj!tjj&|jd} |j'| d| n|r|jjdrxt(j)j*|D]} |j| qjWn|rt+|d}tjj,|j-j.}WdQRX||jkst/d||j|jf|j|tjj!tjj&|d} |j'| |jntj0d||j|jdr|j1drxZ|j2dD]L}t3|rJt4}nt5}|jtjj!||t6r6|jtjj!||dq6W|jdrdt7j8ri}ndd#i}t9j:f|}|j;t<|j=d|j>drdx|j?dD]\}}t3|rt4}nt5}|jtjj!||t6r|jtjj!||d |jtjj!||d!|jtjj!||d"qW|j@|||_AdS)$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.eggr6zeasy-install.pthz./z .dist-inforz;Egg-link %s does not match installed location of %s (at %s)z)Not sure how to uninstall: %s - Check: %sscriptsz.batzentry_points.txt delimitersrIconsole_scriptsz.exez .exe.manifestz -script.py)rI)Bcheck_if_existsrrxr_r`r+rr,rinforrprefixrfrr2r$formatr to_filename project_namerrNr;rgetattr _providerraddrr splitlinesrrwarningswarnr.rdirnameadd_pthpipruninstallation_pathsopennormcasereadlinerrrmetadata_isdirmetadata_listdirr"rrrrrrSafeConfigParserreadfpr'get_metadata_lines has_sectionitemsrre)rm auto_confirmdist dist_pathpaths_to_removedevelop_egg_linkdevelop_egg_link_egg_infoegg_info_existsdistutils_egg_infoinstalled_filer; top_level_pkgeasy_install_eggeasy_install_pthfh link_pointerrbin_dirriconfigrxvaluer?)rr@ uninstallRs                     zInstallRequirement.uninstallcCs$|jr|jjntjd|jdS)Nz'Can't rollback %s, nothing uninstalled.)rerollbackrerrorrx)rmr?r?r@rollback_uninstalls z%InstallRequirement.rollback_uninstallcCs*|jr|jjn|js&tjd|jdS)Nz%Can't commit %s, nothing uninstalled.)recommitrfrr2rx)rmr?r?r@commit_uninstalls  z#InstallRequirement.commit_uninstallcCs|js td}d|j|jdf}tjj||}tjj|rtdt |d}|dkr^d }nj|dkrt j d t |tj |nF|dkrt |}t j d t |t |tj||n|dkrtjd|rtj|dtjdd }tjjtjj|j}xtj|D]\} } } d| kr"| j dxR| D]J} tjj| | } |j| |} tj|jd| d}d|_|j|dq(WxL| D]D}|tkrq|tjj| |}|j||} |j||jd| q|WqW|jt j dt |dS)NTz %s-%s.ziprz8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort iwbaFz Deleting %szBacking up %s to %sr6) allowZip64z pip-egg-info/irzSaved %s)r6r7r8r9i)!rVrrxrrNr;rrrrrrrr rrrexitzipfileZipFile ZIP_DEFLATEDrrrr_clean_zip_nameZipInfo external_attrwritestrrwriterr)rmrcreate_archive archive_name archive_pathresponse dest_fileziprdirpathrrrrxzipdirrr?r?r@archivesX            "zInstallRequirement.archivecCsJ|j|tjjs"td||f|t|dd}|jtjjd}|S)Nz$name %r doesn't start with prefix %rr6r;)rtrNr;rOrrreplace)rmrxrr?r?r@rB5s z"InstallRequirement._clean_zip_namecs0|sd}jdk r(tfdd|DSdSdS)Nrc3s|]}jjd|iVqdS)rDN)r\evaluate)rCrD)rmr?r@rEDsz3InstallRequirement.match_markers..T)r)r\rP)rmextras_requestedr?)rmr@ match_markers=s   z InstallRequirement.match_markersc,s^|jr|j|||ddS|jrZtjj|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|_ |jr8dSfdd} t|H} x@| D](} tjj| }|jdrT| |}PqTWtj d|dSWdQRXg}t|P} xH| D]@} | j!}tjj"|r|tjj#7}|j$tjj%| ||qWWdQRXtjj|d}t|d} | j&dj|dWdQRXWdtjj|rPtj'|t(|XdS)N)r)rrTglobal_optionsinstall_optionsz --no-user-cfgz-recordzpip-zinstall-record.txtzRunning setup.py install for %sF)rrspinnerzRecord file %s not foundcs(dkstjj| r|St|SdS)N)rNr;isabsr)r;)rr?r@ prepend_rootzsz0InstallRequirement.install..prepend_rootz .egg-infoz;Could not find .egg-info directory in install record for %szinstalled-files.txtr7 ))rWinstall_editablerrr wheel_versionrVcheck_compatibilityrxr4rdrigetrlrrrrNr;rget_install_argsr1r/r%rrrrr[rrrrrrrOappendrelpathrFrr)rmrUrTrrr temp_locationrecord_filename install_argsmsgrVrXrline directoryr new_linesrinst_files_pathr?)rr@installIsv               " 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)rVr)rm 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-criz--recordz#--single-version-externally-managedz--rootz--prefixz --compilez --no-compilerz--install-headersincludesite)rrr_r0rrr[rjrrget_python_versionrNr;rrrx)rmrTrbrrrc py_ver_strr?r?r@r^s(        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) rVrNr;rrrrrrra)rmr?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-cdevelopz --no-depsF)rrT)rrrxrlrrr/r%rrr0rrrd)rmrUrTr prefix_paramr?r?r@rZs   z#InstallRequirement.install_editablec Cs|jdkrdSyFtt|j}d|_tjt||_|jrR|jrR|j|_d|_dSWnxtj k rjdStj k rtj|jj }|j rt |r||_qtrt|rtd|j|jfn||_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)rKr rr]rget_distributionr_rWr`DistributionNotFoundVersionConflictrxrgr"rr#rr r)rm no_marker existing_distr?r?r@rs2    z"InstallRequirement.check_if_existscCs|jo |jjS)N)rYr)rmr?r?r@rszInstallRequirement.is_wheelc Cs*t|j|j||j|j|||j|jd dS)N)userhomerrrjrl)r4rxrKrgrhrjrl)rmwheeldirrrr?r?r@r4 s z#InstallRequirement.move_wheel_filescCsX|jdjd}tjj|}tj||}tjjtjj|d}tj tjj|||dS)zAReturn a pkg_resources.Distribution built from self.egg_info_pathrr;r)r metadata) rrstriprNr;rr PathMetadatasplitextbasename Distribution)rmrbase_dirr{ dist_namer?r?r@get_dist+s   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)boolrir])rmr?r?r@has_hash_options6sz#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) rir]copyrYrZhash setdefault hash_namer_r-)rmtrust_internet good_hashesrYr?r?r@r@s  zInstallRequirement.hashes) NFNFTTNFNNF)NNFNNF)NFNNF)T)F)N)NN)T).r __module__ __qualname__rp classmethodr|rrrrpropertyrrrrrrxrrrrrrr8compile_requirements_section_rerrrr0r3r5rOrBrSrirkr^rprZrrr4rrrr?r?r?r@rHIsb ;  M      : 6    $0  W )   rHcCstjd|}|r|jd}|S)z2 Strip req postfix ( -dev, 0.2, etc ) z^(.*?)(?:-dev|-\d.*)$r6)r8rr:)rKr9r?r?r@_strip_postfixVs  rc 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)rqNz^(.+)(\[[^\]]+\])$r6r7zsetup.pyz;Directory %r is not installable. File 'setup.py' not found.zfile:rz%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)rx)rCrr?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)rrrqr8r9r:rNr;rrrrrrrtrr r=r3rrr.rrbackendsr) rvrwrqryr=r< url_no_extras package_nameversion_controlr error_messager?r?r@rsbs`            rs)N)d __future__rloggingrNr8rrrrRrr? distutilsrdistutils.utilr email.parserr pip._vendorrrZpip._vendor.packagingrpip._vendor.packaging.markersr "pip._vendor.packaging.requirementsr r pip._vendor.packaging.utilsr Zpip._vendor.packaging.versionr rrZpip._vendor.six.movesr pip.wheelr pip.compatrrr pip.downloadrrrrpip.exceptionsrr pip.locationsrrrr pip.utilsrrrr r!r"r#r$r%r&r'r(r)r*r+r,pip.utils.hashesr-Zpip.utils.deprecationr.pip.utils.loggingr/pip.utils.setuptools_buildr0 pip.utils.uir1pip.req.req_uninstallr2pip.vcsr3r4r5 getLoggerrr Specifier _operatorskeysrQrArGobjectrHrrsr?r?r?r@s`        H