a
    ɉxd2H                     @   s~  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 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 zddlmZmZ dd ZW n* e y   ddl!m"Z"mZ dd ZY n0 dd Z#dd Z$dd Z%G dd deZ&e'(d) Z*dd Z+dd Z,dd Z-d d!d"Z.d#d$ Z/d%d& Z0d'd( Z1g d)Z2d.d,d-Z3dS )/z6setuptools.command.bdist_egg

Build .egg distributions    )DistutilsSetupError)remove_treemkpath)log)CodeTypeN)six)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   T/var/www/html/Ranjet/env/lib/python3.9/site-packages/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| v rt j| d } | dr.| d d } | S )N.r   modulei)ospathsplitextendswith)filenamer   r   r   strip_module$   s
    
r   c                 c   s6   t | D ]&\}}}|  |  |||fV  q
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   sJ   t d }t|d}|||   W d    n1 s<0    Y  d S )Na  
        def __bootstrap__():
            global __bootstrap__, __loader__, __file__
            import sys, pkg_resources
            from importlib.machinery import ExtensionFileLoader
            __file__ = pkg_resources.resource_filename(__name__, %r)
            __loader__ = None; del __bootstrap__, __loader__
            ExtensionFileLoader(__name__,__file__).load_module()
        __bootstrap__()
        w)textwrapdedentlstripopenwrite)resourcepyfileZ_stub_templatefr   r   r   
write_stub6   s    
r.   c                   @   s   e Zd ZdZdddde  fdddd	gZg 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d  Zd!S )"	bdist_eggzcreate an "egg" distribution)z
bdist-dir=bz1temporary directory for creating the distributionz
plat-name=pz;platform name to embed in generated filenames (default: %s))exclude-source-filesNz+remove all .py files from the generated egg)	keep-tempkzPkeep the pseudo-installation tree around after creating the distribution archive)z	dist-dir=dz-directory to put final built distributions in)
skip-buildNz2skip rebuilding everything (for testing/debugging))r3   r6   r2   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_options\   s    zbdist_egg.initialize_optionsc                 C   s   |  d }| _|j| _| jd u r>|  dj}tj|d| _| jd u rPt	 | _| 
dd | jd u rtd d |j|jt | j o| j }tj| j|d | _d S )Negg_infobdistZegg)r:   r:   z.egg)get_finalized_commandei_cmdrA   r7   
bdist_baser   r   joinr8   r   set_undefined_optionsr<   r	   egg_nameZegg_versionr   distributionhas_ext_modulesr:   )r?   rD   rE   basenamer   r   r   finalize_optionse   s    


zbdist_egg.finalize_optionsc                 C   s   | j | d_tjtjt }| jj	g  }| j_	|D ]}t
|trt|dkrtj|d rtj|d }tj|}||ks||tj r|t|d d  |d f}| jj	| q:z*td| j  | jddd d W || j_	n
|| j_	0 d S )Ninstall   r      zinstalling package data to %sinstall_data)forceroot)r7   rC   install_libr   r   normcaserealpathr   rI   
data_files
isinstancetuplelenisabs
startswithsepappendr   infocall_command)r?   site_packagesolditemrU   
normalizedr   r   r   do_install_data}   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   t D ]}||| j q|d| j |d| j | j|fi |}| | |S )z8Invoke reinitialized command `cmdname` with keyword argsr;   dry_run)INSTALL_DIRECTORY_ATTRS
setdefaultr7   r;   rf   reinitialize_commandrun_command)r?   Zcmdnamekwdirnamecmdr   r   r   r_      s    
zbdist_egg.call_commandc                 C   s  |  d td| j | d}|j}d |_| j rH| jsH|  d | j	ddd}||_| 
 \}}g | _g }t|D ]|\}}tj|\}	}
tj| jt|	d }| j| td	| | jsttj|| || |tjd
||< qz|r|| | jjr|   | j}tj|d}| | | jjrltj|d}td| | j	d|dd | | tj|d}|rtd| | js t| t|d}| d| | d |!  n,tj"|r td| | js t#| t$tj|d| %  tj&tj| j'dr<t(d | j)rL| *  t+| j,|| j-| j| . d | j/st0| j| jd t1| jdg dt2 | j,f d S )NrA   zinstalling library code to %srM   
build_clibrS   r   )warn_dir.pyzcreating stub loader for %s/EGG-INFOscriptszinstalling scripts to %sinstall_scriptsrO   )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.)verboserf   moderf   
dist_filesr/   )3rj   r   r^   r7   rC   rR   rI   has_c_librariesr;   r_   get_ext_outputsstubs	enumerater   r   r   rF   r   r]   rf   r.   rK   replacer\   byte_compilerV   rd   r   rs   copy_metadata_tor
   r)   r*   closeisfileunlinkwrite_safety_flagzip_safeexistsrA   warnr=   zap_pyfilesmake_zipfiler<   rx   
gen_headerr9   r   getattrr   )r?   ZinstcmdZold_rootrm   all_outputsext_outputsZ
to_compiler1   Zext_namer   extr,   Zarchive_rootrA   Z
script_dirZnative_libsZ	libs_filer   r   r   run   s    













zbdist_egg.runc           
   
   C   s   t d t| jD ]\}}}|D ]}tj||}|drTt d| t	| |dr"|}d}t
||}tj|tj|dd }	t d||	f  zt|	 W n ty   Y n0 t||	 q"qd S )	Nz+Removing .py files from temporary directoryrp   zDeleting %s__pycache__z#(?P<name>.+)\.(?P<magic>[^.]+)\.pycname.pyczRenaming file from [%s] to [%s])r   r^   walk_eggr7   r   r   rF   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      s0    



