a [f*Q@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddlm Z ddlmZmZmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!ddl"m#Z#ddl$m%Z%m&Z&m'Z'ddl(m)Z)dd l*m+Z+dd l,m-Z-m.Z.m/Z/dd l,m0Z0dd l1m2Z2dd l3m4Z4ddl5m6Z6gdZ7e8e9Z:e dZ;eee<ee>e>fZ?ee@eee@ee@ffZAe@dddZBee>dfee>e>e>fdddZCe@ddddZDe@dddZEe%de&de'dd de@eFdd"d#d$ZGedefe@e=dd%d&d'ZHe@e@dd(d)ZIde@e@e@d+d,d-ZJe@ee@e@d.d/d0ZKe@dd1d2d3ZLe@ee@e@d.d4d5ZMe@e@d1d6d7ZNe@e@d1d8d9ZOe@e>d:d;d<ZPeQe@d=d>d?ZReeeeee@ee>fd@dAdBZSe@eFddCdDZTejUfee>eeVdEdFdGZWde@eFe@dHdIdJZXe@ee@e@fddKdLZYe@e@ddMdNdOZZe@eFddPdQZ[e#eFdRdSdTZ\e#eFdRdUdVZ]e#eFdRdWdXZ^dYdZZ_e@ee#d[d\d]Z`e#e@dRd^d_Zaeedd`dadbZbGdcdddde Zcejde@eecdedfdgZeeecddhdiZfeecddjdkZgeeeedldmdnZhe@ee>e@dodpdqZide@e@e@dsdtduZje@ee@ee>fdvdwdxZke@eAdvdydzZle@e@dvd{d|Zme@ee@geedffee@eAfd}d~dZne@eAdvddZoe@ee@dvddZpe@ee@e@ee@e@ffdddZqe@e@dddZre@e@dddZsGdddZte@etdddZue@etdddZveFddddZweFdddZxde@e>eee>fdddZyeFdddZzeeeeeefdddZ{ee;geFfee;eee;ee;fdddZ|dS)N)StringIO) filterfalsetee zip_longest) TracebackType) AnyBinaryIOCallableContextManagerIterableIteratorListOptionalTextIOTupleTypeTypeVarcast Distribution)retrystop_after_delay wait_fixed) __version__) CommandError)get_major_minor_version site_packages user_site) get_scheme)WINDOWS)egg_link_path_from_location)running_under_virtualenv) rmtree display_path backup_dirasksplitext format_sizeis_installable_dirnormalize_pathrenamesget_progcaptured_stdout ensure_dirremove_auth_from_urlTreturncCs4tjtjtdd}tj|}dt|tS)Nz..zpip {} from {} (python {})) ospathjoindirname__file__abspathformatrr)Z pip_pkg_dirr9tyL}z&|jtjkr8|jtjkr8WYd}~n d}~00dS)z os.path.makedirs without EEXIST.N)r2makedirsOSErrorerrnoZEEXISTZ ENOTEMPTY)r3er9r9r:r-es r-c CsPz2tjtjd}|dvr*tjdWS|WSWntttfyJYn0dS)Nr)z __main__.pyz-cz -m pippip) r2r3basenamesysargv executableAttributeError TypeError IndexError)progr9r9r:r+os r+Tr=g?)ZreraisestopwaitF)dir ignore_errorsr1cCstj||tddS)N)rQonerror)shutilr"rmtree_errorhandler)rPrQr9r9r:r"}sr")funcr3exc_infor1cCsRzt|jtj@ }Wnty,YdS0|rLt|tj||dSdS)zOn Windows, the files in .svn are read-only, so when rmtree() tries to remove them, an exception is thrown. We catch that here, remove the read-only attribute, and hopefully continue without problems.N)r2statst_modeS_IWRITErBchmod)rUr3rVZhas_attr_readonlyr9r9r:rTs rTcCsFtjtj|}|ttjjrBd|ttd}|S)zTGives the display value for a given path, making it relative to cwd if possible..N)r2r3normcaser7 startswithgetcwdsepr?r3r9r9r:r#sr#.bak)rPextr1cCs6d}|}tj||r.|d7}|t|}q||S)z\Figure out the name of a directory to back up the given dir to (adding .bak, .bak2, etc))r2r3existsstr)rPrbn extensionr9r9r:r$s r$)messageoptionsr1cCs2tjddD]}||vr|Sqt||S)NZPIP_EXISTS_ACTION)r2environgetsplitr%)rhriactionr9r9r:ask_path_existss ro)rhr1cCstjdrtd|dS)z&Raise an error if no input is allowed.Z PIP_NO_INPUTz5No input was expected ($PIP_NO_INPUT set); question: N)r2rkrl Exceptionrhr9r9r:_check_no_inputs rrcCsFt|t|}|}||vrYour response ({!r}) was not one of the expected responses: {}z, N)rrinputstriplowerprintr8r4)rhriZresponser9r9r:r%s  r%cCst|t|S)zAsk for input interactively.)rrrsrqr9r9r: ask_inputsrwcCst|t|S)z!Ask for a password interactively.)rrgetpassrqr9r9r: ask_passwordsry)valr1cCs2|}|dvrdS|dvr dStd|dS)zConvert a string representation of truth to true (1) or false (0). True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if 'val' is anything else. )yZyesttrueZon1rc)rfnofZfalseZoff0rzinvalid truth value N)ru ValueError)rzr9r9r: strtobools r)bytesr1cCs\|dkrd|ddS|dkr4dt|dS|dkrJd|dSdt|SdS) Ni@Bz {:.1f} MBg@@ii'z{} kBz {:.1f} kBz{} bytes)r8int)rr9r9r:r'sr')rowsr1cs@dd|D}ddt|ddiDfdd|D}|fS)zReturn a list of formatted rows and a list of column sizes. For example:: >>> tabulate([['foobar', 2000], [0xdeadbeef]]) (['foobar 2000', '3735928559'], [10, 4]) cSsg|]}ttt|qSr9)tuplemapre.0rowr9r9r: ztabulate..cSsg|]}ttt|qSr9)maxrr?)rcolr9r9r:rr fillvaluerjcs$g|]}dttj|qS) )r4rreljustrstriprZsizesr9r:rr)r)rtabler9rr:tabulatesrcCsHtj|sdStjtj|dr*dStjtj|drDdSdS)atIs path is a directory containing pyproject.toml or setup.py? If pyproject.toml exists, this is a PEP 517 project. Otherwise we look for a legacy setuptools layout by identifying setup.py. We don't check for the setup.cfg because using it without setup.py is only available for PEP 517 projects, which are already covered by the pyproject.toml check. Fzpyproject.tomlTzsetup.py)r2r3isdirisfiler4r`r9r9r:r(s r()filesizer1ccs||}|sq|VqdS)z7Yield pieces of data from a file-like object until EOF.N)read)rrchunkr9r9r: read_chunkss r)r3resolve_symlinksr1cCs6tj|}|rtj|}n tj|}tj|S)zN Convert a path to its canonical, case-normalized, absolute version. )r2r3 expanduserrealpathr7r\)r3rr9r9r:r)s   r)cCs@t|\}}|dr8|dd|}|dd}||fS)z,Like os.path.splitext, but take off .tar tooz.tarN) posixpathr&ruendswith)r3baserbr9r9r:r&$s  r&)oldnewr1cCsxtj|\}}|r.|r.tj|s.t|t||tj|\}}|rt|rtzt|WntyrYn0dS)z7Like os.renames(), but handles renaming across devices.N) r2r3rmrdrArSmove removedirsrB)rrheadtailr9r9r:r*-s   r*cCsts dS|ttjS)z Return True if path is within sys.prefix, if we're running in a virtualenv. If we're not in a virtualenv, all paths are considered "local." Caution: this function assumes the head of path has been normalized with normalize_path. T)r!r]r)rGprefixr`r9r9r:is_local>s r)distr1cCs tt|S)z Return True if given Distribution object is installed locally (i.e. within current virtualenv). Always True if we're not in a virtualenv. )r dist_locationrr9r9r: dist_is_localLsrcCst|ttS)zF Return True if given Distribution is installed in user site. )rr]r)rrr9r9r:dist_in_usersiteWsrcCst|ttS)z[ Return True if given Distribution is installed in sysconfig.get_python_lib(). )rr]r)rrr9r9r:dist_in_site_packages^srcCs*tt|}|ttdjddS)zf Return True if given Distribution is installed in path matching distutils_scheme layout. rjZpythonr)r)rr]rZpurelibrm)rZ norm_pathr9r9r:dist_in_install_pathfs r)req_namer1cCs<ddlm}ddlm}||}|dur0dSt||jS)a%Given a requirement name, return the installed Distribution object. This searches from *all* distributions available in the environment, to match the behavior of ``pkg_resources.get_distribution()``. Left for compatibility until direct pkg_resources uses are refactored out. r)get_default_environmentrN)Zpip._internal.metadatarZ$pip._internal.metadata.pkg_resourcesrget_distributionrZ_dist)rrZ_Distrr9r9r:rps    rcCs t|j}|rt|St|jS)aO Get the site-packages location of this distribution. Generally this is dist.location, except in the case of develop-installed packages, where dist.location is the source code location, and we want to know where the egg-link file is. The returned location is normalized (in particular, with symlinks removed). )r Z project_namer)location)rZegg_linkr9r9r:rs r)msgargsr1cGstj|g|RdSN)loggerinfo)rrr9r9r: write_outputsrc@s:eZdZUdZeed<eeddddZeddZ dS) StreamWrapperN orig_stream)rr1cCs ||_|Sr)r)clsrr9r9r: from_streamszStreamWrapper.from_streamcCs|jjSr)rencodingselfr9r9r:rszStreamWrapper.encoding) __name__ __module__ __qualname__rr__annotations__ classmethodrpropertyrr9r9r9r:rs  r) stream_namer1c csLtt|}tt|t|ztt|VWtt||ntt||0dS)zReturn a context manager used by captured_stdout/stdin/stderr that temporarily replaces the sys stream *stream_name* with a StringIO. Taken from Lib/support/__init__.py in the CPython repo. N)getattrrGsetattrrr)rZ orig_stdoutr9r9r:captured_outputs  rcCstdS)zCapture the output of sys.stdout: with captured_stdout() as stdout: print('hello') self.assertEqual(stdout.getvalue(), 'hello ') Taken from Lib/support/__init__.py in the CPython repo. stdoutrr9r9r9r:r,s r,cCstdS)z See captured_stdout(). stderrrr9r9r9r:captured_stderrsr) sequentialnamedr1cOsDtt|tt|fi|}dd|D}||d<tdd|S)NcSsi|]\}}||qSr9r9)rkeyvaluer9r9r: rzenum..Zreverse_mappingEnumr9)dictzipranger?itemstype)rrZenumsreverser9r9r:enumsr)hostportr1cCs.|dur |Sd|vr d|d}|d|S)z. Build a netloc from a host-port pair N:[]r9)rrr9r9r: build_netlocs  rhttps)netlocschemer1cCs8|ddkr*d|vr*d|vr*d|d}|d|S)z) Build a full URL from a netloc. r@rrz://)count)rrr9r9r:build_url_from_netlocs r)rr1cCs t|}tj|}|j|jfS)z2 Return the host-port pair from a netloc. )rurllibparseurlparsehostnamer)rurlparsedr9r9r: parse_netlocs rcCstd|vr|dfS|dd\}}d}d|vr>|dd\}}n |d}}tj|}|durhtj|}|||ffS)zp Parse out and remove the auth information from a netloc. Returns: (netloc, (username, password)). r)NNrcNr)rsplitrmrrunquote)rauthZpwuserr9r9r:split_auth_from_netlocs   rcCsNt|\}\}}|dur|S|dur.d}d}ntj|}d}dj|||dS)z Replace the sensitive data in a netloc with "****", if it exists. For example: - "user:pass@example.com" returns "user:****@example.com" - "accesstoken@example.com" returns "****@example.com" N****rjz:****z{user}{password}@{netloc})rpasswordr)rrrquoter8)rrrr9r9r: redact_netloc s r)rtransform_netlocr1cCsJtj|}||j}|j|d|j|j|jf}tj|}|t d|fS)aRTransform and replace netloc in a url. transform_netloc is a function taking the netloc and returning a tuple. The first element of this tuple is the new netloc. The entire tuple is returned. Returns a tuple containing the transformed url as item 0 and the original tuple returned by transform_netloc as item 1. r NetlocTuple) rrurlsplitrrr3queryfragment urlunsplitr)rrZpurlZ netloc_tupleZ url_piecesZsurlr9r9r:_transform_urls   rcCst|Sr)rrr9r9r: _get_netloc3srcCs t|fSr)rrr9r9r:_redact_netloc7sr)rr1cCst|t\}\}}|||fS)z Parse a url into separate netloc, auth, and url with no auth. Returns: (url_without_auth, netloc, (username, password)) rr)rZurl_without_authrrr9r9r:split_auth_netloc_from_url;srcCst|tdS)z7Return a copy of url with 'username:password@' removed.rrrr9r9r:r.Esr.cCst|tdS)z.Replace the password in a given url with ****.r)rrr r9r9r:redact_auth_from_urlLsr c@sJeZdZeeddddZedddZeddd Zeed d d Z dS) HiddenTextN)secretredactedr1cCs||_||_dSr)r r )rr r r9r9r:__init__RszHiddenText.__init__r0cCsdt|S)Nz)r8rerr9r9r:__repr__VszHiddenText.__repr__cCs|jSrr rr9r9r:__str__YszHiddenText.__str__)otherr1cCs t|t|krdS|j|jkS)NF)rr )rrr9r9r:__eq__]szHiddenText.__eq__) rrrrerrrrboolrr9r9r9r:r Qsr )rr1cCs t|ddS)Nrr)r )rr9r9r: hide_valuefsrcCst|}t||dS)Nr)r r )rr r9r9r:hide_urljsr) modifying_pipr1cCszddtjddjtjddg}|oBtoBtjtjd|v}|rvtjddgtjd d}t d d |dS) zProtection of pip.exe from modification on Windows On Windows, any operation modifying pip should be run as: python -m pip ... zpip.exez pip{}.exerz pip{}.{}.exeNrz-mrErcz3To modify pip, please run the following command: {}r) r8rG version_inforr2r3rFrHrIrr4)rZ pip_namesZshould_show_use_python_msgZ new_commandr9r9r:(protect_pip_from_modification_on_windowsosrcCstjduotjS)zIs this console interactive?N)rGstdinisattyr9r9r9r:is_console_interactivesr)r3 blocksizer1cCsft}d}t|d8}t||dD]}|t|7}||q$Wdn1sT0Y||fS)z5Return (hash, length) for path using hashlib.sha256()rrb)rN)hashlibZsha256openrr?update)r3rhlengthrblockr9r9r: hash_files  *r&cCs&z ddl}Wnty YdS0dS)z8 Return whether the wheel package is installed. rNFT)wheel ImportError)r'r9r9r:is_wheel_installeds   r))iterabler1cCst|}t||S)zb Return paired elements. For example: s -> (s0, s1), (s2, s3), (s4, s5), ... )iterr)r*r9r9r:pairwisesr,)predr*r1cCs t|\}}t||t||fS)z Use a predicate to partition entries into false entries and true entries, like partition(is_odd, range(10)) --> 0 2 4 6 8 and 1 3 5 7 9 )rrfilter)r-r*t1t2r9r9r: partitions r1)F)ra)T)r)r)} contextlibrCrxr ioZloggingr2rrSrWrG urllib.parserr itertoolsrrrtypesrtypingrrr r r r r rrrrrrZpip._vendor.pkg_resourcesrZpip._vendor.tenacityrrrrErZpip._internal.exceptionsrZpip._internal.locationsrrrrZpip._internal.utils.compatrZpip._internal.utils.egg_linkr Zpip._internal.utils.virtualenvr!__all__Z getLoggerrrr/ BaseExceptionZExcInforr>rerr;r@r-r+rr"rTr#r$rorrr%rwryrfloatr'rr(DEFAULT_BUFFER_SIZErrr)r&r*rrrrrrrrrcontextmanagerrr,rrrrrrrrrrrr.r r rrrrr&r)r,r1r9r9r9r:s  <         "    (          "