U
    {h5                     @   s   d Z dZddlZddl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	mZ ejZejZG d	d
 d
Ze ZG dd dejZdS )zCython.Distutils.old_build_ext

Implements a version of the Distutils 'build_ext' command, for
building Cython extension modules.

Note that this module is deprecated.  Use cythonize() instead.
z$Id:$    N)DistutilsPlatformError)newernewer_group)log)	build_ext)	sysconfigc                   @   s$   e Zd Zdd Zdd Zdd ZdS )Optimizationc                 C   s"   d| _ tj| j  | _t | _d S )N)OPTCFLAGSCPPFLAGSZEXTRA_CFLAGS
BASECFLAGS	PY_CFLAGS)flagsr   get_config_varsstateconfig_varsself r   B/tmp/pip-unpacked-wheel-fhl22ezh/Cython/Distutils/old_build_ext.py__init__2   s    zOptimization.__init__c                    sN   d t | j| jD ]6\}}|dk	r fdd| D }d|| j|< qdS )z.disable optimization for the C or C++ compiler)z-O1z-O2z-O3Nc                    s   g | ]}| kr|qS r   r   ).0optZ
badoptionsr   r   
<listcomp>E   s      z5Optimization.disable_optimization.<locals>.<listcomp> )zipr   r   splitjoinr   )r   flagoptionLr   r   r   disable_optimization?   s
    z!Optimization.disable_optimizationc                 C   s.   t | j| jD ]\}}|dk	r|| j|< qdS )zrestore the original stateN)r   r   r   r   )r   r   r    r   r   r   restore_stateH   s    zOptimization.restore_stateN)__name__
__module____qualname__r   r"   r#   r   r   r   r   r   1   s   	r   c                   @   s   e Zd ZdZejjZejjdd Zejjdd Zejj	dd Z	e
dddddde fdd	d
dddddddde fddddg e
ddddddddddg
 dd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, ZdS )-old_build_extzCbuild C/C++ and Cython extensions (compile/link to build directory)N)cython-cplusNgenerate C++ source files)cython-create-listingNwrite errors to a listing file)cython-line-directivesNemit source line directiveszcython-include-dirs=z path to the Cython include files)cython-c-in-tempN'put generated C files in temp directory)zcython-gen-pxiN*generate .pxi file for public declarations)zcython-directives=Ncompiler directive overrides)
cython-gdbN$generate debug information for cygdb)zcython-compile-time-envNzcython compile time environment)pyrex-cplusNr)   )pyrex-create-listingNr+   )pyrex-line-directivesNr-   zpyrex-include-dirs=)pyrex-c-in-tempNr/   )zpyrex-gen-pxiNr0   )zpyrex-directives=Nr1   )	pyrex-gdbNr3   r(   r*   r,   r.   r2   r4   r5   r6   r7   r8   c                 C   sL   t j|  d| _d| _d| _d | _d | _d| _d| _	d| _
d| _d | _d S )Nr   F)
_build_extr   initialize_optionscython_cpluscython_create_listingcython_line_directivescython_include_dirscython_directivescython_c_in_tempcython_gen_pxi
cython_gdbno_c_in_tracebackcython_compile_time_envr   r   r   r   r:      s    z old_build_ext.initialize_optionsc                 C   s8   |d d dkr&t | d|dd   S tj| |S d S N   Zpyrex_Zcython_)getattrr9   r   __getattr__)r   namer   r   r   rH      s    zold_build_ext.__getattr__c                 C   s6   |d d dkr(t | d|dd   |S || j|< d S rE   )setattr__dict__)r   rI   valuer   r   r   __setattr__   s    zold_build_ext.__setattr__c                 C   sN   t j|  | jd krg | _nt| jtr:| jtj| _| j	d krJi | _	d S N)
r9   r   finalize_optionsr>   
isinstancestrr   ospathsepr?   r   r   r   r   rO      s    

