U ja_ @sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddlm Z ddlmZmZmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(m)Z)ddl*m+Z+dd l,m-Z-dd l.m/Z/m0Z0m1Z1dd l2m3Z3m4Z4dd l5m6Z6m7Z7d ddddddddddddg Z8e9e:Z;e"dZe e?e?e?fZ@e eAe eeAeeAffZBddZCddZDddZEd dZFe'd!e(d"e)d#d$dd&d ZGd'd(ZHd)dZIdd+dZJd,d-ZKd.d/ZLd0dZMd1d2ZNd3d4ZOd5d6ZPd7dZQd8d9ZReAeSd:d;dZTejUfddZWd?dZXd@dZYdAdBZZdCdDZ[dEdFZ\dGdHZ]dIdJZ^d!e4d!d%d%dfdKdLZ_dMdNZ`dOdPZadQdRZbdSdTZcGdUdVdVe ZdejedWdXZfdYdZgdZd[Zhd\d]Zid^d_ZjddadbZkdcddZldedfZmdgdhZndidjZodkdlZpdmdnZqdodpZrdqdZsdrdsZtGdtduduZudvdwZvdxdyZwdzd{Zxd|d}ZydddZzddZ{ddZ|ddZ}dS)N)StringIO) filterfalsetee zip_longest) TracebackType)AnyAnyStrBinaryIOCallable ContainerContextManagerIterableIteratorListOptionalTextIOTupleTypeTypeVarcast Distribution)retrystop_after_delay wait_fixed) __version__) CommandError)get_major_minor_version site_packages user_site)WINDOWS stdlib_pkgs)running_under_virtualenvvirtualenv_no_globalrmtree display_path backup_dirasksplitext format_sizeis_installable_dirnormalize_pathrenamesget_progcaptured_stdout ensure_dirremove_auth_from_urlTcCs4tjtjtdd}tj|}dt|tS)Nz..zpip {} from {} (python {})) ospathjoindirname__file__abspathformatrr) pip_pkg_dirr:p/private/var/folders/k6/_7fsz4ts3b78x3b3xwrxjh_c8s8xv7/T/pip-unpacked-wheel-bug3gbve/pip/_internal/utils/misc.pyget_pip_versionJs r<cCsDt|dkr"|dt|d7}nt|dkr:|dd}td|S)ax Convert a tuple of ints representing a Python version to one of length three. :param py_version_info: a tuple of ints representing a Python version, or None to specify no version. The tuple can have any length. :return: a tuple of length three if `py_version_info` is non-None. Otherwise, return `py_version_info` unchanged (i.e. None). )rN VersionInfo)lenr)py_version_infor:r:r;normalize_version_infoVs   rAc CsPzt|Wn<tk rJ}z|jtjkr:|jtjkr:W5d}~XYnXdS)z os.path.makedirs without EEXIST.N)r2makedirsOSErrorerrnoEEXIST ENOTEMPTY)r3er:r:r;r/js c CsRz2tjtjd}|dkr*tjdWS|WSWntttfk rLYnXdS)Nr)z __main__.pyz-cz -m pippip) r2r3basenamesysargv executableAttributeError TypeError IndexError)progr:r:r;r-us Tr=g?)reraisestopwaitFcCstj||tddS)N) ignore_errorsonerror)shutilr$rmtree_errorhandler)dirrTr:r:r;r$scCsTzt|jtj@ }Wntk r.YdSX|rNt|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_IWRITErCchmod)funcr3exc_infohas_attr_readonlyr:r:r;rWsrWcCsFtjtj|}|ttjjrBd|ttd}|S)zTGives the display value for a given path, making it relative to cwd if possible..N)r2r3normcaser7 startswithgetcwdsepr?r3r:r:r;r%s.bakcCs6d}|}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)rXextn extensionr:r:r;r&s cCs2tjddD]}||kr|Sqt||S)NPIP_EXISTS_ACTION)r2environgetsplitr')messageoptionsactionr:r:r;ask_path_existss rucCstjdrtd|dS)z&Raise an error if no input is allowed. PIP_NO_INPUTz5No input was expected ($PIP_NO_INPUT set); question: N)r2rorp Exceptionrrr:r:r;_check_no_inputs rycCsFt|t|}|}||krYour response ({!r}) was not one of the expected responses: {}z, N)ryinputstriplowerprintr8r4)rrrsresponser:r:r;r's cCst|t|S)zAsk for input interactively.)ryrzrxr:r:r; ask_inputsrcCst|t|S)z!Ask for a password interactively.)rygetpassrxr:r:r; ask_passwordsrcCs2|}|dkrdS|dkr 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. )yyesttrueon1rg)rknoffalseoff0rzinvalid truth value N)r| ValueError)valr:r:r; strtobools rcCs\|dkrd|ddS|dkr4dt|dS|dkrJd|dSdt|SdS) Ni@Bz {:.1f} MBg@@ii'z{} kBz {:.1f} kBz{} bytes)r8int)bytesr:r:r;r)scs@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|qSr:)tuplemapri.0rowr:r:r; sztabulate..cSsg|]}ttt|qSr:)maxrr?)rcolr:r:r;r s fillvaluerncs$g|]}dttj|qS) )r4rriljustrstriprsizesr:r;r s)r)rowstabler:rr;tabulates r)r3returncCsHtj|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)r2r3isdirisfiler4rer:r:r;r*s ccs||}|sq|VqdS)z7Yield pieces of data from a file-like object until EOF.N)read)filesizechunkr:r:r; read_chunks!s rcCs6tj|}|rtj|}n tj|}tj|S)zN Convert a path to its canonical, case-normalized, absolute version. )r2r3 expanduserrealpathr7ra)r3resolve_symlinksr:r:r;r++s   cCs@t|\}}|dr8|dd|}|dd}||fS)z,Like os.path.splitext, but take off .tar tooz.tarN) posixpathr(r|endswith)r3baserjr:r:r;r(9s  cCsztj|\}}|r.|r.tj|s.t|t||tj|\}}|rv|rvzt|Wntk rtYnXdS)z7Like os.renames(), but handles renaming across devices.N) r2r3rqrhrBrVmove removedirsrC)oldnewheadtailr:r:r;r,Cs  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"rbr+rJprefixrer:r:r;is_localUs rcCs 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_locationdistr:r:r; dist_is_localds rcCst|ttS)zF Return True if given Distribution is installed in user site. )rrbr+rrr:r:r;dist_in_usersitepsrcCst|ttS)z[ Return True if given Distribution is installed in sysconfig.get_python_lib(). )rrbr+rrr:r:r;dist_in_site_packagesxsrcCs6tjD]*}tj||jd}tj|rdSqdS)zC Return True if given Distribution is an editable install. .egg-linkTF)rJr3r2r4 project_namer)r path_itemegg_linkr:r:r;dist_is_editables   rc sZddlm}m}ddlm|dkr,|}n||}|j|||||d} fdd| DS)zReturn a list of installed Distribution objects. Left for compatibility until direct pkg_resources uses are refactored out. r)get_default_environmentget_environmentrN) local_onlyskipinclude_editableseditables_only user_onlycsg|]}t|jqSr:)r_dist)rr_Distr:r;rsz/get_installed_distributions..)pip._internal.metadatarr$pip._internal.metadata.pkg_resourcesrZiter_installed_distributions) rrrrrpathsrrenvdistsr:rr;get_installed_distributionss  rcCs<ddlm}ddlm}||}|dkr0dSt||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)rrN)rrrrget_distributionrr)req_namerrrr:r:r;rs   rcCsxg}tr*|ttsBtrB|tntr8|t|t|D],}tj||jd}tj |rF|SqFdS)a Return the path for the .egg-link file if it exists, otherwise, None. There's 3 scenarios: 1) not in a virtualenv try to find in site.USER_SITE, then site_packages 2) in a no-global virtualenv try to find in site_packages 3) in a yes-global virtualenv try to find in site_packages, then site.USER_SITE (don't look in global location) For #1 and #3, there could be odd cases, where there's an egg-link in 2 locations. This method will just return the first one found. rN) r"appendrr#rr2r3r4rr)rsitessiteegglinkr:r:r; egg_link_paths       rcCst|}|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). )rr+location)rrr:r:r;rs rcGstj|f|dSN)loggerinfo)msgargsr:r:r; write_outputsrc@s(eZdZdZeddZeddZdS) StreamWrapperNcCs ||_|Sr) orig_stream)clsrr:r:r; from_streamszStreamWrapper.from_streamcCs|jjSr)rencodingselfr:r:r;rszStreamWrapper.encoding)__name__ __module__ __qualname__r classmethodrpropertyrr:r:r:r;rs  rc cs@tt|}tt|t|ztt|VW5tt||XdS)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)getattrrJsetattrrr) stream_name orig_stdoutr:r:r;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. stdoutrr:r:r:r;r.s cCstdS)z See captured_stdout(). stderrrr:r:r:r;captured_stderr#srcOs@tt|tt|f|}dd|D}||d<tdd|S)NcSsi|]\}}||qSr:r:)rkeyvaluer:r:r; /szenum..reverse_mappingEnumr:)dictzipranger?itemstype) sequentialnamedenumsreverser:r:r;enum,srcCs.|dkr |Sd|kr d|d}|d|S)z. Build a netloc from a host-port pair N:[]r:)hostportr:r:r; build_netloc4s  r httpscCs8|ddkr*d|kr*d|kr*d|d}|d|S)z) Build a full URL from a netloc. r@rr z://)count)netlocschemer:r:r;build_url_from_netlocAs rcCs t|}tj|}|j|jfS)z2 Return the host-port pair from a netloc. )rurllibparseurlparsehostnamer )rurlparsedr:r:r; parse_netlocLs rcCstd|kr|dfS|dd\}}d}d|kr>|dd\}}n |d}}tj|}|dk rhtj|}|||ffS)zp Parse out and remove the auth information from a netloc. Returns: (netloc, (username, password)). r)NNrgNr)rsplitrqrrunquote)rauthpwuserr:r:r;split_auth_from_netlocVs   r cCsNt|\}\}}|dkr|S|dkr.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****rnz:****z{user}{password}@{netloc})rpasswordr)r rrquoter8)rrr"r:r:r; redact_netlocts  r$cCsJtj|}||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)rtransform_netlocpurl netloc_tuple url_piecessurlr:r:r;_transform_urls   r/cCst|Sr)r rr:r:r; _get_netlocsr1cCs t|fSr)r$r0r:r:r;_redact_netlocsr2cCst|t\}\}}|||fS)z Parse a url into separate netloc, auth, and url with no auth. Returns: (url_without_auth, netloc, (username, password)) r/r1)rurl_without_authrrr:r:r;split_auth_netloc_from_urlsr5cCst|tdS)z7Return a copy of url with 'username:password@' removed.rr3rr:r:r;r0scCst|tdS)z.Replace the password in a given url with ****.r)r/r2r6r:r:r;redact_auth_from_urlsr7c@s,eZdZddZddZddZddZd S) HiddenTextcCs||_||_dSr)secretredacted)rr9r:r:r:r;__init__szHiddenText.__init__cCsdt|S)Nz)r8rirr:r:r;__repr__szHiddenText.__repr__cCs|jSrr:rr:r:r;__str__szHiddenText.__str__cCs t|t|krdS|j|jkS)NF)rr9)rotherr:r:r;__eq__szHiddenText.__eq__N)rrrr;r<r>r@r:r:r:r;r8s r8cCs t|ddS)Nr!r=)r8)rr:r:r; hide_valuesrAcCst|}t||dS)Nr=)r7r8)rr:r:r:r;hide_urlsrBcCszddtjddjtjddg}|oBtoBtjtjd|k}|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-mrHrgz3To modify pip, please run the following command: {}r) r8rJ version_infor r2r3rIrKrLrr4) modifying_pip pip_namesshould_show_use_python_msg new_commandr:r:r;(protect_pip_from_modification_on_windowssrHcCstjdk otjS)zIs this console interactive?N)rJstdinisattyr:r:r:r;is_console_interactivesrKc CsRt}d}t|d.}t||dD]}|t|7}||q$W5QRX||fS)z5Return (hash, length) for path using hashlib.sha256()rrb)r)hashlibsha256openrr?update)r3 blocksizehlengthrblockr:r:r; hash_file s  rVcCs(z ddl}Wntk r"YdSXdS)z8 Return whether the wheel package is installed. rNFT)wheel ImportError)rWr:r:r;is_wheel_installeds  rYcCst|}t||S)zb Return paired elements. For example: s -> (s0, s1), (s2, s3), (s4, s5), ... )iterr)iterabler:r:r;pairwise$sr\cCs 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)predr[t1t2r:r:r; partition0s ra)F)rf)T)r )rL)~ contextlibrDrrNiologgingr2rrVrYrJ urllib.parserr itertoolsrrrtypesrtypingrrr r r r r rrrrrrrrZpip._vendor.pkg_resourcesrZpip._vendor.tenacityrrrrHrpip._internal.exceptionsrpip._internal.locationsrrrpip._internal.utils.compatr r!pip._internal.utils.virtualenvr"r#__all__ getLoggerrrr1 BaseExceptionZExcInforr>rir%r<rAr/r-r$rWr%r&ruryr'rrrr)rboolr*DEFAULT_BUFFER_SIZErr+r(r,rrrrrrrrrrrcontextmanagerrr.rrr rrr r$r/r1r2r5r0r7r8rArBrHrKrVrYr\rar:r:r:r;s  D                $