3
A|e@                 @   s"  d 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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 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    )remove_treemkpath)log)CodeTypeN)get_build_platformDistributionensure_directory)Library)Command)get_pathget_python_versionc               C   s   t dS )Npurelib)r    r   r   `/var/www/html/StaffProfile/staffvenv/lib/python3.6/site-packages/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_optionsR   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bdisteggr<   z.egg)r<   r<   )get_finalized_commandei_cmdrB   r9   
bdist_baser   r   joinr:   r   set_undefined_optionsr>   r   egg_nameegg_versionr   distributionhas_ext_modulesr<   )r@   rF   rG   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)r9   rE   install_libr   r   normcaserealpathr   rL   
data_files
isinstancetuplelenisabs
startswithsepappendr   infocall_command)r@   Zsite_packagesolditemrX   
normalizedr   r   r   do_install_datas   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 argsr=   dry_run)INSTALL_DIRECTORY_ATTRS
setdefaultr9   r=   rh   reinitialize_commandrun_command)r@   Zcmdnamekwdirnamecmdr   r   r   rb      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 )NrB   zinstalling library code to %srP   
build_clibrV   r   )Zwarn_dirz.pyzcreating stub loader for %s/zEGG-INFOscriptszinstalling scripts to %sinstall_scriptsrR   )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.)verboserh   mode)rh   
dist_filesr+   )3rl   r   ra   r9   rE   rU   rL   has_c_librariesr=   rb   get_ext_outputsstubs	enumerater   r   r   rH   r   r`   rh   r*   rN   replacer_   byte_compilerY   rf   r   rr   copy_metadata_tor   r%   r&   closeisfileunlinkwrite_safety_flagzip_safeexistsrB   warnr?   zap_pyfilesmake_zipfiler>   rw   
gen_headerr;   r   getattrr   )r@   ZinstcmdZold_rootro   all_outputsext_outputsZ
to_compiler/   Zext_namer   extr(   Zarchive_rootrB   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   ra   walk_eggr9   r   r   rH   r   debugr   rematchpardirgroupremoveOSErrorrename)
r@   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   rL   r   r   analyze_eggr9   r|   )r@   safer   r   r   r     s
    
zbdist_egg.zip_safec             C   s   dS )Nr!   r   )r@   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_dir N)r   r   normpathrB   rH   rF   filelistr   r^   r\   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 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   rR   rq   	build_extzdl-)r9   r    r   r   r   lowerNATIVE_EXTENSIONSr`   rH   rL   rM   rE   
extensionsrZ   r	   Zget_ext_fullnamer   Zget_ext_filenamerN   r^   r   )r@   r   r   pathsr   r   r   r   Z	build_cmdr   fullnamer   r   r   r{     s(    


&


zbdist_egg.get_ext_outputs)r,   r-   r.   )r0   Nr1   Pkeep the pseudo-installation tree around after creating the distribution archive)r2   r3   r   )r4   r5   r6   )r7   Nr8   )__name__
__module____qualname__descriptionr   user_optionsboolean_optionsrA   rO   rf   rg   rb   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_dirZwalkerr   r   r   Zbdfr   r   r   r   :  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   rH   can_scanr   r   scan_module)	r   r|   flagfnr   r   r   r   r   r   r   r   r   E  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 )Nru   rv   )r   r   r   r   rH   r   boolr   r%   r&   r   )r   r   r   r   r)   r   r   r   r   W  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 stuffNrR   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   rH   r\   r~   r_   r   sysversion_infor%   readmarshalloadr   dictfromkeysiter_symbolsr   r   )r   r   r   r|   r   pkgr   skipr)   coder   symbolsZbadr   r   r   r   j  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_constsrZ   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   rV   rt   rS   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)rh   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 )NrR   zadding '%s')	r   r   r   rH   r   r\   r&   r   r   )zrn   namesr   r   r/   )base_dirrh   r   r   visit  s    
zmake_zipfile.<locals>.visit)compression)zipfiler   r   r   rn   r   ra   ZIP_DEFLATED
ZIP_STOREDZipFiler    r   )zip_filenamer   rw   rh   compressrx   r   r   r   r   rn   r   r   r   )r   rh   r   r     s    	
r   )r   r   Tr!   )*__doc__distutils.dir_utilr   r   	distutilsr   typesr   r   r   r   r"   r   pkg_resourcesr   r   r   setuptools.extensionr	   
setuptoolsr
   	sysconfigr   r   r   r   r    r*   r+   r   r   splitr   r   r   r   r   r   r   r   ri   r   r   r   r   r   <module>   s<   
 }" 