3
;p_DG                 @   sF  d Z ddlmZ ddlmZmZ ddlmZ ddlm	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mZmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZmZ dd Zdd Zdd Zdd Z G dd deZ!e"j#dj$ Z%dd Z&dd Z'dd Z(dddZ)d d! Z*d"d# Z+d$d% Z,d&d'd(d)gZ-d.d,d-Z.dS )/z6setuptools.command.bdist_egg

Build .egg distributions    )DistutilsSetupError)remove_treemkpath)log)CodeTypeN)get_build_platformDistributionensure_directory)
EntryPoint)Library)CommandSetuptoolsDeprecationWarning)get_pathget_python_versionc               C   s   t dS )Npurelib)r    r   r   D/tmp/pip-install-ofl94hr3/setuptools/setuptools/command/bdist_egg.py_get_purelib   s    r   c             C   s2   d| krt jj| d } | jdr.| d d } | S )N.r   module   i)ospathsplitextendswith)filenamer   r   r   strip_module   s
    
r   c             c   s:   x4t j| D ]&\}}}|j  |j  |||fV  qW dS )zbDo os.walk in a reproducible way,
    independent of indeterministic filesystem readdir order
    N)r   walksort)dirbasedirsfilesr   r   r   sorted_walk$   s    r#   c          
   C   s6   t jdj }t|d}|j||   W d Q R X d S )Na  
        def __bootstrap__():
            global __bootstrap__, __loader__, __file__
            import sys, pkg_resources, importlib.util
            __file__ = pkg_resources.resource_filename(__name__, %r)
            __loader__ = None; del __bootstrap__, __loader__
            spec = importlib.util.spec_from_file_location(__name__,__file__)
            mod = importlib.util.module_from_spec(spec)
            spec.loader.exec_module(mod)
        __bootstrap__()
        w)textwrapdedentlstripopenwrite)resourcepyfileZ_stub_templatefr   r   r   
write_stub.   s    

r-   c               @   s   e Zd ZdZd*ddde  fd+d-d.d/gZdddgZdd Zdd Zdd Z	dd Z
dd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd	S )0	bdist_eggzcreate an "egg" distribution
bdist-dir=b1temporary directory for creating the distributionz
plat-name=pz;platform name to embed in generated filenames (default: %s)exclude-source-filesN+remove all .py files from the generated egg	keep-tempkz/keep the pseudo-installation tree around after z!creating the distribution archive	dist-dir=d-directory to put final built distributions in
skip-build2skip rebuilding everything (for testing/debugging)c             C   s.   d | _ d | _d| _d | _d| _d | _d | _d S )Nr   )	bdist_dir	plat_name	keep_tempdist_dir
skip_build
egg_outputexclude_source_files)selfr   r   r   initialize_optionsU   s    zbdist_egg.initialize_optionsc             C   s   | j d }| _|j| _| jd kr>| j dj}tjj|d| _| jd krPt	 | _| j
dd | jd krtd d |j|jt | jj o| jj }tjj| j|d | _d S )Negg_infobdistZeggr?   z.egg)r?   r?   )get_finalized_commandei_cmdrE   r<   
bdist_baser   r   joinr=   r   set_undefined_optionsrA   r   egg_nameZegg_versionr   distributionhas_ext_modulesr?   )rC   rH   rI   basenamer   r   r   finalize_options^   s    


zbdist_egg.finalize_optionsc             C   s   | j | jd_tjjtjjt }| jj	g  }| j_	x|D ]}t
|trt|dkrtjj|d rtjj|d }tjj|}||ks|j|tj r|t|d d  |d f}| jj	j| q<W z"tjd| j  | jddd d W d || j_	X d S )Ninstall   r      zinstalling package data to %sinstall_data)forceroot)r<   rG   install_libr   r   normcaserealpathr   rM   
data_files
isinstancetuplelenisabs
startswithsepappendr   infocall_command)rC   site_packagesolditemrY   
normalizedr   r   r   do_install_datav   s     
zbdist_egg.do_install_datac             C   s   | j gS )N)rA   )rC   r   r   r   get_outputs   s    zbdist_egg.get_outputsc             K   sT   xt D ]}|j|| j qW |jd| j |jd| j | j|f|}| j| |S )z8Invoke reinitialized command `cmdname` with keyword argsr@   dry_run)INSTALL_DIRECTORY_ATTRS
setdefaultr<   r@   rj   reinitialize_commandrun_command)rC   Zcmdnamekwdirnamecmdr   r   r   rc      s    

zbdist_egg.call_commandc             C   s  | j d tjd| j | jd}|j}d |_| jj rJ| j rJ| j d | j	ddd}||_| j
 \}}g | _g }xt|D ]|\}}tjj|\}	}
