
 X%                @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z m Z d d l Z d d l m Z m Z d d l m Z d d l m Z m Z d d l m Z d d	 l m Z m Z d d
 l  m! Z! m" Z" m# Z# m$ Z$ d d l% m& Z& m' Z' d d l( m) Z) d d l* m+ Z+ d d l, m- Z- d d l, m. Z. d d l( m/ Z/ m0 Z0 d d l1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 d d l m7 Z7 m8 Z8 m9 Z9 m: Z: m; Z; m< Z< m= Z= m> Z> m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD mE ZE e jF jG d e jH jI e jJ   ZK d d d d d d g ZL d d   ZM d d   ZN e jO d f k rd d   ZP d  d!   ZQ n d" d   ZP d# d!   ZQ Gd$ d   d e  ZR d% d&   ZS d' d(   ZT d) d   ZU d* d   ZV d+ d,   ZW Gd- d   d e=  ZX eK d. d/ d0  ZY d1 d2   ZZ d3 d4   Z[ d5 d6   Z\ d7 d8 d9  Z] d: d;   Z^ d< d=   Z_ d> d?   Z` y d d@ l ma Zb Wn ec k
 rdA dB   Zb Yn XdC dD   Za dE dF   Zd GdG dH   dH ee  Zf GdI dJ   dJ ef  Zg GdK dL   dL eg  Zh ef ji Zi dM dN   Zj dO dP   Zk d. eZ dQ dR  Zl dS dT   Zm dU dV   Zn d dW d  Zo d S)Xa  
Easy Install
------------

A tool for doing automatic download/extract/build of distutils-based Python
packages.  For detailed documentation, see the accompanying EasyInstall.txt
file, or visit the `EasyInstall home page`__.

__ https://pythonhosted.org/setuptools/easy_install.html

    N)glob)logdir_util)Command_dont_write_bytecode)	run_setup)get_pathget_config_vars)get_platform)convert_path
subst_vars)DistutilsArgErrorDistutilsOptionErrorDistutilsErrorDistutilsPlatformError)INSTALL_SCHEMESSCHEME_KEYS)setopt)unpack_archive)PackageIndex)
URL_SCHEME)	bdist_eggegg_info)	iteritemsmaxsize
basestringunicodereraise)yield_linesnormalize_pathresource_stringensure_directoryget_distributionfind_distributionsEnvironmentRequirementDistributionPathMetadataEggMetadata
WorkingSetDistributionNotFoundVersionConflictDEVELOP_DIST__PYVENV_LAUNCHER__samefileeasy_installPthDistributionsextract_wininst_cfgmainget_exe_prefixesc               C   s   t  j d  d k S)NP   )structcalcsize r8   r8   Q/home/ubuntu/projects/ifolica/build/setuptools/setuptools/command/easy_install.pyis_64bit@   s    r:   c             C   s   t  j j |   o! t  j j |  } t t  j d  o9 | } | rU t  j j |  |  St  j j t  j j |    } t  j j t  j j |   } | | k S)Nr.   )ospathexistshasattrr.   normpathnormcase)Zp1Zp2Z
both_existZuse_samefileZnorm_p1Znorm_p2r8   r8   r9   r.   C   s    $   c             C   s   |  S)Nr8   )sr8   r8   r9   	_to_asciiM   s    rC   c             C   s2   y t  |  d  d SWn t k
 r- d SYn Xd  S)NasciiTF)r   UnicodeError)rB   r8   r8   r9   isasciiO   s
    rF   c             C   s   |  j  d  S)NrD   )encode)rB   r8   r8   r9   rC   V   s    c             C   s2   y |  j  d  d SWn t k
 r- d SYn Xd  S)NrD   TF)rG   rE   )rB   r8   r8   r9   rF   X   s
    c               @   s  e  Z d  Z d Z d Z d Z d d d d d d d d d d d d d d d d d d d d d d d g Z d d
 d d d d0 d3 d9 d< d@ g
 Z e j	 r dE e j
 Z e j dF d e f  e j dF  n  i d d* 6Z e Z dG dH   Z dI dJ   Z dK dL   Z dM dN   Z dO dP   Z dQ dR   Z dS dT   Z dU dV   Z dW dX   Z dY dZ   Z d[ d\   Z d] d^   Z d_ d`   Z da db   Z dc dd   Z de df   Z dg dh di  Z  dg dj dk  Z! dl dm   Z" d dn do  Z# dp dq   Z$ dr ds   Z% dt du   Z& d dv dw  Z' dx f  dy dz  Z( d{ d|   Z) d} d~   Z* d d   Z+ d d   Z, d d   Z- d d d  Z. d d   Z/ d d   Z0 d d   Z1 d d   Z2 d d   Z3 d d   Z4 d d   Z5 d d   Z6 d d   Z7 d d   Z8 d d   Z9 e: j; d d  d k sd e: j< k rd Z= n d Z= e> d e> d d d d  d e> d d e= d d  d e> d d e= d d  d e> d d e= d d   Z? e> d d d d  Z@ d d   ZA d S)r/   z'Manage a download/build/install processz Find/get/install Python packagesTprefix=Ninstallation prefixzip-okzinstall package as a zipfilemulti-versionm%make apps have to require() a versionupgradeU1force upgrade (searches PyPI for latest versions)install-dir=dinstall package to DIRscript-dir=rB   install scripts to DIRexclude-scriptsxDon't install scriptsalways-copya'Copy all needed packages to install dir
index-url=i base URL of Python Package Indexfind-links=f(additional URL(s) to search for packagesbuild-directory=b/download/extract/build in DIR; keep the results	optimize=Olalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0]record=3filename in which to record list of installed filesalways-unzipZ*don't install as a zipfile, no matter what
site-dirs=S)list of directories where .pth files workeditablee+Install specified packages in editable formno-depsNdon't install dependenciesallow-hosts=H$pattern(s) that hostnames must matchlocal-snapshots-okl(allow building eggs from local checkoutsversion"print version information and exitinstall-layout=1installation layout to choose (known values: deb)"force-installation-into-system-dir0force installation into /usrno-find-links9Don't load find-links defined in packages being installedz!install in user site-package '%s'userc             C   s  t  j r3 t j j t  } | j t  j  |  _ n	 d |  _ d  |  _	 |  _
 d  |  _ |  _ |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ |  _ d  |  _ |  _ |  _ d  |  _ |  _ |  _ d  |  _ |  _ |  _ d  |  _ d  |  _ d  |  _ d  |  _  d  |  _! d  |  _" d  |  _# d  |  _$ d  |  _% t  j rQt  j& |  _' t  j |  _( n d  |  _' d  |  _( d  |  _) d  |  _* d  |  _+ |  _, d  |  _- i  |  _. d |  _/ d  |  _0 d  |  _1 d  |  _2 d  |  _3 |  j4 j5 |  _5 |  j4 j6 |  |  j4 j7 d   d  S)Nr   Fr/   )8siteENABLE_USER_SITEr;   r<   abspath__file__
startswith	USER_SITEr   zip_oklocal_snapshots_okinstall_dir
script_direxclude_scripts	index_url
find_linksbuild_directoryargsoptimizerecordrP   always_copymulti_versionrr   no_depsallow_hostsrootprefix	no_reportr~   install_purelibinstall_platlibinstall_headersinstall_libinstall_scriptsinstall_datainstall_baseinstall_platbase	USER_BASEinstall_userbaseinstall_usersiteno_find_linkspackage_indexpth_filealways_copy_from	site_dirsinstalled_projectssitepy_installedinstall_layout"force_installation_into_system_dir	multiarch_dry_rundistributionverbose_set_command_optionsget_option_dict)selfZwhereamir8   r8   r9   initialize_options   sR    																												zeasy_install.initialize_optionsc             C   s   x | D] } t  j j |  s1 t  j j |  r t j d |  |  j s t  j j |  r| t  j j |  r| t |  q t  j	 |  q q q Wd  S)NzDeleting %s)
r;   r<   r=   islinkr   infodry_runisdirrmtreeunlink)r   blockersfilenamer8   r8   r9   delete_blockers   s    $	%zeasy_install.delete_blockersc       
      C   s
  |  j  r- t d t d  j   t j   n  t j  j   d } t d d  \ } } i |  j j   d 6|  j j	   d 6|  j j
   d 6| d	 6| d d
  d 6| d | d d 6| d 6| d 6| d 6| d 6t t d d  d 6|  _ t j r|  j |  j d <|  j |  j d <n  |  j rt j r|  j   |  j d  k rNt d   n  |  j |  _ |  _ t j d k r|  j d  q|  j t j d  n  |  j   |  j   |  j r|  j j   d4 k rt d   n  d d  l } t j d  d  d5 k r| j  d  |  _! qn  |  j" d d d d  |  j# d  k rI|  j$ |  _# n  |  j% d  k rdd |  _% n  |  j& d  d6  |  j& d! d7  |  j r|  j' r|  j' |  _$ |  j( |  _# n  |  j) d" k r|  j* rt d#   n  |  j& d$ d8  t+ t, t j-  } t.   |  _/ |  j0 d  k	 rd& d'   |  j0 j d(  D } xq | D]f } t j- j1 |  sgt2 j3 d) |  q<t, |  | k rt | d*   q<|  j/ j4 t, |   q<Wn  |  j5 s|  j6   n  |  j7 pd+ |  _7 |  j/ d  d   |  _8 xE |  j$ t, |  j#  f D]+ } | |  j8 k r |  j8 j9 d |  q q W|  j: d  k	 r`d, d'   |  j: j d(  D }	 n	 d- g }	 |  j; d  k r|  j< |  j7 d. |  j8 d/ |	 |  _; n  t= |  j8 t j-  |  _> |  j? d  k	 rt@ |  j? tA  r|  j? j   |  _? qn	 g  |  _? |  jB r |  j; jC |  j8 t j-  n  |  j% s?|  j; jD |  j?  n  |  j& d  d9  t@ |  jE tF  sy> tF |  jE  |  _E d |  jE k od k n stG  n  WqtG k
 rt d1   YqXn  |  j5 r|  jH rtI d2   n  |  jJ stI d3   n  g  |  _K d  S):Nzsetuptools %s