zold_build_ext.finalize_optionsc                 C   s.   | j sdd | jD rt  tj|  d S )Nc                 S   s   g | ]}t |d drdqS )rB   F   )rG   )r   extr   r   r   r      s    z%old_build_ext.run.<locals>.<listcomp>)rB   
extensionsoptimizationr"   r9   r   runr   r   r   r   rX      s    zold_build_ext.runc                 C   s.   t j| | | jD ]}| |j||_qd S rN   )r9   r   check_extensions_listrV   cython_sourcessources)r   rV   rU   r   r   r   rY      s    
z#old_build_ext.check_extensions_listc           #      C   s  g }g }i }| j pt|dd}| jp.t|dd}| jp@t|dd}| jpft|ddpf|jof|j dk}	| jpxt|dd}
| jpt|dd	}| j	pt|d
d}t
| j}z"|jD ]}||kr|| qW n tk
r   Y nX t
|j|_|jD ]}||kr|| qt| j}t|dr,||j |	r8d}nd}| js| jsZt|ddrtj| jd}|jddd D ]}tj||}q~nd}d}|D ]}tjtj|\}}|dkrd}|dkr|ptj|}|tj|||  || |d ||< n:|dks,|dkrH|dksBt||rR|}n
|| q|s`|S z$ddlm }m!}m"} ddl#m$} W n6 t%k
r   t&' d }t(d|  t)dY nX |j}|D ]}|| }|gt
|j*pd }|dd  dkr0tj+|dd d r0||dd d g7 }| j,pBt-||d } | s^|dk	r^t||} | rt./d!|| | 0tj| | jrtj1}n| j2}|||||||	|| |
|||d"}!|||!|d#}"nt./d$| q|S )%a  
        Walk the list of source files in 'sources', looking for Cython
        source files (.pyx and .py).  Run Cython on all that are
        found, and return a modified 'sources' list with Cython source
        files replaced by the generated C (or C++) files.
        r<   r   r=   rC   r;   zc++rA   rB   FrD   Nr?   z.cppz.cr@   Zpyrex.z.pyz.pyxz.pxiz.pxd)CompilationOptionsdefault_optionscompile)
PyrexErrorrT   zfailed to import Cython: %sz&Cython does not appear to be installedr   Zpxdr   zcythoning %s to %s)Zuse_listing_fileZinclude_pathZcompiler_directivesZoutput_filecplusZemit_linenumsZc_line_in_tracebackZgenerate_pxi
output_dirZ	gdb_debugZcompile_time_env)optionsZfull_module_namez+skipping '%s' Cython extension (up-to-date))3r<   rG   r=   rC   r;   languagelowerrA   rB   rD   listr>   appendAttributeErrorinclude_dirsdictr?   hasattrupdateZinplacer@   rR   pathr   
build_temprI   r   splitextbasenamedirnamer   ZCython.Compiler.Mainr^   r_   r`   ZCython.Compiler.Errorsra   ImportErrorsysexc_infoprintr   dependsisfileforcer   r   infomkpathcurdir	build_lib)#r   r[   	extensionZnew_sourcesrZ   Zcython_targetsZcreate_listingZline_directivesrC   rd   rA   rB   rD   ZincludesiZ
directivesZ
target_ext
target_dirpackage_nameZnewest_dependencysourcebaserU   re   r^   Zcython_default_optionsZcython_compilera   emodule_nametargetry   Zrebuildrf   resultr   r   r   rZ      s    













0
zold_build_ext.cython_sources)r$   r%   r&   descriptionr9   r   Zsep_byuser_optionsboolean_optionshelp_optionsextendr:   rH   rM   rO   rX   rY   rZ   r   r   r   r   r'   R   s^   '      	r'   )__doc__Z__revision__rv   rR   distutils.errorsr   distutils.dep_utilr   r   	distutilsr   distutils.commandr   r9   r   Zextension_name_reshow_compilersr   rW   r'   r   r   r   r   <module>   s   