3 Pfml@sddlmZddlmZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlmZddlmZmZmZddlmZmZmZmZmZmZddl m!Z!ddl"m#Z#dd l$m%Z%dd l&m'Z'e%r dd lm(Z)n dd lm)Z)d ddddddddddddddddddd d!d"d#d$gZ*e j+e,Z-dzZ.d{Z/d|Z0d}Z1e0e.e1e/Z2e0e1Z3yddl4Z4e3e.7Z3Wn e5k re-j6d1YnXyddl7Z7e3e/7Z3Wn e5k re-j6d2YnXd3d4Z8d5d!Z9d6dZ:e'd7d8d9d~d;d Z;ddZ=dd@dZ>dAdBZ?dCdZ@dDdZAdEdZBdFdZCdGdZDejEfdHdIZFdJdZGdKdZHddMdZIdNdZJdOdZKdPdQZLdRdSZMdTdUZNdVdWZOdXdYZPdZd[ZQdLedLd:d:fd\d]ZRd^d_ZSd`daZTdbdZUdcddZVddedZWdfdZXdgdZYddidZZdjdkZ[dldmZ\Gdndodoe]Z^Gdpdqdqe)Z_ej`drdsZadtd ZbGdudvdve]Zcddwd$ZddxdyZedS))absolute_import)dequeN)InstallationError)console_to_str expanduser stdlib_pkgs) site_packages user_siterunning_under_virtualenvvirtualenv_no_globalwrite_delete_marker_filedistutils_scheme) pkg_resources)input)PY2)retry)BytesIO)StringIOrmtree display_path backup_dirasksplitext format_sizeis_installable_dir is_svn_page file_contentssplit_leading_dirhas_leading_dirnormalize_pathrenamesget_terminal_sizeget_prog unzip_file untar_file unpack_filecall_subprocesscaptured_stdout ensure_dirARCHIVE_EXTENSIONSSUPPORTED_EXTENSIONSget_installed_version.tar.bz2.tbz.tar.xz.txz.tlz.tar.lz .tar.lzma.zip.whl.tar.gz.tgz.tarzbz2 module is not availablezlzma module is not availablec Os,yt|Stk r&|||YnXdS)N) __import__ ImportError)Zpkg_or_module_stringZ ExceptionTypeargskwargsr</usr/lib/python3.6/__init__.pyimport_or_raiseIsr>cCsDytj|Wn0tk r>}z|jtjkr.WYdd}~XnXdS)z os.path.makedirs without EEXIST.N)osmakedirsOSErrorerrnoZEEXIST)pather<r<r=r(Ps  c CsDy$tjjtjddkr"dtjSWntttfk r>YnXdS)Nr __main__.py-cz %s -m pipZpip)rErF) r?rCbasenamesysargv executableAttributeError TypeError IndexErrorr<r<r<r=r"Ys i i)Zstop_max_delayZ wait_fixedFcCstj||tddS)N) ignore_errorsonerror)shutilrrmtree_errorhandler)dirrNr<r<r=rcscCs2tj|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)r?statst_modeS_IREADchmodS_IWRITE)funcrCexc_infor<r<r=rQis rQcCsttjjtjj|}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)r?rCnormcaseabspathrH version_infodecodegetfilesystemencodingencodegetdefaultencoding startswithgetcwdseplen)rCr<r<r=rxs.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))r?rCexistsstr)rRextn extensionr<r<r=rs cCs2x&tjjddjD]}||kr|SqWt||S)NZPIP_EXISTS_ACTION)r?environgetsplitr)messageoptionsactionr<r<r=ask_path_existssrvcCsZxTtjjdrtd|t|}|jj}||krNtd|dj|fq|SqWdS)z@Ask the message interactively, with the given possible responsesZ PIP_NO_INPUTz7No input was expected ($PIP_NO_INPUT set); question: %sz[^<]*Revision \d+:z#Powered by (?:]*?>)?Subversion)researchI)Zhtmlr<r<r=rs c Cs$t|d}|jjdSQRXdS)Nrbzutf-8)openreadr`)filenamefpr<r<r=rs ccs x|j|}|sP|VqWdS)z7Yield pieces of data from a file-like object until EOF.N)r)filesizechunkr<r<r= read_chunkss  rcCsh|jdjd}d|krHd|kr4|jd|jdkss rcCs8x2tjD](}tjj||jd}tjj|rdSqWdS)z$Is distribution an editable install?z .egg-linkTF)rHrCr?r{ project_namer)rZ path_itemegg_linkr<r<r=dist_is_editableHs   rcsl|r tndd|r ddndd|r6ddndd|rHtnd d fd d tjDS) a Return a list of installed Distribution objects. If ``local_only`` is True (default), only return installations local to the current virtualenv, if in a virtualenv. ``skip`` argument is an iterable of lower-case project names to ignore; defaults to stdlib_pkgs If ``editables`` is False, don't report editables. If ``editables_only`` is True , only report editables. If ``user_only`` is True , only report installations in the user site directory. cSsdS)NTr<)dr<r<r= local_testjsz/get_installed_distributions..local_testcSsdS)NTr<)rr<r<r= editable_testnsz2get_installed_distributions..editable_testcSs t| S)N)r)rr<r<r=rqscSst|S)N)r)rr<r<r=editables_only_testusz8get_installed_distributions..editables_only_testcSsdS)NTr<)rr<r<r=rxscSsdS)NTr<)rr<r<r= user_test~sz.get_installed_distributions..user_testcs:g|]2}|r|jkr|r|r|r|qSr<)key).0r)rrrskiprr<r= s  z/get_installed_distributions..)rrr working_set)Z local_onlyrZinclude_editablesZeditables_onlyZ user_onlyr<)rrrrrr=get_installed_distributionsQs  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 r appendrr r?rCr{rr)rZsitesZsiteZegglinkr<r<r= 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)rrr<r<r=rsrc Csdd}|dp|dp|d}|sZy(tjtjtj}||}tj|Wn YnX|sztjjddtjjdd f}t|dt|dfS) zlReturns a tuple (x, y) representing the width(x) and the height(x) in characters of the terminal window.c SsPy4ddl}ddl}ddl}|jd|j||jd}Wn dS|dkrLdS|S)NrZhhZ1234)rr)fcntltermiosstructunpackZioctlZ TIOCGWINSZ)fdrrrcrr<r<r= ioctl_GWINSZsz'get_terminal_size..ioctl_GWINSZrrirZZLINESZCOLUMNSP)r?rctermidO_RDONLYcloserprqint)rrrr<r<r=r!scCstjd}tj||S)zBGet the current umask which involves having to set it temporarily.r)r?umask)maskr<r<r= current_umasks  rc Cst|t|d}ztj|dd}t|jo0|}x|jD]}|j}|j|}|} |rdt |d} t j j || } t j j | } | jds| jdrt| qd}n8|jjtrRd}n$|jjdrfd}ntjd|d }tj||}zt d d |j D}x|j D]}|j }|d krq|rt |d }t jj||}ytj|j|d|Wntjk r YnX|jr"t|q|jrxy|j||Wn8tk rt}ztjd||j |wWYdd}~XnXqy|j|} Wn<ttfk r}ztjd||j |wWYdd}~XnXtt jj|t|d} tj| | WdQRX| j|j|||jd@rt j |dt!dBqWWd|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|]}|jdkr|jqS)pax_global_header)r)rmemberr<r<r=r(szuntar_file..rri)rz/In the tar file %s the member %s is invalid: %sNrri)"r(ryrBZ2_EXTENSIONS XZ_EXTENSIONSloggerwarningtarfilerrZ getmembersrrr?rCr{Z data_filterr[ZLinkOutsideDestinationErrorr~ZissymZ_extract_memberrwZ extractfileKeyErrorrKrrPZ copyfileobjrutimerrVr) rrrZtarrrrrCexcrZdestfpr<r<r=r$ sh           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)r?rCrryrZIP_EXTENSIONSrZ is_zipfiler#rZ is_tarfileTAR_EXTENSIONSrrr$rdrrZpip.vcs.subversionrZurlrrcriticalr)rrZ content_typelinkrr<r<r=r%`s,       raisecCs,|r d}ntj}|dkrng}xF|D]>} d| ksFd| ksFd| ksFd| krVd| jdd} |j| q"Wdj|}tjd|tjj } |r| j |ytj |tj d||| d} Wn2t k r} ztjd | |WYdd} ~ XnX|dk rNg} x\t| jj}|sP|j}| j|dtjtjkr:tj|q|dk r|jqW| j|dk r~| jrt|jd n |jd | jr|d krtjtjkr| rtjd |tjdj| dtd|| j|fn:|dkrtjd|| j|n|dkrntdt||s(dj| SdS)N  "'z"%s"z\"zRunning command %s)stderrstdinstdoutcwdenvz#Error %s while executing command %serrordonerz Complete output from command %s:roz) ----------------------------------------z,Command "%s" failed with error code %s in %swarnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=%s) subprocessPIPEr[rr{rdebugr?rpcopyupdatePopenZSTDOUTrwrrrreadlinerstripZgetEffectiveLevel std_loggingDEBUGZspinwait returncodeZfinishrrr ValueErrorrepr)cmdZ show_stdoutrZ on_returncodeZ command_descZ extra_environZspinnerrZ cmd_partspartrprocrZ all_outputliner<r<r=r&sz                  cCsxt|d}|j}WdQRXdtjddg}x4|D],}y|j|}Wntk r\w4YnXPq4Wt|tkstt|S)aRReturn the contents of *filename*. Try to decode the file contents with utf-8, the preferred system encoding (e.g., cp1252 on some Windows machines), and latin1, in that order. Decoding a byte string with latin1 will never raise an error. In the worst case, the returned string will contain some garbage characters. rNzutf-8Flatin1) rrlocalegetpreferredencodingr`UnicodeDecodeErrortyper}AssertionError)rrrZ encodingsencr<r<r=read_text_files  rcCstj|t|dS)N)r?r@r )Z build_dirr<r<r=_make_build_dirs rc@s(eZdZdZddZddZddZdS) FakeFilezQWrap a list of lines in an object with readline() to make ConfigParser happy.cCsdd|D|_dS)Ncss|] }|VqdS)Nr<)rlr<r<r= sz$FakeFile.__init__..)_gen)selflinesr<r<r=__init__szFakeFile.__init__cCsDy*y t|jStk r&|jjSXWntk r>dSXdS)Nro)nextr NameError StopIteration)rr<r<r=rs zFakeFile.readlinecCs|jS)N)r)rr<r<r=__iter__szFakeFile.__iter__N)__name__ __module__ __qualname____doc__rrrr<r<r<r=rs rc@s$eZdZeddZeddZdS) StreamWrappercCs ||_|S)N) orig_stream)clsr!r<r<r= from_streamszStreamWrapper.from_streamcCs|jjS)N)r!encoding)rr<r<r=r$szStreamWrapper.encodingN)rrr classmethodr#propertyr$r<r<r<r=r s r c 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)getattrrHsetattrr r#)Z stream_nameZ orig_stdoutr<r<r=captured_output s  r)cCstdS)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)r)r<r<r<r=r'/s c@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)Nr)r'rrX)rrXr<r<r=rCs zcached_property.__init__cCs(|dkr |S|j|}|j|jj<|S)N)rX__dict__r)robjr"valuer<r<r=__get__Gszcached_property.__get__N)rrrrrr.r<r<r<r=r*;sr*cCs@tjj|}|dkrtj}n tj|}|j|}|r<|jSdS)zCGet the installed version of dist_name avoiding pkg_resources cacheN)rZ RequirementparseZ WorkingSetrversion)Z dist_nameZ lookup_dirsZreqrrr<r<r=r+Os     cCst|dddS)zConsume an iterable at C speed.r)maxlenN)r)iteratorr<r<r=consumecsr3)r,r-)r.r/r0r1r2)r3r4)r5r6r7)F)rh)T)T)TNrNNN)N)fZ __future__r collectionsr contextlibrBior Zloggingrrr?rrPrSrrHrrZpip.exceptionsrZ pip.compatrrrZ pip.locationsrr r r r r Z pip._vendorrZpip._vendor.six.movesrZpip._vendor.sixrZpip._vendor.retryingrrr__all__Z getLoggerrrrrrrr)r*bz2r9rZlzmar>r(r"rrQrrrvrrrrrDEFAULT_BUFFER_SIZErrrrrr rrrrrrrrrr!rr#r$r%r&rrobjectrr contextmanagerr)r'r*r+r3r<r<r<r=s                            5% +S! _