3 ]m@sddlmZddlmZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlmZddlmZmZmZddlmZmZmZmZmZddlm Z ddl!m"Z"dd l#m$Z$dd l%m&Z&e$rdd lm'Z(n dd lm(Z(d ddddddddddddddddddd d!d"d#d$gZ)e j*e+Z,dxZ-dyZ.dzZ/d{Z0e/e-e0e.Z1e/e0Z2yddl3Z3e2e-7Z2Wn e4k re,j5d1YnXyddl6Z6e2e.7Z2Wn e4k re,j5d2YnXd3d4Z7d5d!Z8d6dZ9e&d7d8d9d|d;d Z:ddZdCdZ?dDdZ@dEdZAdFdZBdGdZCejDfdHdIZEdJdZFdKdZGd~dMdZHdNdZIdOdZJdPdQZKdRdSZLdTdUZMdVdWZNdXdYZOdLedLd:d:fdZd[ZPd\d]ZQd^d_ZRd`dZSdadbZTddcdZUdddZVdedZWddgdZXdhdiZYdjdkZZGdldmdme[Z\Gdndodoe(Z]ej^dpdqZ_drd Z`Gdsdtdte[Zaddud$ZbdvdwZcdS))absolute_import)dequeN)InstallationError)console_to_str expanduser stdlib_pkgs) site_packages user_siterunning_under_virtualenvvirtualenv_no_globalwrite_delete_marker_file) 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)pkg_or_module_string ExceptionTypeargskwargsr=1/tmp/pip-build-8jg9gmni/pip/pip/utils/__init__.pyimport_or_raiseIsr?cCsDytj|Wn0tk r>}z|jtjkr.WYdd}~XnXdS)z os.path.makedirs without EEXIST.N)osmakedirsOSErrorerrnoEEXIST)pather=r=r>r'Ps  c CsDy$tjjtjddkr"dtjSWntttfk r>YnXdS)Nr __main__.py-cz %s -m pippip)rGrH) r@rEbasenamesysargv executableAttributeError TypeError IndexErrorr=r=r=r>r!Ys i i)stop_max_delay wait_fixedFcCstj||tddS)N) ignore_errorsonerror)shutilrrmtree_errorhandler)dirrSr=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)funcrEexc_infor=r=r>rVis rVcCsttjjtjj|}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@rEnormcaseabspathrK version_infodecodegetfilesystemencodingencodegetdefaultencoding startswithgetcwdseplen)rEr=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@rEexistsstr)rWextn extensionr=r=r>rs cCs2x&tjjddjD]}||kr|SqWt||S)NPIP_EXISTS_ACTION)r@environgetsplitr)messageoptionsactionr=r=r>ask_path_existssr|cCsZxTtjjdrtd|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: %szrs  cCsL|dkrd|ddS|d kr,d|dS|dkr@d|dSd|SdS) Niz%.1fMBg@@ z%ikBz%.1fkBz%ibytesi@Bi'r=)bytesr=r=r>rs  cCs2tjj|sdStjj|d}tjj|r.dSdS)z@Return True if `path` is a directory containing a setup.py file.Fzsetup.pyT)r@rEisdirrisfile)rEsetup_pyr=r=r>rs   cCstjd|otjd|tjS)zT Returns true if the page appears to be the index page of an svn repository z[^<]*Revision \d+:z#Powered by (?:<a[^>]*?>)?Subversion)researchI)htmlr=���r=���r>���r������s���� c���������� ���C���s$���t�|�d}|j�jdS�Q�R�X�d�S�)Nrbzutf-8)openreadre���)filenamefpr=���r=���r>���r������s���� c�������������c���s ���x|�j�|}|sP�|V��qW�dS�)z7Yield pieces of data from a file-like object until EOF.N)r���)filesizechunkr=���r=���r>��� read_chunks���s ���� r���c�������������C���sh���|�j�dj�d}�d|�krHd|�kr4|�jd|�jdk�s<d|�krH|�jddS�d|�kr\|�jddS�|�dfS�d�S�)N/\rn���ru���)lstripfindrx���)rE���r=���r=���r>���r������s����$  c�������������C���sD���d}x:|�D�]2}t�|\}}|s"dS�|dkr0|}q ||kr dS�q W�dS�)zyReturns true if all the paths have the same leading path name (i.e., everything is in one subdirectory in an archive)NFT)r���)paths common_prefixrE���prefixrestr=���r=���r>���r������s����  Tc�������������C���s2���t�|�}�|rtjj|�}�n tjj|�}�tjj|�S�)zN Convert a path to its canonical, case-normalized, absolute version. )r���r@���rE���realpathrc���rb���)rE���resolve_symlinksr=���r=���r>���r������s ���� c�������������C���s@���t�j|�\}}|j�jdr8|dd�|�}|dd�}||fS�)z,Like os.path.splitext, but take off .tar tooz.tar���Nr���) posixpathr���r���endswith)rE���baserq���r=���r=���r>���r������s ���� c���������� ���C���s|���t�jj|\}}|r0|r0t�jj| �r0t�j|�tj|�|�t�jj|�\}}|rx|rxyt�j|�W�n�tk rv���Y�nX�dS�)z7Like os.renames(), but handles renaming across devices.N) r@���rE���rx���ro���rA���rU���move removedirsrB���)oldnewheadtailr=���r=���r>���r�����s����  c�������������C���sr���t�|�}�t�tj}t�r(|�jt�tjS�ddlm}�|�j|rjx&|dj�D�]}|�jt�|rLdS�qLW�dS�dS�dS�)aB�� Return True if this is a path pip is allowed to modify. If we're in a virtualenv, sys.prefix points to the virtualenv's prefix; only sys.prefix is considered local. If we're not in a virtualenv, in general we can modify anything. However, if the OS vendor has configured distutils to install somewhere other than sys.prefix (which could be a subdirectory of sys.prefix, e.g. /usr/local), we consider sys.prefix itself nonlocal and the domain of the OS vendor. (In other words, everything _other than_ sys.prefix is considered local.) r���)distutils_schemeru���TFN)r���rK���r���r ���ri��� pip.locationsr���values)rE���r���r��� local_pathr=���r=���r>���is_local��s����   r���c�������������C���s ���t�t|�S�)zh Return True if given Distribution object is installed somewhere pip is allowed to modify. )r��� dist_location)distr=���r=���r>��� dist_is_local5��s����r���c�������������C���s���t�t|�}|jt�tS�)zF Return True if given Distribution is installed in user site. )r���r���ri���r ���)r��� norm_pathr=���r=���r>���dist_in_usersite>��s���� r���c�������������C���s���t�t|�jt�tS�)ze Return True if given Distribution is installed in distutils.sysconfig.get_python_lib(). )r���r���ri���r���)r���r=���r=���r>���dist_in_site_packagesF��s���� r���c�������������C���s8���x2t�jD�](}tjj||�jd�}tjj|rdS�qW�dS�)z$Is distribution an editable install?z .egg-linkTF)rK���rE���r@���r��� project_namer���)r��� path_itemegg_linkr=���r=���r>���dist_is_editableP��s ����  r���c����������������sl���|�r t�ndd�|r dd��ndd��|r6dd�ndd�|rHtnd d ��fd d tjD�S�) 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. c�������������S���s���dS�)NTr=���)dr=���r=���r>��� local_testr��s����z/get_installed_distributions.<locals>.local_testc�������������S���s���dS�)NTr=���)r���r=���r=���r>��� editable_testv��s����z2get_installed_distributions.<locals>.editable_testc�������������S���s ���t�|� �S�)N)r���)r���r=���r=���r>���r���y��s����c�������������S���s���t�|�S�)N)r���)r���r=���r=���r>���editables_only_test}��s����z8get_installed_distributions.<locals>.editables_only_testc�������������S���s���dS�)NTr=���)r���r=���r=���r>���r�����s����c�������������S���s���dS�)NTr=���)r���r=���r=���r>��� user_test��s����z.get_installed_distributions.<locals>.user_testc����������������s:���g�|�]2}|r|j�kr�|r|r|r|qS�r=���)key).0r���)r���r���r���skipr���r=���r>��� <listcomp>��s ���� z/get_installed_distributions.<locals>.<listcomp>)r���r���r ��� working_set) local_onlyr���include_editableseditables_only user_onlyr=���)r���r���r���r���r���r>���get_installed_distributionsY��s����  r���c�������������C���s���g�}t��r6t�r|jt�qN|jt�trN|jt�ntrD|jt�|jt�x0|D�](}tjj||�jd�}tjj |rT|S�qTW�dS�)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 ���appendr���r ���r@���rE���r���r���r���)r���sitessiteegglinkr=���r=���r>��� egg_link_path��s����       r���c�������������C���s���t�|�}|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. )r���location)r���r���r=���r=���r>���r�����s����r���c����������� ���C���s���dd�}�|�dp|�dp|�d}|sZy(t�jt�j�t�j}|�|}t�j|�W�n ���Y�nX�|szt�jjddt�jjdd f}t|d�t|d�fS�) zlReturns a tuple (x, y) representing the width(x) and the height(x) in characters of the terminal window.c���������� ���S���sP���y4dd�l�}dd�l}dd�l}|jd|j|�|jd}W�n ���d�S�|dkrLd�S�|S�)Nr���hh1234)r���r���)fcntltermiosstructunpackioctl TIOCGWINSZ)fdr���r���r���crr=���r=���r>��� ioctl_GWINSZ��s����z'get_terminal_size.<locals>.ioctl_GWINSZr���rn���r_���LINES���COLUMNSP���)r@���r���ctermidO_RDONLYcloserv���rw���int)r���r���r���r=���r=���r>���r �����s����c��������������C���s���t�jd}�t�j|��|�S�)zBGet the current umask which involves having to set it temporarily.r���)r@���umask)maskr=���r=���r>��� current_umask��s����  r���c������� ������C���s��t�|�t|�d}ztj|dd}t|j�o0|}x|j�D�]}|j}|j|}|} |rdt |d�} t j j || } t j j | } | jds| jdrt�| �q<t�| �t| d} z| j|�W�d| j��|jd ?�} | rtj| r| d @�rt j| d t��d B��X�q<W�W�d|j��X�dS�) 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. r���T) allowZip64rn���r���r���wbN���I���i��)r'���r���zipfileZipFiler���namelistinfolistr���r���r���r@���rE���r���dirnamer���writer��� external_attrrX���S_ISREGr[���r���) r���r���flattenzipfpzipleadinginfonamedatafnrW���r���moder=���r=���r>���r"�����s0����         c������� ��� ���C���s ��t�|�|�j�jds$|�j�jdr*d}nL|�j�jtr>d}n8|�j�jtrRd}n$|�j�jdrfd}ntjd|��d }tj|�|}zxt d d �|j �D�}xZ|j �D�]L}|j }|d krq|rt |d �}t jj||}|j�rt�|�q|j�rDy|j||�W�n8�tk r@�}�ztjd|�|j |�wW�Y�dd}~X�nX�qy|j|} W�n<�ttfk r�}�ztjd|�|j |�wW�Y�dd}~X�nX�t�t jj|�t|d} tj| | �W�dQ�R�X�| j��|j||�|jd@�rt j|dt��dB��qW�W�d|j��X�dS�)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:*c�������������S���s���g�|�]}|j�d�kr|j�qS�)pax_global_header)r���)r���memberr=���r=���r>���r���0��s����zuntar_file.<locals>.<listcomp>r���rn���z/In the tar file %s the member %s is invalid: %sNr���r���i��)r'���r���r���BZ2_EXTENSIONS XZ_EXTENSIONSloggerwarningtarfiler���r��� getmembersr���r���r@���rE���r���r���issym_extract_memberr~��� extractfileKeyErrorrN���r���rU��� copyfileobjr���utimer���r[���r���) r���r���r���tarr���r���r���rE���excr���destfpr=���r=���r>���r#�����s`����          c�������������C���s���t�jj|�}�|dks,|�j�jts,tj|�rDt|�||�jd �d�n|dkslt j |�sl|�j�jt t �t �rxt|�|�nX|r|jdrtt|�rddlm}�|d|j�j|�ntjd |�||�td |�d�S�) Nzapplication/zipz.whl)r���zapplication/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@���rE���r���r���r���ZIP_EXTENSIONSr��� is_zipfiler"���r�� is_tarfileTAR_EXTENSIONSr���r���r#���ri���r���r���pip.vcs.subversionr ��urlr���r���criticalr���)r���r��� content_typelinkr ��r=���r=���r>���r$���a��s,����       raisec�������������C���s,��|r d�}nt�j}|d�krng�}xF|�D�]>} d| ksFd| ksFd| ksFd| krVd| jdd�} |j| �q"W�dj|}tjd|�tjj �} |r| j |�yt�j |�t�j d�||| d} W�n2�t k r�} �ztjd | |��W�Y�d�d�} ~ X�nX�|d�k rNg�} x\t| jj�}|sP�|j�}| j|d��tj�tjkr:tj|�q|d�k r|j��qW�| j��|d�k r~| jrt|jd �n |jd �| jr|d krtj�tjkr| �rtjd |�tjdj| d��td|| j|f�n:|dkrtjd|| j|�n|dkrntdt|�|s(dj| S�d�S�)N  "'z"%s"z\"zRunning command %s)stderrstdinstdoutcwdenvz#Error %s while executing command %serrordoner��z Complete output from command %s:ru���z) ----------------------------------------z,Command "%s" failed with error code %s in %swarnz$Command "%s" had error code %s in %signorezInvalid value: on_returncode=%s) subprocessPIPEr`���r���r���r���debugr@���rv���copyupdatePopenSTDOUTr~���r��r���r��readlinerstripgetEffectiveLevel std_loggingDEBUGspinwait returncodefinishr���r���r��� ValueErrorrepr)cmd show_stdoutr�� on_returncode command_desc extra_environspinnerr�� cmd_partspartr��procr �� all_outputliner=���r=���r>���r%�����sz����                  c�������������C���sx���t�|�d}|j�}W�dQ�R�X�dtjddg}x4|D�],}y|j|}W�n�tk r\���w4Y�nX�P�q4W�t|tkstt|S�)aR��Return 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. r���Nzutf-8Flatin1) r���r���localegetpreferredencodingre���UnicodeDecodeErrortyper���AssertionError)r���r���r��� encodingsencr=���r=���r>���read_text_file��s����  rI��c�������������C���s���t�j|��t|��d�S�)N)r@���rA���r ���) build_dirr=���r=���r>���_make_build_dir��s���� rK��c���������������@���s(���e�Zd�ZdZdd�Zdd�Zdd�ZdS�) FakeFilezQWrap a list of lines in an object with readline() to make ConfigParser happy.c�������������C���s���dd�|D�|�_�d�S�)Nc�������������s���s���|�] }|V��qd�S�)Nr=���)r���lr=���r=���r>��� <genexpr>��s����z$FakeFile.__init__.<locals>.<genexpr>)_gen)selflinesr=���r=���r>���__init__��s����zFakeFile.__init__c�������������C���sD���y*y t�|�jS��tk r&���|�jj��S�X�W�n�tk r>���dS�X�d�S�)Nru���)nextrO�� NameError StopIteration)rP��r=���r=���r>���r+����s���� zFakeFile.readlinec�������������C���s���|�j�S�)N)rO��)rP��r=���r=���r>���__iter__��s����zFakeFile.__iter__N)__name__ __module__ __qualname____doc__rR��r+��rV��r=���r=���r=���r>���rL����s��� rL��c���������������@���s$���e�Zd�Zedd�Zedd�ZdS�) StreamWrapperc�������������C���s ���||�_�|��S�)N) orig_stream)clsr\��r=���r=���r>��� from_stream��s����zStreamWrapper.from_streamc�������������C���s���|�j�jS�)N)r\��encoding)rP��r=���r=���r>���r_����s����zStreamWrapper.encodingN)rW��rX��rY�� classmethodr^��propertyr_��r=���r=���r=���r>���r[����s��� r[��c���������� ���c���s@���t�t|�}tt|�tj|�zt�t|�V��W�dtt|�|�X�dS�)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)getattrrK���setattrr[��r^��) stream_name orig_stdoutr=���r=���r>���captured_output!��s ���� rf��c���������������C���s���t�dS�)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��)rf��r=���r=���r=���r>���r&���0��s���� c���������������@���s ���e�Zd�ZdZdd�Zdd�ZdS�)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 c�������������C���s���t�|d|�_||�_d�S�)NrZ��)rb��rZ��r]���)rP��r]���r=���r=���r>���rR��D��s���� zcached_property.__init__c�������������C���s(���|d�kr |�S�|�j�|�}|j|�j�j<�|S�)N)r]���__dict__rW��)rP��objr]��valuer=���r=���r>���__get__H��s����zcached_property.__get__N)rW��rX��rY��rZ��rR��rk��r=���r=���r=���r>���rg��<��s���rg��c�������������C���s@���t�jj|�}|dkrt�j�}n t�j|}|j|}|r<|jS�dS�)zCGet the installed version of dist_name avoiding pkg_resources cacheN)r ��� Requirementparse WorkingSetr���version) dist_name lookup_dirsreqr���r���r=���r=���r>���r*���P��s ����    c�������������C���s���t�|�dd�dS�)zConsume an iterable at C speed.r���)maxlenN)r���)iteratorr=���r=���r>���consumed��s����ru��)r+���r,���)r-���r.���r/���r0���r1���)r2���r3���)r4���r5���r6���)F)rm���)T)T)TNr��NNN)N)d __future__r��� collectionsr��� contextlibrC���iorB��loggingr.��r���r@���r���rU���rX���r$��rK���r��r���pip.exceptionsr��� pip.compatr���r���r���r���r���r ���r ���r ���r ��� pip._vendorr ���Zpip._vendor.six.movesr���Zpip._vendor.sixr���Zpip._vendor.retryingr���r���r���__all__ getLoggerrW��r���r���r���r ��r��r(���r)���bz2r8���r&��lzmar?���r'���r!���r���rV���r���r���r|���r���r���r���r���r���DEFAULT_BUFFER_SIZEr���r���r���r���r���r���r���r���r���r���r���r���r���r���r ���r���r"���r#���r$���r%���rI��rK��objectrL��r[��contextmanagerrf��r&���rg��r*���ru��r=���r=���r=���r>���<module>���s���                          5% +L!��� _