a
    bC5                     @   s   d Z d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	 ddl
mZ ddlmZ ddl
mZ ddlZzdd	lmZ W n ey   eZY n0 d
d Zedsedsedsed ejZejZG dd de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)	sysconfig)
basestringc                 C   sP   z8t t  dD ]"}| |d tjdv r W dS qW n tyJ   Y n0 dS )Nr      /TF)inspectgetouterframescurrentframereplaceossep	Exception)pathframe r   n/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/Cython/Distutils/old_build_ext.py_check_stack   s    r   zsetuptools/extensions.pyzpyximport/pyxbuild.pyzCython/Distutils/build_ext.pyzWCython.Distutils.old_build_ext does not properly handle dependencies and is deprecated.c                   @   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CPPFLAGSEXTRA_CFLAGS
BASECFLAGS	PY_CFLAGS)flagsr   get_config_varsstateconfig_varsselfr   r   r   __init__2   s    zOptimization.__init__c                    sN   d t | j| jD ]6\}}|du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 | ]}| vr|qS r   r   ).0optZ
badoptionsr   r   
<listcomp>E       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u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$   r1   r2   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
g d 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-cplusNr8   )pyrex-create-listingNr:   )pyrex-line-directivesNr<   zpyrex-include-dirs=)pyrex-c-in-tempNr>   )zpyrex-gen-pxiNr?   )zpyrex-directives=Nr@   )	pyrex-gdbNrB   )
r7   r9   r;   r=   rA   rC   rD   rE   rF   rG   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   rI      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_)getattrrH   r   __getattr__)r#   namer   r   r   rW      s    zold_build_ext.__getattr__c                 C   s6   |d d dkr(t | d|dd   |S || j|< d S rT   )setattr__dict__)r#   rX   valuer   r   r   __setattr__   s    zold_build_ext.__setattr__c                 C   sN   t j|  | jd u rg | _nt| jtr:| jtj| _| j	d u rJi | _	d S N)
rH   r   finalize_optionsrM   
isinstancer   r,   r   pathseprN   r"   r   r   r   r^      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 )rQ   Fr	   )rV   )r%   extr   r   r   r(      s   z%old_build_ext.run.<locals>.<listcomp>)rQ   
extensionsoptimizationr1   rH   r   runr"   r   r   r   rd      s    zold_build_ext.runc                 C   s8   |  | j | jD ]}| |j||_qtj|  d S r]   )Zcheck_extensions_listrb   cython_sourcessourcesrH   r   build_extensions)r#   ra   r   r   r   rg      s    
zold_build_ext.build_extensionsc           #      C   s  z$ddl m}m}m} ddlm} W n2 tyV   t d }t	d|  t
dY n0 g }g }	i }
| jptt|dd}| jpt|dd}| jpt|d	d}| jpt|d
dp|jo|j dk}| jpt|dd}| jpt|dd}| jpt|dd}| j}z&|jD ]}||vr|| qW n ty6   Y n0 t|j|_|jD ]}||vrJ|| qJ| j}t|dr||j |rd}nd}| js| jst|ddrtj !| j"d}|j#$ddd D ]}tj !||}qnd}d}|D ]}tj %tj &|\}}|dkr$d}|dkrp|p>tj '|}|tj !|||  |	| |d |
|< n:|dks|dkr|du st(||r|}n
|| q|	s|S |j#}|	D ]}|
| }|gt|j)pd }|dd  dkr,tj *|dd d r,||dd d g7 }| j+p>t,||d } | sZ|durZt(||} | rt-.d!|| | /tj '| | jrtj0}n| j1}||||||||| ||||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   )CompilationOptionsdefault_optionscompile)
PyrexErrorr	   zfailed to import Cython: %sz&Cython does not appear to be installedrK   rL   rR   rJ   zc++rP   rQ   FrS   NrN   z.cppz.crO   Zpyrex.z.pyz.pyxz.pxiz.pxdr   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))2ZCython.Compiler.Mainrh   ri   rj   ZCython.Compiler.Errorsrk   ImportErrorsysexc_infoprintr   rK   rV   rL   rR   rJ   languagelowerrP   rQ   rS   rM   appendAttributeErrorlistinclude_dirsrN   hasattrupdateZinplacerO   r   r   r-   
build_temprX   r,   splitextbasenamedirnamer   dependsisfileforcer   r   infomkpathcurdir	build_lib)#r#   rf   	extensionrh   Zcython_default_optionsZcython_compilerk   eZnew_sourcesre   Zcython_targetsZcreate_listingZline_directivesrR   rp   rP   rQ   rS   ZincludesiZ
directivesZ
target_ext
target_dirpackage_nameZnewest_dependencysourcebasera   rq   module_nametargetr   Zrebuildrr   resultr   r   r   re      s    













0
zold_build_ext.cython_sources)r3   r4   r5   descriptionrH   r   Zsep_byuser_optionsboolean_optionshelp_optionsextendrI   rW   r\   r^   rd   rg   re   r   r   r   r   r6   R   sH   '		r6   )__doc__Z__revision__r   rt   r   distutils.errorsr   distutils.dep_utilr   r   	distutilsr   distutils.commandr   rH   r   warnings__builtin__r   rs   strr   warnZextension_name_reshow_compilersobjectr   rc   r6   r   r   r   r   <module>   s8   
	