setuptoolsr   r   exec_prefix	dist_namedist_versiondist_fullname
py_versionrA   py_version_short   py_version_nodot
sys_prefixsys_exec_prefixabiflags userbaseusersitez$User base directory is not specifiedposix	unix_user_userdebz"unknown value for --install-layout	MULTIARCHr   r   r   r   Fr   r   z/usrzinstallation into /usr

Trying to install into the system managed parts of the file system. Please
consider to install to another location, or use the option
--force-installation-into-system-dir to overwrite this warning.
installr   c             S   s(   g  |  ] } t  j j | j     q Sr8   )r;   r<   
expanduserstrip).0rB   r8   r8   r9   
<listcomp>-  s   	 z1easy_install.finalize_options.<locals>.<listcomp>,z"%s (in --site-dirs) does not existz$ (in --site-dirs) is not on sys.pathzhttps://pypi.python.org/simplec             S   s   g  |  ] } | j     q Sr8   )r   )r   rB   r8   r8   r9   r   @  s   	 *search_pathhostsr   z--optimize must be 0, 1, or 2z9Must specify a build directory (-b) when using --editablez:No urls, filenames, or requirements specified (see --help))zdeb)rA   rA   )install_dirr   )r   z
script_dir)recordr   )optimizer   )Lr~   printr"   sysexitsplitr	   r   get_nameget_versionget_fullnamegetattrconfig_varsr   r   r   r   r   create_home_pathr   r   r   r;   nameselect_schemeexpand_basedirsexpand_dirsr   lowerr   	sysconfigversion_infoget_config_varr   _expandr   r   r   set_undefined_optionsr   r   r   r   mapr   r<   get_site_dirsall_site_dirsr   r   r   warnappendrr   check_site_dirr   shadow_pathinsertr   r   create_indexr$   local_indexr   
isinstancer   r   Zscan_egg_linksadd_find_linksr   int
ValueErrorr   r   r   outputs)
r   r   r   r   r   r?   r   rT   	path_itemr   r8   r8   r9   finalize_options   s    		


				 "	!			 	zeasy_install.finalize_optionsc             C   s   x | D]y } t  |  |  } | d  k	 r t j d k sF t j d k r[ t j j |  } n  t | |  j  } t |  | |  q q Wd  S)Nr   nt)r   r;   r   r<   r   r   r   setattr)r   attrsattrvalr8   r8   r9   _expand_attrsd  s    zeasy_install._expand_attrsc             C   s   |  j  d d d g  d S)zNCalls `os.path.expanduser` on install_base, install_platbase and
        root.r   r   r   N)r  )r   r8   r8   r9   r   m  s    zeasy_install.expand_basedirsc             C   s#   |  j  d d d d d d g  d S)z+Calls `os.path.expanduser` on install dirs.r   r   r   r   r   r   N)r  )r   r8   r8   r9   r   r  s    zeasy_install.expand_dirsc             C   s  |  j  |  j j  k r( t j |  j   n  z x% |  j D] } |  j | |  j  q5 W|  j r |  j } |  j	 r t
 |  j	  } x5 t t
 |   D] } | | | d   | | <q Wn  d d l m } |  j | j |  j | f d |  j  n  |  j   Wd  t j |  j j   Xd  S)Nr   )	file_utilz'writing list of installed files to '%s')r   r   r   set_verbosityr   r/   r   r   r  r   lenrange	distutilsr  execute
write_filewarn_deprecated_options)r   specr  root_lencounterr  r8   r8   r9   runx  s$    			zeasy_install.runc          
   C   sG   y t  j   } Wn t j d t  } Yn Xt  j j |  j d |  S)zReturn a pseudo-tempname base in the install directory.
        This code is intentionally naive; if a malicious party can write to
        the target directory you're already in deep doodoo.
        r   ztest-easy-install-%s)r;   getpidrandomrandintr   r<   joinr   )r   pidr8   r8   r9   pseudo_tempname  s
    zeasy_install.pseudo_tempnamec             C   s   d  S)Nr8   )r   r8   r8   r9   r    s    z$easy_install.warn_deprecated_optionsc             C   s  t  |  j  } t j j | d  } | |  j k } | rS |  j rS |  j   } n |  j   d } t j j	 |  } y: | r t j
 |  n  t | d  j   t j
 |  Wn" t t f k
 r |  j   Yn X| r |  j r t |  j     n  | r*|  j d k r3t | |  j  |  _ q3n	 d |  _ t j j d d  j t j  } | t t  d d   | D  k rd	 |  _ n1 |  j rt j j	 |  rd	 |  _ d |  _ n  | |  _ d S)
z;Verify that self.install_dir is .pth-capable dir, if neededzeasy-install.pthz.write-testwN
PYTHONPATHr   c             S   s   g  |  ] } | r |  q Sr8   r8   )r   _fr8   r8   r9   r     s   	 z/easy_install.check_site_dir.<locals>.<listcomp>T)r   r   r;   r<   r  r   r   check_pth_processingr!  r=   r   opencloseOSErrorIOErrorcant_write_to_targetr   no_default_version_msgr   r0   environgetr   pathsepr   r   )r   instdirr   Zis_site_dirZtestfileZtest_existsr#  r8   r8   r9   r     s6     	!"	zeasy_install.check_site_dirc             C   s_   d } | t  j   d |  j f } t j j |  j  sE | d 7} n
 | d 7} t |   d  S)Na  can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    %s

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    %s
   z
