3
LYC                 @   sh  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m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 yddlmZmZ dd ZW n, ek
r   ddlmZmZ dd ZY nX 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 )0z6setuptools.command.bdist_egg

Build .egg distributions    )DistutilsSetupError)remove_treemkpath)log)CodeTypeN)six)get_build_platformDistributionensure_directory)
EntryPoint)Library)Command)get_pathget_python_versionc               C   s   t dS )Npurelib)r    r   r   v/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/setuptools/setuptools/command/bdist_egg.py_get_purelib   s    r   )get_python_libr   c               C   s   t dS )NF)r   r   r   r   r   r      s    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   s6   t jdj }t|d}|j||   W d Q R X d S )NaR  
        def __bootstrap__():
            global __bootstrap__, __loader__, __file__
            import sys, pkg_resources, imp
            __file__ = pkg_resources.resource_filename(__name__, %r)
            __loader__ = None; del __bootstrap__, __loader__
            imp.load_dynamic(__name__,__file__)
        __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d f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 ).	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 eggz	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_optionsO   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eggr8   z.egg)r8   r8   )get_finalized_commandei_cmdr>   r5   
bdist_baser   r   joinr6   r   set_undefined_optionsr:   r	   egg_nameZegg_versionr   distributionhas_ext_modulesr8   )r<   rA   rB   basenamer   r   r   finalize_optionsX   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)r5   r@   install_libr   r   normcaserealpathr   rF   
data_files
isinstancetuplelenisabs
startswithsepappendr   infocall_command)r<   site_packagesolditemrR   
normalizedr   r   r   do_install_datap   s     
zbdist_egg.do_install_datac             C   s   | j gS )N)r:   )r<   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 argsr9   dry_run)INSTALL_DIRECTORY_ATTRS
setdefaultr5   r9   rc   reinitialize_commandrun_command)r<   Zcmdnamekwdirnamecmdr   r   r   r\      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 )Nr>   zinstalling library code to %srJ   
build_clibrP   r   )warn_dirz.pyzcreating stub loader for %s/zEGG-INFOscriptszinstalling scripts to %sinstall_scriptsrL   )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.)verboserc   mode)rc   
dist_filesr(   )3rg   r   r[   r5   r@   rO   rF   has_c_librariesr9   r\   get_ext_outputsstubs	enumerater   r   r   rC   r   rZ   rc   r'   rH   replacerY   byte_compilerS   ra   r   rn   copy_metadata_tor
   r"   r#   closeisfileunlinkwrite_safety_flagzip_safeexistsr>   warnr;   zap_pyfilesmake_zipfiler:   rs   
gen_headerr7   r   getattrr   )r<   ZinstcmdZold_rootrj   all_outputsext_outputsZ
to_compiler,   Zext_namer   extr%   Zarchive_rootr>   Z
script_dirZnative_libsZ	libs_filer   r   r   run   sz    












zbdist_egg.runc             C   sd   t jd xTt| jD ]F\}}}x:|D ]2}|jdr&tjj||}t jd| tj	| q&W qW d S )Nz+Removing .py files from temporary directoryz.pyzDeleting %s)
r   r[   walk_eggr5   r   r   r   rC   debugr   )r<   basedirsfilesnamer   r   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   rF   r   r   analyze_eggr5   rx   )r<   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 |j s>|jrLtd|f tj	d d }|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   zGeggsecutable entry point (%r) cannot have 'extras' or refer to a module   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
)rc   a)r   	parse_maprF   entry_pointsgetattrsextrasr   sysversionmodule_namerC   r   r   rH   r:   localsrc   r   ri   r"   r#   r}   )
r<   Zepmeppyverpkgfullr   rH   headerr&   r   r   r   r      s*    


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   normpathr>   rC   rA   filelistr   rX   rV   r
   	copy_file)r<   
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| j D ]n\}}}x6|D ].}tjj|d j tkr0|j|| |  q0W x*|D ]"}|| | d |tjj||< qhW 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   rL   rm   	build_extzdl-)r5   r   walkr   r   lowerNATIVE_EXTENSIONSrZ   rC   rF   rG   r@   
extensionsrT   r   Zget_ext_fullnamer   Zget_ext_filenamerH   rX   r   )r<   r   r   pathsr   r   r   r   Z	build_cmdr   fullnamer   r   r   rw   *  s(    


&


zbdist_egg.get_ext_outputs)r)   r*   r+   )r-   Nr.   )r0   r1   r2   )r3   Nr4   )__name__
__module____qualname__descriptionr   user_optionsboolean_optionsr=   rI   ra   rb   r\   r   r   r   r   r|   rw   r   r   r   r   r(   8   s4       
	
Q	'r(   z.dll .so .dylib .pydc             c   sN   t j| }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   r   nextremove)egg_dirwalkerr   r   r   Zbdfr   r   r   r   J  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   rC   can_scanr   r   scan_module)	r   rx   flagfnr   r   r   r   r   r   r   r   r   U  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 )Nrq   rr   )r   r   r   r   rC   r   boolr   r"   r#   r}   )r   r   r   r   r&   r   r   r   r   g  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 stuffNrL   Tr   r   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   rC   rV   rz   rY   r   r   version_infor"   readmarshalloadr}   dictfromkeysiter_symbolsr   r   )r   r   r   rx   r   r   r   skipr&   coder   symbolsbadr   r   r   r   z  s6     





  

r   c             c   s`   x| j D ]
}|V  qW xD| jD ]:}t|tjr6|V  qt|trxt|D ]
}|V  qJW qW dS )zBYield names and strings used by `code` and its nested code objectsN)co_names	co_constsrT   r   string_typesr   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   platformrX   r   r   r   r   r   r   r     s    
r   rP   rp   rM   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j
 D ]\}
}}||	|
| qhW |	j  n&x$tj
 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)rc   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 )NrL   zadding '%s')	r   r   r   rC   r~   rV   r#   r   r   )zri   namesr   r   r,   )base_dirrc   r   r   visit  s    
zmake_zipfile.<locals>.visit)compression)zipfiler   r   r   ri   r   r[   ZIP_DEFLATED
ZIP_STOREDZipFiler   r}   )zip_filenamer   rs   rc   compressrt   r   r   r   r   ri   r   r   r   )r   rc   r   r     s    	
r   )r   r   Tr   )0__doc__Zdistutils.errorsr   distutils.dir_utilr   r   	distutilsr   typesr   r   r   r   r   Zsetuptools.externr   pkg_resourcesr   r	   r
   r   Zsetuptools.extensionr   
setuptoolsr   	sysconfigr   r   r   ImportErrordistutils.sysconfigr   r   r'   r(   r   r   splitr   r   r   r   r   r   r   r   rd   r   r   r   r   r   <module>   sH     " 