3 (\~@sXddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlmZddlmZddlmZddlmZddlmZmZddlmZdd lmZ dd l!m"Z"m#Z#dd l$m%Z%m&Z&m'Z'm(Z(m)Z)dd l*m+Z+m,Z,m-Z-m.Z.dd l/m0Z0er0ddlm1Z2n ddlm2Z2e0rddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>ddl?m@Z@ddlAmBZBddlCmDZDddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,gZEejFeGZHejFd-ZId.ZJd/ZKdZLdZMd7eKfZNdZOeNeLeOeMZPeNeOZQyddlRZReQeL7ZQWn eSk rLeHjTd;YnXyddlUZUeQeM7ZQWn eSk reHjTd<YnXd=d'ZVd>d!ZWed?d@dAddCdZXdDdEZYdFdZZddHdZ[dIdJZ\dKdZ]dLdZ^dMdZ_dNdZ`dOdZaejbfdPdQZcdRdZddSdZeddUdZfdVdZgdWd ZhdXdYZidZd[Zjd\d]Zkd^d_Zld`daZmdTe.dTdBdBfdbdcZndddeZodfdgZpdhdiZqddjd"Zrdkd#Zsdld$ZtdmdnZuddpd%ZvdqdrZwGdsdtdtexZyGdudvdve2Zzej{dwdxZ|dyd&Z}dzd{Z~Gd|d}d}exZdd~d+ZddZddZddZddZddZddZdd,ZddZddZdS))absolute_importN)deque) pkg_resources)retry)PY2)input shlex_quote)parse)unquote) CommandErrorInstallationError)running_under_virtualenv site_packages user_sitevirtualenv_no_globalwrite_delete_marker_file)WINDOWSconsole_to_str expanduser stdlib_pkgs)MYPY_CHECK_RUNNING)BytesIO)StringIO) OptionalTupleIterableListMatchUnionAnyMappingTextAnyStr Container) Distribution)Link)SpinnerInterfacermtree display_path backup_dirasksplitext format_sizeis_installable_dir is_svn_page file_contentssplit_leading_dirhas_leading_dirnormalize_pathrenamesget_prog unzip_file untar_file unpack_filecall_subprocesscaptured_stdout ensure_dirARCHIVE_EXTENSIONSSUPPORTED_EXTENSIONSWHEEL_EXTENSIONget_installed_versionremove_auth_from_urlzpip.subprocessorz(----------------------------------------z.whl.tar.bz2.tbz.tar.xz.txz.tlz.tar.lz .tar.lzmaz.zip.tar.gz.tgz.tarzbz2 module is not availablezlzma module is not availablecCsDytj|Wn0tk r>}z|jtjkr.WYdd}~XnXdS)z os.path.makedirs without EEXIST.N)osmakedirsOSErrorerrnoEEXIST)patherQk/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/utils/misc.pyr:_s  c CsLy,tjjtjd}|dkr&dtjS|SWntttfk rFYnXdS)Nr __main__.py-cz %s -m pippip)rSrT) rJrObasenamesysargv executableAttributeError TypeError IndexError)progrQrQrRr4is i i)stop_max_delay wait_fixedFcCstj||tddS)N) ignore_errorsonerror)shutilr'rmtree_errorhandler)dirr`rQrQrRr'wscCs2tj|jtj@r,tj|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)rJstatst_modeS_IREADchmodS_IWRITE)funcrOexc_inforQrQrRrc~s rccCsttjjtjj|}tjddkrB|jtjd}|jtj d}|j tj tjj rpd|t tj d}|S)zTGives the display value for a given path, making it relative to cwd if possible.rreplace.N)rJrOnormcaseabspathrW version_infodecodegetfilesystemencodingencodegetdefaultencoding startswithgetcwdseplen)rOrQrQrRr(s.bakcCs:d}|}x(tjj||r0|d7}|t|}q W||S)z\Figure out the name of a directory to back up the given dir to (adding .bak, .bak2, etc))rJrOexistsstr)rdextn extensionrQrQrRr)s cCs2x&tjjddjD]}||kr|SqWt||S)NPIP_EXISTS_ACTION)rJenvirongetsplitr*)messageoptionsactionrQrQrRask_path_existssrcCsZxTtjjdrtd|t|}|jj}||krNtd|dj|fq|SqWdS)z@Ask the message interactively, with the given possible responses PIP_NO_INPUTz7No input was expected ($PIP_NO_INPUT set); question: %sz[^<]*Revision \d+:z#Powered by (?:]*?>)?Subversion)researchI)htmlrQrQrRr.s c Cs$t|d}|jjdSQRXdS)Nrbzutf-8)openreadrr)filenamefprQrQrRr/s ccs x|j|}|sP|VqWdS)z7Yield pieces of data from a file-like object until EOF.N)r)filesizechunkrQrQrR read_chunkss  rcCsh|jdjd}d|krHd|kr4|jd|jdks.local_testcSsdS)NTrQ)rrQrQrR editable_testsz2get_installed_distributions..editable_testcSs t| S)N)r)rrQrQrRrscSst|S)N)r)rrQrQrReditables_only_testsz8get_installed_distributions..editables_only_testcSsdS)NTrQ)rrQrQrRrscSsdS)NTrQ)rrQrQrR user_testsz.get_installed_distributions..user_testcs:g|]2}|r|jkr|r|r|r|qSrQ)key).0r)rrrskiprrQrR s  z/get_installed_distributions..)rrr working_set) local_onlyrinclude_editableseditables_only user_onlyrQ)rrrrrrRget_installed_distributionsts  rcCsg}tr6tr|jtqN|jttrN|jtntrD|jt|jtx0|D](}tjj||jd}tjj |rT|SqTWdS)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. z .egg-linkN) r rappendrrrJrOrrr)rsitessiteegglinkrQrQrR egg_link_paths       rcCst|}|r|S|jS)z 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. )rlocation)rrrQrQrRrs rcCstjd}tj||S)zBGet the current umask which involves having to set it temporarily.r)rJumask)maskrQrQrR current_umasks  rc Cs&t|t|d}ztj|dd}t|jo2|}x|jD]}|j}|}|r\t|d}t j j ||}t j j |} |j ds|j drt|q>t| |j|} z&t|d} tj| | WdQRXWd| j|jd ?} | otj| o| d @rt j|d td BXq>WWd|jXdS) a Unzip the file (with path `filename`) to the destination `location`. All files are written based on system defaults and umask (i.e. permissions are not preserved), except that regular file members with any execute permissions (user, group, or world) have "chmod +x" applied after being written. Note that for windows, any execute changes using os.chmod are no-ops per the python docs. rT) allowZip64r{rrwbNIi)r:rzipfileZipFiler1namelistinfolistrr0rJrOrdirnamerrb copyfileobjclose external_attrreS_ISREGrhr) rrflattenzipfpzipleadinginfonamefnrdrdestfpmoderQrQrRr5s0         c Cst||jjds$|jjdr*d}nL|jjtr>d}n8|jjtrRd}n$|jjdrfd}ntjd|d }tj||}znt d d |j D}xP|j D]B}|j }|rt |d }t jj||}|jrt|q|jr:y|j||Wn8tk r6}ztjd ||j |wWYdd}~XnXqy|j|} Wn<ttfk r}ztjd ||j |wWYdd}~XnXtt jj|t|d} tj| | WdQRX| j|j|||jd@rt j|dtdBqWWd|jXdS)a Untar the file (with path `filename`) to the destination `location`. All files are written based on system defaults and umask (i.e. permissions are not preserved), except that regular file members with any execute permissions (user, group, or world) have "chmod +x" applied after being written. Note that for windows, any execute changes using os.chmod are no-ops per the python docs. z.gzz.tgzzr:gzzr:bz2zr:xzz.tarrz-Cannot determine compression type for file %szr:*cSsg|] }|jqSrQ)r)rmemberrQrQrRr5szuntar_file..r{z/In the tar file %s the member %s is invalid: %sNrri)r:rrBZ2_EXTENSIONS XZ_EXTENSIONSloggerwarningtarfilerr1 getmembersrr0rJrOrrissym_extract_memberr extractfileKeyErrorrZrrbrrutimerrhr) rrrtarrrrrOexcrrrQrQrRr6s\          cCstjj|}|dks,|jjts,tj|rDt|||jd dn|dkslt j |sl|jjt t t rxt||nX|r|jdrtt|rddlm}|d|jj|ntjd |||td |dS) Nzapplication/zipz.whl)rzapplication/x-gzipz text/htmlr) Subversionzsvn+zZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz%Cannot determine archive format of %s)rJrOrrrZIP_EXTENSIONSr is_zipfiler5r is_tarfileTAR_EXTENSIONSrrr6rvr.r/Zpip._internal.vcs.subversionrurlunpackrcriticalr )rr content_typelinkrrQrQrRr7fs,       cCsdjdd|DS)z/ Format command arguments for display.  css|]}t|VqdS)N)r)rargrQrQrR sz&format_command_args..)r)argsrQrQrRformat_command_argssrraisec Cs.|dkr g}|dkrg}|r*tj} tj} n tj} tj} tj| k} | oN|dk } |dkr`t|}| d|tj j } |r| j |x|D]}| j |dqWy*t j|t jt jt j|| d}|jjWn2tk r}ztjd||WYdd}~XnXg}xHt|jj}|sP|j}|j|d| || r|jqWz |jWd|jrh|jjX|joz|j|k}| r|r|jdn |jd|r$|dkr| stjd |tjd j|t t!d ||j|fn:|d krtj"d ||j|n|dkrnt#dt$|d j|S)a Args: show_stdout: if true, use INFO to log the subprocess's stderr and stdout streams. Otherwise, use DEBUG. Defaults to False. extra_ok_returncodes: an iterable of integer return codes that are acceptable, in addition to 0. Defaults to None, which means []. unset_environ: an iterable of environment variable names to unset prior to calling subprocess.Popen(). NzRunning command %s)stderrstdinstdoutcwdenvz#Error %s while executing command %s errordonerz Complete output from command %s:rz,Command "%s" failed with error code %s in %swarnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=%s)%subprocess_loggerr std_loggingINFOdebugDEBUGgetEffectiveLevelrrJrcopyupdatepop subprocessPopenSTDOUTPIPErrrrrrreadlinerstriprspinwait returncodefinishrr LOG_DIVIDERr r ValueErrorrepr)cmd show_stdoutr on_returncodeZextra_ok_returncodes command_desc extra_environZ unset_environspinnerZlog_subprocessZ used_levelZshowing_subprocessZ use_spinnerrrprocr all_outputlineZproc_had_errorrQrQrRr8s               cCstj|t|dS)N)rJrKr) build_dirrQrQrR_make_build_dirs r:c@s(eZdZdZddZddZddZdS) FakeFilezQWrap a list of lines in an object with readline() to make ConfigParser happy.cCsdd|D|_dS)Ncss|] }|VqdS)NrQ)rlrQrQrRr sz$FakeFile.__init__..)_gen)selflinesrQrQrR__init__szFakeFile.__init__cCsDy*y t|jStk r&|jjSXWntk r>dSXdS)Nr)nextr= NameError StopIteration)r>rQrQrRr'!s zFakeFile.readlinecCs|jS)N)r=)r>rQrQrR__iter__*szFakeFile.__iter__N)__name__ __module__ __qualname____doc__r@r'rDrQrQrQrRr;s r;c@s$eZdZeddZeddZdS) StreamWrappercCs ||_|S)N) orig_stream)clsrJrQrQrR from_stream0szStreamWrapper.from_streamcCs|jjS)N)rJencoding)r>rQrQrRrM6szStreamWrapper.encodingN)rErFrG classmethodrLpropertyrMrQrQrQrRrI.s rIc cs@tt|}tt|tj|ztt|VWdtt||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)getattrrWsetattrrIrL) stream_name orig_stdoutrQrQrRcaptured_output;s  rTcCstdS)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. r)rTrQrQrQrRr9Js cCstdS)z See captured_stdout(). r)rTrQrQrQrRcaptured_stderrVsrUc@s eZdZdZddZddZdS)cached_propertyzA property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property. Source: https://github.com/bottlepy/bottle/blob/0.11.5/bottle.py#L175 cCst|d|_||_dS)NrH)rPrHrj)r>rjrQrQrRr@es zcached_property.__init__cCs(|dkr |S|j|}|j|jj<|S)N)rj__dict__rE)r>objrKvaluerQrQrR__get__iszcached_property.__get__N)rErFrGrHr@rZrQrQrQrRrV]srVcCs4tjj|}|dkrtj}|j|}|r0|jSdS)zCGet the installed version of dist_name avoiding pkg_resources cacheN)r Requirementr WorkingSetrversion) dist_namerreqrrQrQrRr>qs   cCst|dddS)zConsume an iterable at C speed.r)maxlenN)r)iteratorrQrQrRconsumesrbcOs@tt|tt|f|}dd|jD}||d<tdf|S)NcSsi|]\}}||qSrQrQ)rrrYrQrQrR szenum..Zreverse_mappingEnum)dictrrangeryitemstype)Z sequentialnamedenumsreverserQrQrRenumsrlcCsXd|kr|dfS|jdd\}}d|kr6|jdd}n|df}tdd|D}||fS)zp Parse out and remove the auth information from a netloc. Returns: (netloc, (username, password)). @Nr{:css"|]}|dkrdnt|VqdS)N)urllib_unquote)rxrQrQrRr sz)split_auth_from_netloc..)NN)rsplitrtuple)netlocauth user_passrQrQrRsplit_auth_from_netlocsrvcCsBt|\}\}}|dkr|S|dkr(dnd}djtj|||dS)z Replace the password in a netloc with "****", if it exists. For example, "user:pass@example.com" returns "user:****@example.com". Nrz:****z{user}{password}@{netloc})userpasswordrs)rvformat urllib_parsequote)rsrwrxrQrQrR redact_netlocs r|cCs8tj|}||j}|j||j|j|jf}tj|}|S)N)rzurlsplitrsschemerOqueryfragment urlunsplit)rZtransform_netlocpurlrs url_piecessurlrQrQrR_transform_urls    rcCs t|dS)Nr)rv)rsrQrQrR _get_netlocsrcCs t|tS)N)rr)rrQrQrRr?scCs t|tS)z.Replace the password in a given url with ****.)rr|)rrQrQrRredact_password_from_urlsrcCszddjtjddjtjddg}|oBtoBtjjtjd|k}|rvtjddgtjd d}t d jd j |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{}.{}.exeNrlz-mrUr{z3To modify pip, please run the following command: {}r ) ryrWrqrrJrOrVrXrYr r)Z modifying_pipZ pip_namesZshould_show_use_python_msgZ new_commandrQrQrR(protect_pip_from_modification_on_windowss r)r@rA)rBrCrDrErF)rGrHrI)F)rz)T)T)FNrNNNNN)N) __future__r contextlibrMiologgingrrJrrrbrer#rWrr collectionsr pip._vendorrpip._vendor.retryingrpip._vendor.sixrpip._vendor.six.movesrrZpip._vendor.six.moves.urllibr rzZ"pip._vendor.six.moves.urllib.parser roZpip._internal.exceptionsr r Zpip._internal.locationsr rrrrZpip._internal.utils.compatrrrrZpip._internal.utils.typingrrrZtypingrrrrrrrr r!r"r#Zpip._vendor.pkg_resourcesr$Zpip._internal.models.linkr%Zpip._internal.utils.uir&__all__ getLoggerrErrr-r=rrrrr;r<bz2 ImportErrorrlzmar:r4r'rcr(r)rr*r,r-r.r/DEFAULT_BUFFER_SIZErr0r1r2r+r3rrrrrrrrrr5r6r7rr8r:objectr;rIcontextmanagerrTr9rUrVr>rbrlrvr|rrr?rrrQrQrQrRs         4                       7' .L'  x