This directory does not currently exist.  Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).
aK  
Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  https://pythonhosted.org/setuptools/easy_install.html

Please make the appropriate changes for your system and try again.
)r   exc_infor   r;   r<   r=   r   )r   templatemsgr8   r8   r9   r*    s    
z!easy_install.cant_write_to_targetc             C   s.  |  j  } t j d |  |  j   d } | d } t j j |  } y] | r^ t j |  n  t j j |  } t j j |  s t j	 |  n  t
 | d  } Wn" t t f k
 r |  j   YnHXz | j d | f  | j   d } t j } t j d k rct j j |  \ } } t j j | d  }	 | j   d	 k rct j j |	  rc|	 } qcn  d
 d l m }
 |
 | d d d g d
  t j j |  rt j d |  d SWd | r| j   n  t j j |  rt j |  n  t j j |  rt j |  n  X|  j s*t j d |  n  d S)z@Empirically verify whether .pth files are supported in inst. dirz Checking .pth file support in %sz.pthz.okr"  z7import os; f = open(%r, 'w'); f.write('OK'); f.close()
Nr
  zpythonw.exez
python.exer   )spawnz-Ez-cpassz-TEST PASSED: %s appears to support .pth filesTz+TEST FAILED: %s does NOT support .pth filesF)r   r   r   r!  r;   r<   r=   r   dirnamemakedirsr&  r(  r)  r*  writer'  r   
executabler   r   r  r   distutils.spawnr4  r   r   )r   r/  r   Zok_fileZ	ok_existsr6  rb   r9  basenameZaltr4  r8   r8   r9   r%    sP    	
 
	$	z!easy_install.check_pth_processingc             C   s   |  j  ro | j d  ro xS | j d  D]? } | j d |  rH q) n  |  j | | | j d |   q) Wn  |  j |  d S)z=Write all the scripts for `dist`, unless scripts are excludedscriptszscripts/N)r   metadata_isdirmetadata_listdirinstall_scriptget_metadatainstall_wrapper_scripts)r   distscript_namer8   r8   r9   install_egg_scripts  s    z easy_install.install_egg_scriptsc             C   s|   t  j j |  rh xc t  j |  D]? \ } } } x- | D]% } |  j j t  j j | |   q8 Wq" Wn |  j j |  d  S)N)r;   r<   r   walkr  r   r  )r   r<   basedirsfilesr   r8   r8   r9   
add_output+  s
    *zeasy_install.add_outputc             C   s#   |  j  r t d | f   n  d  S)NzjInvalid argument %r: you can't use filenames or URLs with --editable (except via the --find-links option).)rr   r   )r   r  r8   r8   r9   not_editable3  s    	zeasy_install.not_editablec             C   sW   |  j  s d  St j j t j j |  j | j   rS t d | j |  j f   n  d  S)Nz2%r already exists in %s; can't do a checkout there)rr   r;   r<   r=   r  r   keyr   )r   r  r8   r8   r9   check_editable;  s    	'zeasy_install.check_editableFc             C   s  t  j d d  } d  } |  j s. |  j   n  zYt | t  s t |  r |  j |  |  j j	 | |  } |  j
 d  | | | d  St j j |  r |  j |  |  j
 d  | | | d  St |  } n  |  j |  |  j j | | |  j |  j |  j |  j  } | d  k rDd | } |  j r5| d 7} n  t |   nB | j t k rm|  j | | | d  | S|  j
 | | j | |  SWd  t j j |  rt |  n  Xd  S)Nr   zeasy_install-Tz+Could not find suitable distribution for %rz2 (--always-copy skips system and development eggs)Using)tempfilemkdtemprr   install_site_pyr  r%   r   rJ  r   downloadinstall_itemr;   r<   r=   parse_requirement_argrL  Zfetch_distributionrP   r   r  r   
precedencer,   process_distributionlocationr   )r   r  depstmpdirrQ  rB  r3  r8   r8   r9   r/   E  s:    	 	
	zeasy_install.easy_installc             C   s  | p |  j  } | p* t j j |  | k } | p@ | j d  } | p| |  j d  k	 o| t j j t |   t |  j  k } | r | r x4 |  j | j D] } | j	 | k r Pq q Wd } n  t
 j d t j j |   | r!|  j | | |  } xP | D] } |  j | | |  qWn, |  j |  g } |  j | | d | d  | d  k	 r}x! | D] } | | k r`| Sq`Wn  d  S)Nz.eggTzProcessing %sr   rM  )r   r;   r<   r6  endswithr   r   r  project_namerV  r   r   r;  install_eggsrU  egg_distribution)r   r  rQ  rX  rW  install_neededrB  distsr8   r8   r9   rR  n  s.    	zeasy_install.install_itemc             C   sU   t  | } xD t D]< } d | } t |  |  d k r t |  | | |  q q Wd S)z=Sets the install directories by applying the install schemes.install_N)r   r   r   r  )r   r   schemerK  attrnamer8   r8   r9   r     s
    

zeasy_install.select_schemec             G   s6  |  j  |  |  j j |  |  j j |  |  j |  | |  j | j <t j |  j	 | | |   | j
 d  r |  j r |  j j | j d   n  | r |  j r d  S| d  k	 r | j | j k r t j d |  d  S| d  k s | | k r0| j   } | p| } t | j | j | j  } n  t j d |  y( t g   j | g |  j |  j  } Wni t k
 rt j   d } t d | j   Yn5 t k
 rt j   d } t d | j   Yn X|  j s|  j r"x9 | D]. } | j |  j k r|  j | j    qqWn  t j d |  d  S)Nzdependency_links.txtzSkipping dependencies for %szProcessing dependencies for %sr0  z'Could not find required distribution %sz7Installed distribution %s conflicts with requirement %sz'Finished processing dependencies for %s)
update_pthr   addr  rD  r   rK  r   r   installation_reporthas_metadatar   r  get_metadata_linesr   r   as_requirementr%   rZ  specsextrasr)   resolver/   r*   r   r1  r   r   r+   r   )r   requirementrB  rW  r   ZdistreqZdistrosrs   r8   r8   r9   rU    sL    
	z!easy_install.process_distributionc             C   sA   |  j  d  k	 r |  j  S| j d  r* d S| j d  s= d Sd S)Nznot-zip-safeTzzip-safeF)r   re  )r   rB  r8   r8   r9   should_unzip  s    zeasy_install.should_unzipc             C   s  t  j j |  j | j  } t  j j |  rS d } t j | | j |  j |  | St  j j |  rn | } n t  j j	 |  | k r t  j
 |  n  t  j |  } t |  d k r t  j j | | d  } t  j j |  r | } q n  t |  t j | |  | S)Nz<%r already exists in %s; build directory %s will not be keptr0  r   )r;   r<   r  r   rK  r=   r   r   r   r6  r   listdirr  r!   shutilmove)r   r  dist_filename