zbdist_egg.zap_pyfilesc                 C   s2   t | jdd }|d ur|S td t| j| jS )Nr   z4zip_safe flag not set; analyzing archive contents...)r   rI   r   r   analyze_eggr7   r~   )r?   safer   r   r   r     s
    
zbdist_egg.zip_safec           
      C   s   t | jjpd}|di d}|d u r0dS tdt |jrH|j	rVt
d|f djtj }|j}d|j}|jd	 }tj| j}d
t  }| jsttj| j| jd t| jd}	|	| |	  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
rz   a)r   	parse_maprI   Zentry_pointsgetwarningsr   r   attrsextrasr   formatsysversion_infomodule_namerF   r   r   rK   r<   localsrf   r   rl   r)   r*   r   )
r?   Zepmeppyverpkgfullr!   rK   headerr-   r   r   r   r     s8    

zbdist_egg.gen_headerc                 C   sh   t j| j}t j|d}| jjjD ]<}||r&t j||t	|d }t
| | || q&dS )z*Copy metadata (egg info) to the target_dirr   N)r   r   normpathrA   rF   rD   filelistr#   r[   rY   r
   	copy_file)r?   
target_dirZnorm_egg_infoprefixr   targetr   r   r   r   B  s    
zbdist_egg.copy_metadata_toc                 C   s  g }g }| j di}t| j D ]f\}}}|D ].}tj|d  tv r*||| |  q*|D ]"}|| | d |tj||< q^q| j	
 r| d}|jD ]Z}	t|	trq||	j}
||
}tj|dstjtj| j |r|| q||fS )zAGet a list of relative paths to C extensions in the output distror   rO   rq   	build_extzdl-)r7   r$   r   r   r   lowerNATIVE_EXTENSIONSr]   rF   rI   rJ   rC   
extensionsrW   r   Zget_ext_fullnamer   Zget_ext_filenamerK   r[   r   )r?   r   r   pathsr!   r"   r#   r   Z	build_cmdr   fullnamer   r   r   r}   N  s0    





zbdist_egg.get_ext_outputsN)__name__
__module____qualname__descriptionr   user_optionsboolean_optionsr@   rL   rd   re   r_   r   r   r   r   r   r}   r   r   r   r   r/   E   s,   	
Q-r/   z.dll .so .dylib .pydc                 c   sH   t | }t|\}}}d|v r(|d |||fV  |D ]
}|V  q8dS )z@Walk an unpacked egg's contents, skipping the metadata directoryrr   N)r$   nextr   )egg_dirwalkerr!   r"   r#   Zbdfr   r   r   r   n  s    
r   c           	      C   s   t  D ](\}}tjtj| d|r|  S qt s<dS d}t| D ]R\}}}|D ]B}|dsV|drrqVqV|ds|drVt	| |||o|}qVqH|S )Nrr   FTrp   z.pywr   z.pyo)
safety_flagsitemsr   r   r   rF   can_scanr   r   scan_module)	r   r~   flagfnr   r!   r"   r#   r   r   r   r   r   y  s    
r   c                 C   s   t  D ]r\}}tj| |}tj|rJ|d u s>t||krzt| q|d urt||krt|d}|	d |
  qd S )Nrv   rw   )r   r   r   r   rF   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||}|dd |v r"dS |t| d d t jd}||rJdpLd t j|d  }tjrld}nt	j
d	k r|d
}nd}t|d}|| t|}	|  d}
tt|	}dD ]}||v rtd|| d}
qd|v r
dD ]}||v rtd|| d}
q|
S )z;Check whether module possibly uses unsafe-for-zipfile stuffNTrO   r   r   r      )            rb)__file____path__z%s: module references %sFinspect)	getsource
getabsfilegetsourcefileZgetfilegetsourcelines
findsourcegetcommentsgetframeinfogetinnerframesgetouterframesstacktracez"%s: module MAY be using inspect.%s)r   r   rF   rY   r   r\   r   r   PY2r   r   r)   readmarshalloadr   dictfromkeysiter_symbolsr   r   )r   r!   r   r~   r   r   r   skipr-   coder   symbolsbadr   r   r   r     s4     




r   c                 c   sT   | j D ]
}|V  q| jD ]6}t|tjr0|V  qt|trt|D ]
}|V  qBqdS )zBYield names and strings used by `code` and its nested code objectsN)co_names	co_constsrW   r   string_typesr   r   )r   r   constr   r   r   r     s    


r   c                   C   s2   t jdst jdkrdS td t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   )rS   ru   rP   install_baseTr%   c                    s   ddl }ttj| d td|    fdd}|rB|jn|j}s|j	| ||d}	t
 D ]\}
}}||	|
| qd|	  n t
 D ]\}
}}|d|
| q| 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   Nrz   z#creating '%s' and adding '%s' to itc                    s`   |D ]V}t jt j||}t j|r|t d d  }sN| || td| qd S )NrO   zadding '%s')	r   r   r   rF   r   rY   r*   r   r   )zrl   namesr   r   r1   base_dirrf   r   r   visit  s    zmake_zipfile.<locals>.visit)compression)zipfiler   r   r   rl   r   r^   ZIP_DEFLATED
ZIP_STOREDZipFiler$   r   )zip_filenamer   rx   rf   compressry   r   r   r   r   rl   r"   r#   r   r   r   r     s    	
r   )r   r   Tr%   )4__doc__distutils.errorsr   distutils.dir_utilr   r   	distutilsr   typesr   r   r   r   r&   r   r   Zsetuptools.externr   pkg_resourcesr   r	   r
   r   Zsetuptools.extensionr   
setuptoolsr   r   	sysconfigr   r   r   ImportErrordistutils.sysconfigr   r   r$   r.   r/   r   r   splitr   r   r   r   r   r   r   r   rg   r   r   r   r   r   <module>   sR   
  ($  