tjj| jt|	d }| jj| tjd	| | jsttjj|| |j| |jtjd
||< q~W |r|j| | jjr | j  | j}tjj|d}| j| | jjrrtjj|d}tjd| | j	d|dd | j| tjj|d}|rtjd| | jst| t|d}|j dj| |j d |j!  n,tjj"|rtjd| | jstj#| t$tjj|d| j%  tjj&tjj| j'drBtj(d | j)rR| j*  t+| j,|| j-| j| j. d | j/st0| j| jd t1| jdg jdt2 | j,f d S )NrE   zinstalling library code to %srQ   
build_clibrW   r   )warn_dirz.pyzcreating stub loader for %s/zEGG-INFOscriptszinstalling scripts to %sinstall_scriptsrS   )install_dirZno_epznative_libs.txtz
writing %swt
zremoving %szdepends.txtzxWARNING: 'depends.txt' will not be used by setuptools 0.6!
Use the install_requires/extras_require setup() args instead.)verboserj   mode)rj   
dist_filesr.   )3rn   r   rb   r<   rG   rV   rM   has_c_librariesr@   rc   get_ext_outputsstubs	enumerater   r   r   rJ   r   ra   rj   r-   rO   replacer`   byte_compilerZ   rh   r   ru   copy_metadata_tor	   r(   r)   closeisfileunlinkwrite_safety_flagzip_safeexistsrE   warnrB   zap_pyfilesmake_zipfilerA   rz   
gen_headerr>   r   getattrr   )rC   ZinstcmdZold_rootrq   all_outputsext_outputsZ
to_compiler2   Zext_namer   extr+   Zarchive_rootrE   Z
script_dirZnative_libsZ	libs_filer   r   r   run   sz    












zbdist_egg.runc       
      C   s   t jd xt| jD ]\}}}x|D ]}tjj||}|jdrXt jd| tj	| |jdr&|}d}t
j||}tjj|tj|jdd }	t jd||	f  ytj|	 W n tk
r   Y nX tj||	 q&W qW d S )	Nz+Removing .py files from temporary directoryz.pyzDeleting %s__pycache__z#(?P<name>.+)\.(?P<magic>[^.]+)\.pycnamez.pyczRenaming file from [%s] to [%s])r   rb   walk_eggr<   r   r   rJ   r   debugr   rematchpardirgroupremoveOSErrorrename)
rC   r    r!   r"   r   r   Zpath_oldpatternmZpath_newr   r   r   r      s*    




zbdist_egg.zap_pyfilesc             C   s2   t | jdd }|d k	r|S tjd t| j| jS )Nr   z4zip_safe flag not set; analyzing archive contents...)r   rM   r   r   analyze_eggr<   r   )rC   safer   r   r   r     s
    
zbdist_egg.zip_safec       
      C   s   t j| jjpd}|jdi jd}|d kr0dS tjdt |j sJ|j	rXt
d|f djtj }|j}dj|j}|jd	 }tjj| j}d
t  }| jsttjj| j| jd t| jd}	|	j| |	j  dS )N zsetuptools.installationZeggsecutabler$   zEEggsecutables are deprecated and will be removed in a future version.zGeggsecutable entry point (%r) cannot have 'extras' or refer to a modulez{}.{}r   r   aH  #!/bin/sh
if [ `basename $0` = "%(basename)s" ]
then exec python%(pyver)s -c "import sys, os; sys.path.insert(0, os.path.abspath('$0')); from %(pkg)s import %(base)s; sys.exit(%(full)s())" "$@"
else
  echo $0 is not the correct name for this egg file.
  echo Please rename it back to %(basename)s and try again.
  exec false
fi
)rj   a)r
   	parse_maprM   entry_pointsgetwarningsr   r   attrsextrasr   formatsysversion_infomodule_namerJ   r   r   rO   rA   localsrj   r   rp   r(   r)   r   )
rC   Zepmeppyverpkgfullr    rO   headerr,   r   r   r   r     s0    


zbdist_egg.gen_headerc             C   sl   t jj| j}t jj|d}xJ| jjjD ]<}|j|r(t jj||t	|d }t
| | j|| q(W dS )z*Copy metadata (egg info) to the target_dirr   N)r   r   normpathrE   rJ   rH   filelistr"   r_   r]   r	   	copy_file)rC   
target_dirZnorm_egg_infoprefixr   targetr   r   r   r   ;  s    
zbdist_egg.copy_metadata_toc             C   s  g }g }| j di}x|t| j D ]n\}}}x6|D ].}tjj|d j tkr.|j|| |  q.W x*|D ]"}|| | d |tjj||< qfW qW | j	j
 r| jd}xd|jD ]Z}	t|	trq|j|	j}
|j|
}tjj|jdstjjtjj| j |r|j| qW ||fS )zAGet a list of relative paths to C extensions in the output distror   rS   rt   	build_extzdl-)r<   r#   r   r   r   lowerNATIVE_EXTENSIONSra   rJ   rM   rN   rG   
extensionsr[   r   Zget_ext_fullnamer   Zget_ext_filenamerO   r_   r   )rC   r   r   pathsr    r!   r"   r   Z	build_cmdr   fullnamer   r   r   r~   G  s(    


&


zbdist_egg.get_ext_outputs)r/   r0   r1   )r3   Nr4   Pkeep the pseudo-installation tree around after creating the distribution archive)r5   r6   r   )r7   r8   r9   )r:   Nr;   )__name__
__module____qualname__descriptionr   user_optionsboolean_optionsrD   rP   rh   ri   rc   r   r   r   r   r   r~   r   r   r   r   r.   >   s4         
	
Q-r.   z.dll .so .dylib .pydc             c   sL   t | }t|\}}}d|kr(|jd |||fV  x|D ]
}|V  q:W dS )z@Walk an unpacked egg's contents, skipping the metadata directoryzEGG-INFON)r#   nextr   )egg_dirwalkerr    r!   r"   Zbdfr   r   r   r   g  s    

r   c       	      C   s   x0t j D ]$\}}tjjtjj| d|r
|S q
W t s<dS d}xbt| D ]V\}}}xJ|D ]B}|jdsZ|jdrvqZqZ|jds|jdrZt	| |||o|}qZW qJW |S )NzEGG-INFOFTz.pyz.pywz.pycz.pyo)
safety_flagsitemsr   r   r   rJ   can_scanr   r   scan_module)	r   r   flagfnr   r    r!   r"   r   r   r   r   r   r  s    
r   c             C   s   x~t j D ]r\}}tjj| |}tjj|rL|d ks@t||kr|tj| q
|d k	r
t||kr
t|d}|j	d |j
  q
W d S )Nrx   ry   )r   r   r   r   rJ   r   boolr   r(   r)   r   )r   r   r   r   r,   r   r   r   r     s    

r   zzip-safeznot-zip-safe)TFc             C   s  t jj||}|dd |kr"dS |t| d d jt jd}||rJdpLd t jj|d  }tjdk rpd	}nd
}t	|d}|j
| tj|}	|j  d}
tjt|	}x&dD ]}||krtjd|| d}
qW d|kr
x*d D ]"}||k rtjd|| d}
 qW |
S )!z;Check whether module possibly uses unsafe-for-zipfile stuffNrS   Tr   r   r               rb__file____path__z%s: module references %sFinspect	getsource
getabsfilegetsourcefilegetfilegetsourcelines
findsourcegetcommentsgetframeinfogetinnerframesgetouterframesstacktracez"%s: module MAY be using inspect.%s)r   r   )r   r   )r   r   r   r   r   r   r   r   r   r   r   )r   r   rJ   r]   r   r`   r   r   r   r(   readmarshalloadr   dictfromkeysiter_symbolsr   r   )r   r    r   r   r   r   r   skipr,   coder   symbolsbadr   r   r   r     s6     





  

