B
    \                  @   s   d dl m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 yd dlZee d	 ZW n ek
r   dZd ZY nX G d
d deZdd Zdd Zdd Zdd Zdd Zdd Zdd ZdddZedkre  dS )    )absolute_importN)setup   )	cythonizeextended_iglob   )is_package_dir)Optionsg      ?c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	_FakePoolc             C   sB   yddl m} W n tk
r(   t}Y nX x|||D ]}q6W d S )Nr   )imap)	itertoolsr   ImportErrormap)selffuncargsr   _ r   5lib/python3.7/site-packages/Cython/Build/Cythonize.py	map_async   s    
z_FakePool.map_asyncc             C   s   d S )Nr   )r   r   r   r   close   s    z_FakePool.closec             C   s   d S )Nr   )r   r   r   r   	terminate"   s    z_FakePool.terminatec             C   s   d S )Nr   )r   r   r   r   join%   s    z_FakePool.joinN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r
      s   r
   c             C   s>   | j }tt|j|t }tj|d|d}t|j|| d S )NT)Zrelaxed_boolcurrent_settings)destdictgetattrvaluesr	   Zget_directive_defaultsZparse_directive_listsetattr)optionnamevalueparserr   Zold_directives
directivesr   r   r   parse_directives)   s    
r'   c       	      C   sv   | j }tt|j|i }xJ|dD ]<}d|krN|dd\}}| dk}n
|d }}|||< q$W t|j|| d S )N,=r   )Zfalsef0ZnoT)r   r   r   r    splitlowerr!   )	r"   r#   r$   r%   r   optionsZoptnvr   r   r   parse_options2   s    
r1   c             C   s8   | j }tt|j|i }tj||d}t|j|| d S )N)r   )r   r   r   r    r	   parse_compile_time_envr!   )r"   r#   r$   r%   r   Zold_envZnew_envr   r   r   r2   ?   s    r2   c             C   sP   t j| \}}x6t jt j|drFt j|\}}d||f }qW ||fS )Nz__init__.pyz%s/%s)ospathr,   isfiler   )r4   base_dirZpackage_pathparentr   r   r   find_package_baseF   s
    r8   c                s~  d }t tjjt| }y&x|D ]}|jrZ| x*tj rHt rVtj  q4W nd  tj|r~tj	|ddg}n|g}t
|f|j|j|j|j|j|j|jd|j}|r"|jr"t|dkr,|jdkr,|d kryt|j}W n tk
r   t }Y nX |t fdd|D  q"t |f q"W W n    |d k	rX|   Y nX |d k	rz|  |	  d S )Nz**z
*.{py,pyx})ZnthreadsZexclude_failuresZexcludeZcompiler_directivescompile_time_envforcequietr   c                s   g | ]} |gfqS r   r   ).0Zext)r6   r   r   
<listcomp>t   s    z"cython_compile.<locals>.<listcomp>)r   r3   r4   abspathr   build_inplaceisdirr   dirnamer   r   parallel
keep_goingexcludesr&   r9   r:   r;   r.   buildlenmultiprocessingZPoolOSErrorr
   r   run_distutilsr   r   )Zpath_patternr.   ZpoolZ	all_pathsr4   pathsext_modulesr   )r6   r   cython_compileN   sN    




rL   c          	   C   s   | \}}ddg}t  }d }z:|rFt | tj|d}|d|g td||d W d |rt | |rt j|rt	
| X d S )NZ	build_extz-i)dirz--build-tempzsetup.py)script_namescript_argsrK   )r3   getcwdchdirtempfileZmkdtempextendr   r4   r@   shutilZrmtree)r   r6   rK   rO   cwdZtemp_dirr   r   r   rI      s"    

rI   c             C   s  ddl m} |dd}|jddddi d	d
tdd	 |jddddi d	d
tdd	 |jddddi d	d
tdd	 |jddddd dd |jdddddd |jd ddd!dd |jd"d#d$d%d&d' |jd(d)d*d+d,g d-d. |jd/d0d1d%d2d' |jd3d4d5d%d6d' |jd7d8d9d:ttd;t pd<d= |jd>d?d@d%dAd' |jdBdCdDd%dEd' |jdFdGd%dHd' |jdIdJdKd%dLd' || \}} | s|	dM |j
rdN|_td krd|_|jr|jdOkst|j|jd< || fS )PNr   )OptionParserz'%prog [options] [sources and packages]+)Zusagez-Xz--directivezNAME=VALUE,...r&   strcallbackzset a compiler directive)metavarr   defaulttypeactionrX   helpz-Ez--compile-time-envr9   z'set a compile time environment variablez-sz--optionz
NAME=VALUEr.   zset a cythonize optionz-2language_levelZstore_constr   z#use Python 2 syntax mode by default)r   r\   constrZ   r]   z-3   z#use Python 3 syntax mode by default)r   r\   r_   r]   z--3str3strz-az
--annotateannotate
store_truez-generate annotated HTML page for source files)r   r\   r]   z-xz	--excludeZPATTERNrD   appendz2exclude certain file patterns from the compilation)rY   r   r\   rZ   r]   z-bz--buildrE   z'build extension modules using distutilsz-iz	--inplacer?   z=build extension modules in place using distutils (implies -b)z-jz
--parallelrB   Nz+run builds in N parallel jobs (default: %d)r   )r   rY   r[   rZ   r]   z-fz--forcer:   zforce recompilationz-qz--quietr;   z"be less verbose during compilationz	--lenientlenientzBincrease Python compatibility by ignoring some compile time errorsz-kz--keep-goingrC   z8compile as much as possible, ignore compilation failureszno source files providedT)r   r`   ra   )ZoptparserV   Z
add_optionr'   r2   r1   intparallel_compiles
parse_argserrorr?   rE   rG   rB   r^   AssertionErrorr.   )r   rV   r%   r.   r   r   r   ri      sh    






ri   c             C   sF   t | \}}|jrdt_dt_|jr*dt_x|D ]}t|| q0W d S )NFT)ri   rf   r	   Zerror_on_unknown_namesZerror_on_uninitializedrb   rL   )r   r.   rJ   r4   r   r   r   main   s    
rl   __main__)N)Z
__future__r   r3   rT   rR   Zdistutils.corer   ZDependenciesr   r   ZUtilsr   ZCompilerr	   rG   rg   	cpu_countrh   r   objectr
   r'   r1   r2   r8   rL   rI   ri   rl   r   r   r   r   r   <module>   s0   
	3<