setup_basedstr3  contentsr8   r8   r9   
maybe_move  s"    	
zeasy_install.maybe_movec             C   s4   |  j  s0 x$ t |  D] } |  j |   q Wn  d  S)N)r   get_script_argswrite_script)r   rB  r   r8   r8   r9   rA    s    	z$easy_install.install_wrapper_scriptsc                s   t  | j    } t | |  }   f d d   } | rz d   | rZ   j d d    n  t |  |    t   } n  |  j | t |  d  d S)z/Generate a legacy script wrapper and install itc                s4   t  d    } | j d  } | j d d  } | S)am  
            There are a couple of template scripts in the package. This
            function loads one of them and prepares it for use.

            These templates use triple-quotes to escape variable
            substitutions so the scripts get the 2to3 treatment when build
            on Python 3. The templates cannot use triple-quotes naturally.
            r   zutf-8z"""r   )r    decodereplace)r   Z	raw_bytesZtemplate_strZclean_template)template_namer8   r9   get_template  s    	z1easy_install.install_script.<locals>.get_templatezscript template.pyz.pyz	 (dev).pyre   N)strrg  is_python_scriptrx  get_script_headerlocalsrv  rC   )r   rB  rC  script_textZdev_pathr  Z	is_scriptrz  r8   )ry  r9   r?    s    	zeasy_install.install_scripttc                s     j    f d d   | D  t j d |   j  t j j   j |  }   j |  t   }   j	 s t
 |  t j j |  r t j |  n  t | d |  } | j |  | j   t | d |  n  d S)z1Write an executable file to the scripts directoryc                s(   g  |  ] } t  j j   j |   q Sr8   )r;   r<   r  r   )r   rY   )r   r8   r9   r     s   	 z-easy_install.write_script.<locals>.<listcomp>zInstalling %s script to %sr"  i  N)r   r   r   r   r;   r<   r  rI  current_umaskr   r!   r=   r   r&  r8  r'  chmod)r   rC  rs  moder   targetmaskrb   r8   )r   r9   rv  
  s    		

zeasy_install.write_scriptc             C   s  | j    j d  r( |  j | |  g S| j    j d  rP |  j | |  g S| } t j j |  r | j d  r t | | |  j  n' t j j	 |  r t j j
 |  } n  | j |  r |  j r | d  k	 r |  j | | |  } n  t j j | d  } t j j |  st t j j | d d   } | s[t d t j j
 |    n  t |  d k rt d t j j
 |    n  | d	 } n  |  j rt j |  j | |   g  S|  j | |  Sd  S)
Nz.eggz.exez.pyzsetup.pyr   z"Couldn't find a setup script in %sr0  zMultiple setup scripts in %sr   )r   rY  install_egginstall_exer;   r<   isfiler   unpack_progressr   r   r   r   rt  r  r=   r   r   r  rr   r   r   report_editablebuild_and_install)r   r  rp  rX  rq  setup_scriptZsetupsr8   r8   r9   r[    s4    "	zeasy_install.install_eggsc             C   s[   t  j j |  r3 t | t  j j | d   } n t t j |   } t j	 | d | S)NzEGG-INFOmetadata)
r;   r<   r   r'   r  r(   	zipimportzipimporterr&   from_filename)r   egg_pathr  r8   r8   r9   r\  D  s    !zeasy_install.egg_distributionc             C   s  t  j j |  j t  j j |   } t  j j |  } |  j sL t |  n  |  j |  } t	 | |  st  j j
 |  r t  j j |  r t j | d |  j n2 t  j j |  r |  j t  j | f d |  n  t |  t  j j
 |  r+| j |  rt j d } } qt j d } } na |  j |  rZ|  j |  |  j d } } n2 | j |  r|t j d } } n t j d } } |  j | | | f | d t  j j |  t  j j |  f  n  |  j |  |  j |  S)Nr   z	Removing ZMovingZCopyingZ
Extractingz	 %s to %s)r;   r<   r  r   r;  r   r   r!   r\  r.   r   r   r   remove_treer=   r  r   uncache_zipdirr   rn  ro  copytreerl  mkpathunpack_and_compilecopy2r6  rI  )r   r  rX  destinationrB  rb   rN   r8   r8   r9   r  K  s4    $	% 
)zeasy_install.install_eggc                s  t  |  } | d  k r+ t d |   n  t d  d | j d d  d | j d d  d t   } t j j | | j   d  } | _	 | d } t j j | d	  } t j j | d
  } t
 |  t | |  | _ |  j | |  t j j |  s}t | d  }	 |	 j d  xU | j d  D]D \ }
 } |
 d k r(|	 j d |
 j d d  j   | f  q(q(W|	 j   n  t j j | d    |  j   f d d   t |  D  t j | | d |  j d |  j |  j | |  S)Nz(%s is not a valid distutils Windows .exerZ  r  r   r~   platformz.eggz.tmpzEGG-INFOzPKG-INFOr"  zMetadata-Version: 1.0
target_versionz%s: %s
_-r<  c                s)   g  |  ] } t  j j   | d    q S)r   )r;   r<   r  )r   r   )r   r8   r9   r     s   	 z,easy_install.install_exe.<locals>.<listcomp>r   r   )r1   r   r&   r-  r
   r;   r<   r  egg_namerV  r!   r'   	_provider
exe_to_eggr=   r&  r8  itemsrx  titler'  r   ru  r   make_zipfiler   r   r  )r   rp  rX  cfgrB  r  egg_tmpZ	_egg_infoZpkg_infrb   kvr8   )r   r9   r  l  s8    &

0 zeasy_install.install_exec                s  t  |   g   g   i         f d d   } t |   |  g  } x  D] } | j   j d  rY | j d  } | d } t j | d  d | d <t j j	   |  }  j
 |  | j
 |  t j | |  qY qY W|  j   t j t j j	   d  t j   |   x d D] }	 t   |	 r-t j j	   d |	 d
  }
 t j j |
  st |
 d  } | j d j	 t   |	  d  | j   qq-q-Wd S)z;Extract a bdist_wininst to the directories an egg would usec                sR  |  j    } x D]\ } } | j |  r | |  t |  d   }  |  j d  } t j j   |  } | j    } | j d  s | j d  r t j	 | d
  | d <d  t j j
 | d  d < j |   nI | j d  r$| d k r$d  t j j
 | d  d < j |  n  | Sq W|  j d  sNt j d	 |   n  d  S)N/z.pydz.dllr0  r   z.pyzSCRIPTS/z.pthzWARNING: can't process %sr  )r   r   r  r   r;   r<   r  rY  r   strip_modulesplitextr   r   r   )srcrr  rB   oldnewpartsdl)r  native_libsprefixes
to_compile	top_levelr8   r9   process  s$    z(easy_install.exe_to_egg.<locals>.processz.pydr  r0  z.pyzEGG-INFOr  r  z.txtr"  
Nr  r  r  )z	top_levelznative_libs)r3   r   r   rY  r   r   r  r;   r<   r  r   Z
write_stubbyte_compileZwrite_safety_flagZanalyze_eggr~  r=   r&  r8  r'  )r   rp  r  r  Zstubsresr  resourceZpyfiler   Ztxtrb   r8   )r  r  r  r  r  r9   r    s4    
!zeasy_install.exe_to_eggZ	Installedc       	      C   sz   d } |  j  rN |  j rN | d 7} |  j t t t j  k rN | d 7} qN n  | j } | j } | j	 } d } | t
   S)z9Helpful installation message for display to package usersz
%(what)s %(eggloc)s%(extras)sa  

Because this distribution was installed --multi-version, before you can
import modules from this package in an application, you will need to
'import pkg_resources' and then use a 'require()' call similar to one of
these examples, in order to select the desired version:

    pkg_resources.require("%(name)s")  # latest installed version
    pkg_resources.require("%(name)s==%(version)s")  # this exact version
    pkg_resources.require("%(name)s>=%(version)s")  # this version or higher
z

Note also that the installation directory must be on sys.path at runtime for
this to work.  (e.g. by being the application's script directory, by being on
PYTHONPATH, or by being added to sys.path by your code.)
r   )r   r   r   r   r   r   r<   rV  rZ  r~   r~  )	r   reqrB  whatr3  Zegglocr   r~   ri  r8   r8   r9   rd    s    
			z easy_install.installation_reportc             C   s&   t  j j |  } t j } d t   S)Na"  
Extracted editable version of %(spec)s to %(dirname)s

If it uses setuptools in its setup script, you can activate it in
"development" mode by going to that directory and running::

    %(python)s setup.py develop

See the setuptools documentation for the "develop" command for more info.
)r;   r<   r6  r   r9  r~  )r   r  r  r6  pythonr8   r8   r9   r    s    		zeasy_install.report_editablec             C   s+  t  j j d t  t  j j d t  t |  } |  j d k ri d |  j d } | j d d |  n" |  j d k  r | j d d  n  |  j r | j d d	  n  t	 j
 d
 | t |  d d   d j |   y t | |  Wn< t k
 r&t  j   d } t d | j d f   Yn Xd  S)Nzdistutils.command.bdist_eggzdistutils.command.egg_infor   r  r0  r   r  z-qz-nzRunning %s %s zSetup script exited with %s)r   modules
setdefaultr   r   listr   r   r   r   r   r  r  r   
SystemExitr1  r   r   )r   r  rq  r   r  r8   r8   r9   r     s"    	*zeasy_install.run_setupc       	      C   s  d d g } t  j d d d t j j |   } z |  j t j j |   | j |  |  j | | |  t | g  } g  } x? | D]7 } x. | | D]" } | j |  j	 | j
 |   q Wq W| r |  j r t j d |  n  | SWd  t |  t j |  j  Xd  S)Nr   z
--dist-dirr   zegg-dist-tmp-dirz+No eggs found in %s (setup script problem?))rN  rO  r;   r<   r6  _set_fetcher_optionsr   r   r$   r  rV  r   r   r   r   r  r   )	r   r  rq  r   Zdist_dirZall_eggseggsrK  rB  r8   r8   r9   r    s$    	$	

zeasy_install.build_and_installc       	      C   s   |  j  j d  j   } d } i  } xF | j   D]8 \ } } | | k rO q1 n  | d | | j d d	  <q1 Wt d |  } t j j | d
  } t	 j
 | |  d S)a  
        When easy_install is about to run bdist_egg on a source dist, that
        source dist might have 'setup_requires' directives, requiring
        additional fetching. Ensure the fetcher options given to easy_install
        are available to that command as well.
        r/   r   r   r   r   r   r0  r  r  z	setup.cfgN)z
find_links	site_dirsz	index_urlzoptimizer  zallow_hosts)r   r   copyr  rx  dictr;   r<   r  r   Zedit_config)	r   rF  Zei_optsZfetch_directivesZfetch_optionsrK  r  ZsettingsZcfg_filenamer8   r8   r9   r    s    	  z!easy_install._set_fetcher_optionsc             C   s  |  j  d  k r d  Sx~ |  j  | j D]l } |  j sE | j | j k r$ t j d |  |  j  j |  | j |  j k r |  j j | j  q q$ q$ W|  j s| j |  j  j k r t j d |  qt j d |  |  j  j	 |  | j |  j k r|  j j
 | j  qn  |  j s|  j  j   | j d k rt j j |  j d  } t j j |  rot j |  n  t | d  } | j |  j  j | j  d  | j   qn  d  S)Nz&Removing %s from easy-install.pth filez4%s is already the active version in easy-install.pthz"Adding %s to easy-install.pth filer   zsetuptools.pthwtr  )r   rK  r   rV  r   r   remover   pathsrc  r   r   saver;   r<   r  r   r   r   r&  r8  make_relativer'  )r   rB  rT   r   rb   r8   r8   r9   rb  5  s4    	
	  zeasy_install.update_pthc             C   s   t  j d | |  | S)NzUnpacking %s to %s)r   debug)r   r  rr  r8   r8   r9   r  Y  s    zeasy_install.unpack_progressc                s   g   g       f d d   } t  | | |    j     j s x<  D]1 } t j |  t j d Bd @} t | |  qQ Wn  d  S)Nc                s   | j  d  r/ |  j d  r/  j |  n. | j  d  sM | j  d  r]  j |  n    j |  |    j r} | p d  S)Nz.pyz	EGG-INFO/z.dllz.so)rY  r   r   r  r   )r  rr  )r   to_chmodr  r8   r9   pfb  s    z+easy_install.unpack_and_compile.<locals>.pfim  i  )r   r  r   r;   statST_MODEr  )r   r  r  r  rb   r  r8   )r   r  r  r9   r  ^  s    	zeasy_install.unpack_and_compilec             C   s   t  r |  j d  d  Sd d l m } ze t j |  j d  | | d d d d d |  j |  j r | | d |  j d d d |  j n  Wd  t j |  j  Xd  S)Nz%byte-compiling is disabled, skipping.r   )r  r0  r   forcer   )	r   r   distutils.utilr  r   r  r   r   r   )r   r  r  r8   r8   r9   r  q  s    	zeasy_install.byte_compilec             C   s&   d } | |  j  t j j d d  f S)Na  bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    %s

and your PYTHONPATH environment variable currently contains:

    %r

Here are some of your options for correcting the problem:

* You can choose a different installation directory, i.e., one that is
  on PYTHONPATH or supports .pth files

* You can add the installation directory to the PYTHONPATH environment
  variable.  (It must then also be on PYTHONPATH whenever you run
  Python and want to use the package(s) you are installing.)

* You can set up the installation directory to support ".pth" files by
  using one of the approaches described here:

  https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations

Please make the appropriate changes for your system and try again.r#  r   )r   r;   r,  r-  )r   r2  r8   r8   r9   r+    s    z#easy_install.no_default_version_msgc             C   s?  |  j  r d St j j |  j d  } t d d  } d } t j j |  r t j d |  j  t	 | d  } | j
   } t j d k r | j   } n  | j   | j d	  s t d
 |   q n  | | k r2t j d |  |  j st |  t	 | d  } | j |  | j   n  |  j | g  n  d |  _  d S)z8Make sure there's a site.py in the target dir, if neededNzsite.pyr   zsite-patch.pyr   zChecking existing site.py in %srbrA   zdef __boot():z;%s is not a setuptools-generated site.py; please remove it.zCreating %swbT)rA   )r   r;   r<   r  r   r    r=   r   r  r&  readr   r   rw  r'  r   r   r   r   r!   r8  r  )r   Zsitepysourcecurrentrb   r8   r8   r9   rP    s2    	
	
zeasy_install.install_site_pyc             C   s   |  j  s d St t j j d   } xc t |  j  D]R \ } } | j |  r5 t j j |  r5 |  j	 d |  t j
 | d  q5 q5 Wd S)zCreate directories under ~.N~zos.makedirs('%s', 0700)i  )r   r   r;   r<   r   r   r   r   r   debug_printr7  )r   homer   r<   r8   r8   r9   r     s    	"zeasy_install.create_home_pathrA   2.32.42.5real_prefixzsite-packageszdist-packagesr   r   z/$base/lib/python$py_version_short/site-packagesr   z	$base/bin
unix_localz*$base/local/lib/python$py_version_short/%sz$base/local/binposix_local
deb_systemz$base/lib/python3/%sz$base/Lib/site-packagesz$base/Scriptsc             G   s  |  j  d  j } |  j s$ |  j r |  j rT |  j j   d k rT d } d |  _ n* |  j sl d t j k rx t j } n d } | j	   } |  j | d <|  j
 j | |  j  } xH | j   D]7 \ } } t |  | d   d  k r t |  | |  q q Wn  d d	 l m } xo | D]g } t |  |  } | d  k	 r| | |  } t j d
 k ret j j |  } n  t |  | |  qqWd  S)Nr   r   r  z/usrr  r  rF  r   )r   r   )zdeb)get_finalized_commandr   r   r   r   r   __dict__r;   r   r  r   r-  DEFAULT_SCHEMEr  r   r  r  r   r<   r   )r   r  r   Zscheme_namer`  r  r  r   r8   r8   r9   r     s,    zeasy_install._expand)rH   NrI   )rJ   rK   rL   )rM   rN   rO   )zupgraderQ   rR   )rS   rT   rU   )rV   rB   rW   )rX   rY   rZ   )r[   r\   r]   )r^   r_   r`   )ra   rb   rc   )rd   re   rf   )rg   rh   ri   )rj   Nrk   )rl   rm   rn   )ro   rp   rq   )zeditablers   rt   )ru   rv   rw   )rx   ry   rz   )r{   r|   r}   )zversionNr   )r   Nr   )r   r   r   )r   Nr   )r  r  r  )B__name__
__module____qualname____doc__descriptionZcommand_consumes_argumentsuser_optionsboolean_optionsr   r   r   Zhelp_msgr   negative_optr   r  r   r   r	  r  r   r   r  r!  r  r   r*  r%  rD  rI  rJ  rL  r/   rR  r   rU  rl  rt  rA  r?  rv  r[  r\  r  r  r  rd  r  r   r  r  rb  r  r  r  r+  rP  r   r   r~   r  Zsitedir_namer  r   r  r   r8   r8   r8   r9   r/   _   s        		8
	*'0
)$	/	(!*2$$
(		
	
	
	c           
   C   sv  d d   t  j j d d  j t  j  D }  t j g } t j t j k r_ | j t j  n  x| D]} | rf t j	 d k r |  j t  j
 j | d d   n t  j d	 k r |  j t  j
 j | d
 d t j d  d  d  t  j
 j | d
 d  g  n t j d  d  d k r"d } n d } |  j t  j
 j | d d t j d  d  |  t  j
 j | d
 d t j d  d  |  g  t j	 d k rd | k rt  j j d  } | r|  j t  j
 j | d d t j d  d  d   qqqqf qf Wt d  t d  f } x* | D]" } | |  k r|  j |  qqWt j r]|  j t j  n  t t t |    }  |  S)Nc             S   s   g  |  ] } | r |  q Sr8   r8   )r   r$  r8   r8   r9   r     s   	 z!get_site_dirs.<locals>.<listcomp>r#  r   os2emxriscosLibzsite-packagesr  libr  rA   zsite-python2.32.42.5zdist-packagesz	local/libdarwinzPython.frameworkHOMELibraryPythonpurelibplatlib)r  r  )r  r  r  )r;   r,  r-  r   r.  r   r   r   r   r  r<   r  sepextendr~   r   r   r   r   r  r   r   )sitedirsr  r   Zsdirr  Z	lib_pathsZsite_libr8   r8   r9   r   
  sN    "	)0 	r   c             c   s^  i  } xQ|  D]I} t  |  } | | k r1 q n  d | | <t j j |  sS q n  t j |  } | | f Vx | D] } | j d  s qt n  | d k r qt n  t t j j | |   } t t	 |   } | j
   xw | D]o } | j d  s t  | j    } | | k rNd | | <t j j |  s4q n  | t j |  f VqNq q Wqt Wq Wd S)zBYield sys.path directories that might contain "old-style" packagesr0  z.ptheasy-install.pthsetuptools.pthimportN)r  r  )r   r;   r<   r   rm  rY  r&  r  r  r   r'  r   rstrip)inputsseenr6  rH  r   rb   linesliner8   r8   r9   expand_paths=  s4    


r  c             C   s  t  |  d  } zt j |  } | d k r1 d S| d | d | d } | d k  r[ d S| j | d  d d l m } m } d d l } | j d	 | j	 d   \ } } }	 | d k r d S| j | d |  | j
 i d d 6d d 6 }
 y~ | j	 |  } t j d k r't d g  } n t d  } | j | d  d } | j t j    } |
 j | |   Wn | j k
 rd SYn X|
 j d  s|
 j d  rd S|
 SWd | j   Xd S)znExtract configuration data from a bdist_wininst .exe

    Returns a ConfigParser.RawConfigParser, or None
    r  N	            r   )StringIOConfigParserz<iiizV4{V4r   r~   r  r   r0  r  ZSetup)r  r  )r   r  )r&  zipfile_EndRecDataseeksetuptools.compatr
  r  r6   unpackr  RawConfigParserr   r   byteschrr   rw  getfilesystemencodingreadfpErrorhas_sectionr'  )rp  rb   endrecZ	prependedr
  r  r6   tagZcfglenZbmlenr  part	null_byteconfigr8   r8   r9   r1   f  s<    $	 c             C   s  d d d d d g } t  j |   } z}xv| j   D]h} | j } | j d  } t |  d	 k r | d
 d k r | d j d  r | j d d j | d d
   d f  Pq n  t |  d
 k s4 | j d  r q4 n  | j d  r q4 n  | d j	   d k r4 | j
 |  } t j d  k r7| j   } n  xb t |  D]Q } | j   j d d  } | j d  sD| j d | d | f d f  qDqDWq4 q4 WWd | j   Xd d   | D } | j   | j   | S)!z4Get exe->egg path translations for a given .exe filePURELIB/r   PLATLIB/pywin32_system32PLATLIB/SCRIPTS/EGG-INFO/scripts/DATA/lib/site-packagesr  rA   r   zPKG-INFOr0  z	.egg-infor   Nz	EGG-INFO/z.pthz
-nspkg.pthPURELIBPLATLIB\r  z%s/%s/c             S   s(   g  |  ] \ } } | j    | f  q Sr8   )r   )r   rY   yr8   r8   r9   r     s   	 z$get_exe_prefixes.<locals>.<listcomp>)r  r   )r   r   )r!  r   )r"  r#  )r$  r   )r%  r&  )rA   )r  ZipFileinfolistr   r   r  rY  r   r  upperr  r   r   rw  r   r   rx  r   r   r'  sortreverse)Zexe_filenamer  rK   r   r   r  rs  pthr8   r8   r9   r3     s<    		")"3

c             C   s=   y t  j |   SWn% t k
 r8 t d |  f   Yn Xd  S)Nz1Not a URL, existing file, or requirement spec: %r)r%   parser  r   )r  r8   r8   r9   rS    s
    rS  c               @   sg   e  Z d  Z d Z d Z f  d d  Z d d   Z d d   Z d	 d
   Z d d   Z	 d d   Z
 d S)r0   z)A .pth file with Distribution paths in itFc             C   s   | |  _  t t t |   |  _ t t j j |  j    |  _ |  j	   t
 j |  g  d  d   x6 t |  j  D]% } t t |  j t | d    qo Wd  S)NT)r   r  r   r   r  r;   r<   r6  basedir_loadr$   __init__r   r  rc  r#   )r   r   r  r<   r8   r8   r9   r2    s    	
zPthDistributions.__init__c             C   s  g  |  _  d } t j |  j  } t j j |  j  r3t |  j d  } x | D] } | j	 d  rp d } qO n  | j
   } |  j  j |  | j   sO | j   j	 d  r qO n  t t j j |  j |   } |  j  d <t j j |  s | | k r|  j  j   d |  _ qO n  d | | <qO W| j   n  |  j  rO| rOd |  _ n  x. |  j  r|  j  d j   r|  j  j   qRWd  S)	NFrtr  T#r0  r  r  )r  r  fromkeysr  r;   r<   r  r   r&  r   r   r   r   r   r  r0  r=   popdirtyr'  )r   Z
saw_importr  rb   r  r<   r8   r8   r9   r1    s2    	"&	 zPthDistributions._loadc             C   s   |  j  s d Sd j t |  j |  j   } | r t j d |  j  d | } t j	 j
 |  j  rv t j |  j  n  t |  j d  } | j |  | j   n; t j	 j |  j  r t j d |  j  t j |  j  n  d |  _  d S)z$Write changed .pth file back to diskNr  z	Saving %szimport sys; sys.__plen = len(sys.path)
%s
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)
r  zDeleting empty %sF)r7  r  r   r  r  r   r  r   r;   r<   r   r   r&  r8  r'  r=   )r   datarb   r8   r8   r9   r    s     	zPthDistributions.savec             C   sl   | j  |  j k rX | j  |  j k s9 | j  t j   k rX |  j j | j   d |  _ n  t j |  |  d S)z"Add `dist` to the distribution mapTN)	rV  r  r  r;   getcwdr   r7  r$   rc  )r   rB  r8   r8   r9   rc    s    zPthDistributions.addc             C   sI   x2 | j  |  j k r4 |  j j | j   d |  _ q Wt j |  |  d S)z'Remove `dist` from the distribution mapTN)rV  r  r  r7  r$   )r   rB  r8   r8   r9   r    s    zPthDistributions.removec             C   s   t  j j t |   \ } } t |  j  } | g } t  j d k rK d pQ t  j } xu t |  | k r | |  j k r | j t  j	  | j
   | j |  St  j j |  \ } } | j |  qW W| Sd  S)Nr  )r;   r<   r   r   r  r0  altsepr  r   curdirr-  r  )r   r<   npathlastZbaselenr  r  r8   r8   r9   r    s    	
zPthDistributions.make_relativeN)r  r  r  r  r7  r2  r1  r  rc  r  r  r8   r8   r8   r9   r0     s   	
Fc             C   s/  d d l  m } t | j t  s= t j | j j    } n  |  d j   d } | j	 |  } d } | r | j
 d  p~ d } | r d | } q n  | r d } n t |  } d t   } t |  s| r| j   j d	  rd
 | j   d d  } qqd
 } n  t | |  } d t   } | S)z;Create a #! line, getting options (if any) from script_textr   )first_line_rer  r   r0  r  z
python.exez#!%(executable)s%(options)s
r  z -xN)Zdistutils.command.build_scriptsr>  r  patternr{  recompilerw  
splitlinesmatchgroupnt_quote_argr~  rF   r   r   fix_jython_executable)r  r9  wininstr>  firstrC  optionshdrr8   r8   r9   r}  -  s,     	 	r}  c             C   sz   |  t  j k r8 t  j d k r8 t | t j  |  |  St j   \ } } } t | | d | d d |  | f f  d  S)Nr
  r   r0  z %s %s)	r;   r  r   r  r  S_IWRITEr   r1  r   )funcargexcetevr  r8   r8   r9   
auto_chmodL  s
    
rQ  c             C   s1   d d l  m } t |  |  t |  t j  d S)z?Ensure that the importer caches dont have stale info for `path`r   )_zip_directory_cacheN)r  rR  _uncacher   path_importer_cache)r<   Zzdcr8   r8   r9   r  S  s    r  c             C   sT   |  | k r | |  =n: t  |   }  x+ | D]# } t  |  |  k r) | | =d  Sq) Wd  S)N)r   )r<   cachepr8   r8   r9   rS  Y  s    
rS  z<string>c             C   s;   y t  |  | d  Wn t t f k
 r2 d SYn Xd Sd S)z%Is this string a valid Python script?execFTN)rA  SyntaxError	TypeError)textr   r8   r8   r9   	is_pythonc  s
    	r[  c             C   sR   y) t  |   } | j d  } | j   Wn t t f k
 rG |  SYn X| d k S)zCDetermine if the specified executable is a .sh (contains a #! line)r   z#!)r&  r  r'  r(  r)  )r9  fpmagicr8   r8   r9   is_shl  s     	r^  c             C   s  g  } d } d } d |  k p' d |  k } | r@ | j  d  n  x |  D]z } | d k rf | d 7} qG | d k r | j  d | d d	  d } qG | r | j  d |  d } n  | j  |  qG W| r | j  d |  n  | r| j  d |  | j  d  n  d
 j |  S)z@Quote a command line argument according to Windows parsing rulesFr   r  	"r'  r0  r   z\"r   )r   r  )rM  result	needquotenbcr8   r8   r9   rE  u  s,    		rE  c             C   sb   | j  d  s | j  d  r" d St |  |  r5 d S|  j d  r^ d |  j   d j   k Sd S)zMIs this text, as a whole, a Python script? (as opposed to shell/bat/etc.
    z.pyz.pywTz#!r  r   F)rY  r[  r   rB  r   )r  r   r8   r8   r9   r|    s    r|  )r  c              G   s   d  S)Nr8   )r   r8   r8   r9   _chmod  s    re  c             C   s`   t  j d |  |  y t |  |  Wn5 t j k
 r[ t j   d } t  j d |  Yn Xd  S)Nzchanging mode of %s to %or0  zchmod failed: %s)r   r  re  r;   errorr   r1  )r<   r  rs   r8   r8   r9   r    s    r  c             C   sn   t  j j d  rj t |   rj d d  l } | j j j d  d k rI |  S| r_ t j	 d  qj d |  Sn  |  S)Njavar   zos.nameLinuxzWARNING: Unable to adapt shebang line for Jython, the following script is NOT executable
         see http://bugs.jython.org/issue1112 for more information.z/usr/bin/env %s)
r   r  r   r^  rg  langSystemgetPropertyr   r   )r9  rI  rg  r8   r8   r9   rF    s    
rF  c               @   sg   e  Z d  Z d Z e j d  j   Z e e	 d d d   Z
 e d d    Z e d d	    Z d
 S)ScriptWriterz`
    Encapsulates behavior around writing entry point scripts for console and
    gui apps.
    a6  
        # EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r
        __requires__ = %(spec)r
        import sys
        from pkg_resources import load_entry_point

        if __name__ == '__main__':
            sys.exit(
                load_entry_point(%(spec)r, %(group)r, %(name)r)()
            )
    Fc             c   s   |  j  |  } t | j    } t d | |  } xv d D]n } | d } x[ | j |  j   D]D \ }	 }
 | j t   } x% | j | |	 | |  D] } | Vq Wq` Wq: Wd S)zW
        Yield write_script() argument tuples for a distribution's entrypoints
        r   consoleguiZ_scriptsN)zconsolezgui)	
get_writerr{  rg  r}  get_entry_mapr  r2  r~  _get_script_args)clsrB  r9  rG  Z	gen_classr  headertype_rD  r   epr  r  r8   r8   r9   ru    s    
"zScriptWriter.get_script_argsc             C   s#   | s t  j d k r t j   S|  S)Nwin32)r   r  WindowsScriptWriterro  )rr  Zforce_windowsr8   r8   r9   ro    s    
zScriptWriter.get_writerc             c   s   | | | f Vd  S)Nr8   )rr  rt  r   rs  r  r8   r8   r9   rq    s    zScriptWriter._get_script_argsN)r  r  r  r  textwrapdedentlstripr2  classmethodsys_executableru  ro  rq  r8   r8   r8   r9   rl    s   
rl  c               @   sF   e  Z d  Z e d d    Z e d d    Z e d d    Z d S)rw  c             C   s2   t  d t d |   } t j j d d  } | | S)z:
        Get a script writer suitable for Windows
        r9  ZnaturalZSETUPTOOLS_LAUNCHER)r  WindowsExecutableLauncherWriterr;   r,  r-  )rr  Zwriter_lookuplauncherr8   r8   r9   ro    s
    	zWindowsScriptWriter.get_writerc             #   s   t  d d d d  | } | t j d j   j d  k rR t j d | t  n  d d d	 d
 d d d g } | j |  |  j	 | |  }   f d d   | D }   | | | d | f Vd S)z For Windows, add a .py extensionrm  z.pyarn  z.pywPATHEXT;zH%s not listed in PATHEXT; scripts will not be recognized as executables.z.pyz
-script.pyz.pycz.pyoz.exec                s   g  |  ] }   |  q Sr8   r8   )r   rY   )r   r8   r9   r     s   	 z8WindowsScriptWriter._get_script_args.<locals>.<listcomp>r  N)
r  r;   r,  r   r   warningsr   UserWarningr  _adjust_header)rr  rt  r   rs  r  extr  r   r8   )r   r9   rq    s    "	z$WindowsScriptWriter._get_script_argsc             C   s   d } d } |  d k r( | | } } n  t  j t  j |  t  j  } | j d | d |  } | d d
  j d  } t j d	 k r t j	 j
 |  r | S| S)z
        Make sure 'pythonw' is used for gui and and 'python' is used for
        console (regardless of what sys.executable is).
        zpythonw.exez
python.exern  stringreplr   r0  r`  rv  r  )r@  rA  escape
IGNORECASEsubr   r   r  r;   r<   r=   )rt  Zorig_headerr?  r  Z
pattern_obZ
new_headerZclean_headerr8   r8   r9   r    s    "z"WindowsScriptWriter._adjust_headerN)r  r  r  r{  ro  rq  staticmethodr  r8   r8   r8   r9   rw    s   rw  c               @   s"   e  Z d  Z e d d    Z d S)r}  c             #   s   | d k r$ d } d } d g } n d } d } d d d g } |  j  | |  }   f d	 d
   | D }	   | | | d |	 f V  d t |  d f Vt   s   d }
 |
 t    d f Vn  d S)zG
        For Windows, add a .py extension and an .exe launcher
        rn  z-script.pywz.pywcliz
-script.pyz.pyz.pycz.pyoc                s   g  |  ] }   |  q Sr8   r8   )r   rY   )r   r8   r9   r   1  s   	 zDWindowsExecutableLauncherWriter._get_script_args.<locals>.<listcomp>r  z.exere   z.exe.manifestN)r  get_win_launcherr:   load_launcher_manifest)rr  rt  r   rs  r  Zlauncher_typer  r  rJ  r   Zm_namer8   )r   r9   rq  #  s    	
z0WindowsExecutableLauncherWriter._get_script_argsN)r  r  r  r{  rq  r8   r8   r8   r9   r}  "  s   r}  c             C   st   d |  } t  j   j   d k r7 | j d d  } n  t   rU | j d d  } n | j d d  } t d |  S)z
    Load the Windows launcher (executable) suitable for launching a script.

    `type` should be either 'cli' or 'gui'

    Returns the executable as a byte string.
    z%s.exearm.z-arm.z-64.z-32.r   )r  machiner   rx  r:   r    )typeZlauncher_fnr8   r8   r9   r  C  s    
	r  c             C   sH   t  j t d  } t j d d k  r0 | t   S| j d  t   Sd  S)Nzlauncher manifest.xmlr   rA   zutf-8)pkg_resourcesr    r  r   r   varsrw  )r   manifestr8   r8   r9   r  T  s    r  c             C   s~  | r d d   } n | d k r0 d d   } n  g  } y t  j |   } Wn. t  j k
 ry | t  j |  t j    Yn Xx | D] } t  j j |  |  } y t  j |  j } Wn t  j k
 r d } Yn Xt	 j
 |  r t | | |  q y t  j |  Wq t  j k
 r3| t  j | t j    Yq Xq Wy t  j |   Wn. t  j k
 ry| t  j |  t j    Yn Xd S)zRecursively delete a directory tree.

    This code is taken from the Python 2.4 version of 'shutil', because
    the 2.3 version doesn't really work right.
    c              W   s   d  S)Nr8   )r   r8   r8   r9   onerrorb  s    zrmtree.<locals>.onerrorNc              W   s     d  S)Nr8   )r   r8   r8   r9   r  e  s    r   )r;   rm  rf  r   r1  r<   r  lstatst_moder  S_ISDIRr   r  rmdir)r<   ignore_errorsr  namesr   fullnamer  r8   r8   r9   r   [  s2    "r   c              C   s    t  j d  }  t  j |   |  S)N   )r;   umask)tmpr8   r8   r9   r  ~  s    r  c              C   sM   d d  l  }  t j j |  j d  } | t j d <t j j |  t   d  S)Nr   )	r   r;   r<   r6  __path__r   argvr   r2   )r   Zargv0r8   r8   r9   	bootstrap  s
    r  c                s   d d l  m  d d l m   d d  l  d   f d d      f d d    G   f d	 d
   d
      d  k r t j d d    n       f d d    d  S)Nr   )setup)r&   zLusage: %(script)s [options] requirement_or_url ...
   or: %(script)s --help
c                s     t  d t j j |    S)Nscript)r  r;   r<   r;  )rC  )USAGEr8   r9   	gen_usage  s    	zmain.<locals>.gen_usagec                s7     j  j } z    j  _ |    SWd  |   j  _ Xd  S)N)corer  )rb   Zold_gen_usage)r  r  r8   r9   with_ei_usage  s
    zmain.<locals>.with_ei_usagec                   s+   e  Z d  Z d Z    f d d   Z d S)z-main.<locals>.DistributionWithoutHelpCommandsr   c                s#         f d d    d  S)Nc                  s     j      S)N)
_show_helpr8   )r&   r   kwr   r8   r9   <lambda>  s    zJmain.<locals>.DistributionWithoutHelpCommands._show_help.<locals>.<lambda>r8   )r   r   r  )r&   r  )r   r  r   r9   r    s    z8main.<locals>.DistributionWithoutHelpCommands._show_helpN)r  r  r  common_usager  r8   )r&   r  r8   r9   DistributionWithoutHelpCommands  s   r  r0  c                  s6    d d d d g  d t  j d p) d d     S)Nscript_argsz-qr/   z-vrC  r   	distclass)r   r  r8   )r  r  r  r  r8   r9   r    s    zmain.<locals>.<lambda>)r   r  Zsetuptools.distr&   distutils.corer   r  )r  r  r8   )	r&   r  r  r  r  r  r  r  r  r9   r2     s    )pr  r   r;   r  rn  rN  r  r@  r  r  r  rx  r  r   r6   r   r  r   r   r  r   r   r   Zsetuptools.sandboxr   Zsetuptools.py31compatr   r	   r  r
   r   r   distutils.errorsr   r   r   r   distutils.command.installr   r   Zsetuptools.commandr   Zsetuptools.archive_utilr   Zsetuptools.package_indexr   r   r   r   r  r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r,  r-  r<   r?   r9  r|  __all__r:   r.   r   rC   rF   r/   r   r  r1   r3   rS  r0   r}  rQ  r  rS  r[  r^  rE  r|  r  re  ImportErrorrF  objectrl  rw  r}  ru  r  r  r   r  r  r2   r8   r8   r8   r9   <module>   s   "(d	    3)/&j
		!..	#