r   c             c   s^   x| j D ]
}|V  qW xB| jD ]8}t|tr4|V  qt|trxt|D ]
}|V  qHW qW dS )zBYield names and strings used by `code` and its nested code objectsN)co_names	co_constsr[   strr   r   )r   r   constr   r   r   r     s    


r   c               C   s4   t jjd rt jdkrdS tjd tjd d S )NjavacliTz1Unable to analyze compiled code on this platform.zfPlease ask the author to include a 'zip_safe' setting (either True or False) in the package's setup.py)r   platformr_   r   r   r   r   r   r   r     s    
r   rW   rw   rT   install_baseTr$   c                s   ddl }ttjj| d tjd|    fdd}|rB|jn|j}s|j	| ||d}	x"t
 D ]\}
}}||	|
| qfW |	j  n$x"t
 D ]\}
}}|d|
| qW | S )aq  Create a zip file from all the files under 'base_dir'.  The output
    zip file will be named 'base_dir' + ".zip".  Uses either the "zipfile"
    Python module (if available) or the InfoZIP "zip" utility (if installed
    and found on the default search path).  If neither tool is available,
    raises DistutilsExecError.  Returns the name of the output zip file.
    r   N)rj   z#creating '%s' and adding '%s' to itc                sd   x^|D ]V}t jjt jj||}t jj|r|t d d  }sP| j|| tjd| qW d S )NrS   zadding '%s')	r   r   r   rJ   r   r]   r)   r   r   )zrp   namesr   r   r2   )base_dirrj   r   r   visit  s    
zmake_zipfile.<locals>.visit)compression)zipfiler   r   r   rp   r   rb   ZIP_DEFLATED
ZIP_STOREDZipFiler#   r   )zip_filenamer   rz   rj   compressr{   r   r   r   r   rp   r!   r"   r   )r   rj   r   r     s    	
r   )r   r   Tr$   )/__doc__distutils.errorsr   distutils.dir_utilr   r   	distutilsr   typesr   r   r   r   r%   r   r   pkg_resourcesr   r   r	   r
   Zsetuptools.extensionr   
setuptoolsr   r   	sysconfigr   r   r   r   r#   r-   r.   r   r   splitr   r   r   r   r   r   r   r   rk   r   r   r   r   r   <module>   sD   
  (" 