U
    {hF                     @   s   d 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
 zddlmZ dZW n ek
rl   dZY nX dZi add	d
Zedkred ddlmZ dS )zBuild a Pyrex file from .pyx source to .so loadable module using
the installed distutils infrastructure. Call:

out_fname = pyx_to_dll("foo.pyx")
    N)DistutilsArgErrorDistutilsErrorCCompilerError)	Extension)grok_environment_error)	build_extTFc           $   	   C   s  t j| s tdt j|  t jt j| \}}	|st j|	\}
}|dks\t|tsv| dt|  d } t	|
| gd}|dkri }|st j
|d}|}|jdddd	 D ]$}t j|\}}||krd} qq|d
g }tsd|krd}nd}|r|ddg}n|dg}|r0|d |r|r|d|g |jdksd|jdrt|ds|ddi|_nd|jkrd|jd< | }|d|| d ddlm} ||}|jsg |_|j| trdti|_|d}||_| }|| z| }W n tk
r2    Y nX trJt d |!  |sTtzP|d}|"  |# d }|j$rt j
t j%| t j&|}|r|}t j'|}t(|d\}}}||kr|}nt j&|}|dk r|d7 }t j
|j)|d|  } zXddl*}!zt j+| r.t ,|  W n t-k
rN   Y W qY nX |!.||  | }W n t/k
r~   Y qY nX qqt0d| |||ft(|< |W S  t1k
r   t23d Y nH t/t j4fk
r   t25 d }"t6|"}#trt2j78|#d    Y nX dS )!zUCompile a PYX file to a DLL and return the name of the generated .so
       or .dll .zCould not find %s)z.pyxz.pyNz.c)namesourcesZ_pyxbld.script_argsz	--verbosez--quietr   z--cython-c-in-tempz--forcez--build-lib__init__z	.__init__cython_directivesZset_initial_pathZ
SOURCEFILE)script_namer   r   )Distributionbuildz%options (after parsing command line):)NNr   d      z	.reload%sz#reload count for %s reached maximum
)9ospathexistsAssertionErrorabspathsplitsplitext
HAS_CYTHONlenr   joinr   getDEBUGappendextendendswithhasattrr   copyupdatedistutils.distr   ext_modulesr   cmdclassget_command_obj
build_basefind_config_filesparse_config_filesparse_command_liner   printdump_option_dictsrun_commandsget_outputsinplacedirnamebasenamegetmtime_reloads	build_libshutilisfileunlinkOSErrorcopy2IOErrorImportErrorKeyboardInterruptsysexiterrorexc_infor   stderrwrite)$filenameextZforce_rebuildZbuild_in_tempZpyxbuild_dirZ
setup_argsZreload_supportr4   r   r   modname	extensionZpackage_base_dirpackage_nameZpnamer   quietargsZsargsr   distr   ZcfgfilesokZobj_build_extZso_pathZorg_path	timestampZlast_timestampZ	last_pathcountr6   Zr_pathr:   excrD    rT   6/tmp/pip-unpacked-wheel-fhl22ezh/pyximport/pyxbuild.py
pyx_to_dll   s     











rV   __main__z	dummy.pyxr   )test)Nr   FNNFF)__doc__r   rB   distutils.errorsr   r   r   distutils.extensionr   distutils.utilr   ZCython.Distutils.build_extr   r   r@   r!   r8   rV   __name__ rX   rT   rT   rT   rU   <module>   s*   
      
 