Re$b@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z mZddlmZmZmZmZmZmZddlmZmZmZddlmZddlmZddlmZdd d d d d ddddddddddddddddddd gZ d!dZ!d"d#dZ"d$d%Z#d&d Z$d'd(d Z%ddd)d Z&dd*d+Z'd,d-Z(d.d Z)Gd/d0d0e*Z+e+Z,[+ej-d1ej.Z/d2dZ0d3dZ1d4dZ2d5dZ3d6dZ4d7dZ5d8dZ6d9dZ7d:dZ8d;dZ9d<dZ:d=d>Z;d?d@Z<dAdBZ=dCdDZ>dEdFZ?dGd_dGd"dLdMZ@dNdOZAdPdQZBdRdZCdSdTZDdGdUdZEdVdZFdWdZGdXdZHdYdZIdGdddGejJdddZd ZKd[d\ZLGd]d^d^e*ZMdS)`N)InstallationError BadCommandPipError) WindowsError string_types raw_inputconsole_to_str user_sitePermissionError) site_packagesrunning_under_virtualenvvirtualenv_no_global)logger) pkg_resources)versionrmtree display_path backup_dir find_commandaskInfnormalize_namesplitext format_sizeis_installable_dir is_svn_page file_contentssplit_leading_dirhas_leading_dirmake_path_relativenormalize_pathrenamesget_terminal_sizeget_prog unzip_file untar_filecreate_download_cache_foldercache_download unpack_filecall_subprocessc CsPy.tjjtjddkr-dtjSWntttfk rKYnXdS)Nr __main__.py-cz %s -m pippip)r*r+) ospathbasenamesysargv executableAttributeError TypeError IndexErrorr6r6#/tmp/pip-ztkk0jow-build/pip/util.pyr#!s FcCstj|d|dtdS)N ignore_errorsonerror)shutilrrmtree_errorhandler)dirr8r6r6r7r*scCs|dd\}}|tkr5|jddkpp|tkrT|jddkpp|tkop|jddksyntj|jtj@tjkrntj|tj ||dS)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.Nr ) rargsOSErrorr r-statst_modeS_IREADchmodS_IWRITE)funcr.exc_infoexctypevaluer6r6r7r;/s"r;cCsdtjjtjj|}|jtjtjjr`d|ttjd}n|S)zTGives the display value for a given path, making it relative to cwd if possible..N)r-r.normcaseabspath startswithgetcwdseplen)r.r6r6r7rBs#z.bakcCsKd}|}x4tjj||rB|d7}|t|}qW||S)z\Figure out the name of a directory to back up the given dir to (adding .bak, .bak2, etc))r-r.existsstr)r<extn extensionr6r6r7rKs  cCs7|dkr0tjjddjtj}nt|trK|g}n|dkrct}ndd|jjtjD}tj j |dj|krdg}nxj|D]b}tj j ||}x.|D]&}||}tj j |r|SqWtj j |r|SqWt d|dS)z_s z find_command..rSzCannot find command %r)r-environgetsplitpathsep isinstancer get_pathextlowerr.rjoinisfiler)cmdpathspathextr.cmd_pathrV cmd_path_extr6r6r7rVs$ $   %"    cCsF|dkr-tjjddddg}ntjjd|}|S)z9Returns the path extensions from environment or a defaultNz.COMz.EXEz.BATz.CMDPATHEXT)r-r`rdr]r^)default_pathextrhr6r6r7rbqs !rbcCsCx3tjjddjD]}||kr|SqWt||S)NPIP_EXISTS_ACTIONrZ)r-r]r^r_r)messageoptionsactionr6r6r7ask_path_existsys" rqcCs~xwtjjdr(td|nt|}|jj}||krrtd|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)htmlr6r6r7rsc Cs8t|d}z|jjdSWd|jXdS)Nrbzutf-8)openreaddecodeclose)filenamefpr6r6r7rscCst|}|jdjd}d|krvd|krZ|jd|jdksfd|krv|jddSd|kr|jddS|dfSdS)N/\rSrZ)rUlstripfindr_)r.r6r6r7rs 6  cCs\d}xO|D]G}t|\}}|s/dS|dkrD|}q ||kr dSq WdS)zyReturns true if all the paths have the same leading path name (i.e., everything is in one subdirectory in an archive)NFT)r)rg common_prefixr.prefixrestr6r6r7rs    cCs7tjj|}tjj|}tjjtjj|}tjjtjj|}|jtjjjtjj}|jtjjjtjj}x>|r|r|d|dkr|j d|j dqWdgt |||g}|dgkr$dtjjStjjj |S)a Make a filename relative, where the filename path, and it is relative to rel_to >>> make_relative_path('/usr/share/something/a-file.pth', ... '/usr/share/another-place/src/Directory') '../../../something/a-file.pth' >>> make_relative_path('/usr/share/something/a-file.pth', ... '/home/user/src/Directory') '../../../usr/share/something/a-file.pth' >>> make_relative_path('/usr/share/a-file.pth', '/usr/share/') 'a-file.pth' rz..rZrL) r-r.r/dirnamenormpathrNrtrQr_poprRrd)r.rel_to path_filename path_parts rel_to_parts full_partsr6r6r7rs$$# cCs(tjjtjjtjj|S)zN Convert a path to its canonical, case-normalized, absolute version. )r-r.rMrealpath expanduser)r.r6r6r7r scCs[tj|\}}|jjdrQ|dd|}|dd}n||fS)z,Like os.path.splitext, but take off .tar tooz.tarNr) posixpathrrcendswith)r.baserVr6r6r7rs c Cstjj|\}}|rG|rGtjj| rGtj|ntj||tjj|\}}|r|rytj|Wqtk rYqXndS)z7Like os.renames(), but handles renaming across devices.N) r-r.r_rTmakedirsr:move removedirsrB)oldnewheadtailr6r6r7r!!s  cCs)ts dSt|jttjS)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." T)r r rOr0r)r.r6r6r7is_local2s rcCstt|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_location)distr6r6r7 dist_is_local>srcCs-tr%tt|jttSdSdS)zF Return True if given Distribution is installed in user site. FN)r r rrO)rr6r6r7dist_in_usersiteIsrcCstt|jttS)za Return True if given Distribution is installed in distutils.sysconfig.get_python_lib(). )r rrOr )rr6r6r7dist_in_site_packagesRsrcCs)ddlm}|j|g}|jS)z$Is distribution an editable install?r)FrozenRequirement)r,r from_disteditable)rrreqr6r6r7dist_is_editableYsrT setuptoolsr,python distributecs|rtn dd|r0ddn dd|rQddn ddfddtjDS) 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 ('setuptools', 'pip', 'python'). [FIXME also skip virtualenv?] If ``editables`` is False, don't report editables. If ``editables_only`` is True , only report editables. cSsdS)NTr6)dr6r6r7vsz-get_installed_distributions..cSsdS)NTr6)rr6r6r7ryscSs t| S)N)r)rr6r6r7r{scSs t|S)N)r)rr6r6r7r~scSsdS)NTr6)rr6r6r7rscsIg|]?}|r|jkr|r|r|qSr6)key)r[r) editable_testeditables_only_test local_testskipr6r7r\s   z/get_installed_distributions..)rr working_set) local_onlyrinclude_editableseditables_onlyr6)rrrrr7get_installed_distributions`s    rcCsg}trNtr(|jtqq|jttrq|jtqqn#trd|jtn|jtx@|D]8}tjj||jd}tjj |rx|SqxWdS)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-r.rd project_namere)rsitessiteegglinkr6r6r7 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)regg_linkr6r6r7rs rc Csdd}|dp-|dp-|d}|s|y8tjtjtj}||}tj|Wq|Yq|Xn|stjjddtjjdd f}nt|dt|dfS) zlReturns a tuple (x, y) representing the width(x) and the height(x) in characters of the terminal window.c SsyLddl}ddl}ddl}|jd|j||jd}Wn dSYnX|dkrkdS|dkr{dS|S)Nrhh1234)rr)rr)fcntltermiosstructunpackioctl TIOCGWINSZ)fdrrrcrr6r6r7 ioctl_GWINSZs      z'get_terminal_size..ioctl_GWINSZrrSr=LINESCOLUMNSP)r-rctermidO_RDONLYrr]r^int)rrrr6r6r7r"s $ -cCs tjd}tj||S)zBGet the current umask which involves having to set it temporarily.r)r-umask)maskr6r6r7 current_umasks rc Cstjj|s"tj|nt|d}z}tj|}t|joX|}xO|j D]A}|j }|j |}|} |rt |d} ntjj || } tjj| } tjj| stj| n| jds | jdr1tjj| stj| qqht| d} z| j|Wd| j|jd?} | rtj| r| d@rtj| d tdBnXqhWWd|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. rrSrrwbNIi)r-r.rTrrzipfileZipFilernamelistinfolistrrrrdrrwriter external_attrrCS_ISREGrFr) rrflattenzipfpzipleadinginfordatafnr<rmoder6r6r7r$s6    'c Cstjj|s"tj|n|jjdsL|jjdrUd}nh|jjds|jjdrd}n5|jjdrd}ntjd |d }tj ||}zt d d |j D}x|j D]}|j }|d krqn|r8t |d}ntjj||}|jr~tjj|stj|qq|jry|j||Wqtjd}tjd||j |fwYqXqy|j|} WnHttfk r9tjd}tjd||j |fwYnXtjjtjj|sttjtjj|nt |d} ztj| | Wd| jX| j|jd@rtj|dtdBqqWWd|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:gzz.bz2z.tbzzr:bz2z.tarrz-Cannot determine compression type for file %szr:*cSs(g|]}|jdkr|jqS)pax_global_header)r)r[memberr6r6r7r\$s zuntar_file..rrSz/In the tar file %s the member %s is invalid: %srNri)r-r.rTrrcrrwarntarfilerr getmembersrrrdrissym_extract_memberr0rI extractfileKeyErrorr3rr: copyfileobjrrrFr) rrrtarrrrr.erdestfpr6r6r7r% sf * *          &cCs@tjd8_tjd|tjd7_tj|dS)Nr=z&Creating supposed download cache at %s)rindentnotifyr-r)folderr6r6r7r&XscCsUtjdt|tj||t|dd}|j||jdS)NzStoring download in cache at %sz .content-typew)rr rr:copyfilerrr) target_file temp_location content_typerr6r6r7r'_s  cCsCtjj|}|dksZ|jdsZ|jdsZ|jdsZtj|rzt||d|jd n|dkstj|st |dj dkrt ||n~|r|j d rt t|rddlm}|d|jj|n*tjd|||ftd|dS)Nzapplication/zipz.zip .pybundle.whlrzapplication/x-gziprS.tar.tar.gz.tar.bz2.tgz.tbzz text/htmlr) Subversionzsvn+zZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz%Cannot determine archive format of %s)rr)rrrrr)r-r.rrr is_zipfiler$r is_tarfilerrcr%rOrrpip.vcs.subversionrurlrrfatalr)rrrlinkrr6r6r7r(gs$    cCs|dkrg}xd|D]\} d| ksOd| ksOd| ksOd| krhd| jdd} n|j| qWdj|}n|rd} n tj} tj|d|tjj } |r| j |ny4tj |dtj d dd | d |d | } Wn<t k rNtjd } tjd| |fYnXg}| dk r| j} xt| j}|sPn|j}|j|d|r||}t|tr|\}}ntj||tj|stjqqmtj|qmWn!| j\}}|p4dg}| j| jr|r|rtjd|tjdj|dntd|| j|fqtjd|| j|fn| dk rdj|SdS)N  "'z"%s"z\"zRunning command %sstderrstdinstdoutcwdenvrSz#Error %s while executing command %srZz Complete output from command %s:z) ----------------------------------------z*Command %s failed with error code %s in %sz"Command %s had error code %s in %s) replacerrd subprocessPIPErlogr-r]copyupdatePopenSTDOUTrsr0rIr r(rreadlinerstripratuplestdout_level_matches show_progressr communicatewait returncoder rr)rf show_stdout filter_stdoutr)raise_on_returncode command_level command_desc extra_environ cmd_partspartr(r*procr  all_outputlinelevelreturned_stdoutreturned_stderrr6r6r7r)sp  0          cCsEtj|}|dkrdStj|}tdd|DS)z Attempt to determine if this is a pre-release using PEP386/PEP426 rules. Will return True if it is a pre-release and False if not. Versions are assumed to be a pre-release if they cannot be parsed. NTcSs)g|]}tdd|DqS)c Ss1g|]'}|tdddddgkqS)abcrcdev)set)r[yr6r6r7r\s z,is_prerelease...)any)r[xr6r6r7r\s z!is_prerelease..)r_suggest_normalized_version_normalized_keyrP)vers normalizedparsedr6r6r7 is_prereleases  rWc@sReZdZddddZddZddZdd Zd d ZdS) BuildDirectoryNcCsm|dkr!|dkr!d}n|dkrWtjdd}|dkrWd}qWn||_||_dS)NTrz pip-build-)tempfilemkdtemprdelete)rxrr[r6r6r7__init__s     zBuildDirectory.__init__cCsdj|jj|jS)Nz <{} {!r}>)format __class__rr)rxr6r6r7rszBuildDirectory.__repr__cCs|jS)N)r)rxr6r6r7 __enter__szBuildDirectory.__enter__cCs|jdS)N)cleanup)rxexcrKtbr6r6r7__exit__szBuildDirectory.__exit__cCs|jrt|jndS)N)r[rr)rxr6r6r7r`s zBuildDirectory.cleanup)rrrr\rr_rcr`r6r6r6r7rXs    rX)z setuptoolszpipzpythonz distribute)Nr0r:r-rCrrrrr,textwraprYpip.exceptionsrrrZpip.backwardcompatrrrrr r pip.locationsr r r pip.logr pip._vendorrpip._vendor.distlibr__all__r#rr;rrrrbrqrobjectrwrcompilerrrrrrrrrrr rr!rrrrrrrrr"rr$r%r&r'r(DEBUGr)rWrXr6r6r6r7s           .                    ' "   - L    ?