U
    ef&                     @   s   d dl mZmZ d dlZd dlZd dlZddlmZmZ ddl	m
Z
 ddlmZ z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_importprint_functionN   )	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   s>   zddl m} W n tk
r(   t}Y nX |||D ]}q4d S )Nr   )imap)	itertoolsr   ImportErrormap)selffuncargsr   _ r   :/tmp/pip-unpacked-wheel-7k3cqui1/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 r   r   r   r   r   r   	terminate   s    z_FakePool.terminatec                 C   s   d S r   r   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>   t j| \}}t|r6t j|\}}d||f }q||fS )Nz%s/%s)ospathsplitr   )r   base_dirpackage_pathparentr   r   r   find_package_base&   s
    r$   c                 C   s    t tjjt| }t|| d S r   )r   r   r   abspathr   _cython_compile_files)path_patternoptions	all_pathsr   r   r   cython_compile-   s    r*   c                    sf  d }z | D ]}|j r@| tj r0t rDtj  qnd  tj|rdtj|ddg}n|g}t|f|j|j	|j
|j|j|j|j|j|jd	|j}|r|jrt|dkr|jdkr|d krzt|j}W n tk
r   t }Y nX |t fdd|D  qt |f qW n    |d k	r@|   Y nX |d k	rb|  |  d S )Nz**z
*.{py,pyx})	ZnthreadsZexclude_failuresexcludeZcompiler_directivescompile_time_envforcequietdepfilelanguager   c                    s   g | ]} |gfqS r   r   ).0extr!   r   r   
<listcomp>W   s    z)_cython_compile_files.<locals>.<listcomp>)build_inplacer   r   isdirr   dirnamer   r   parallel
keep_goingexcludes
directivesr,   r-   r.   r/   r0   r(   buildlenmultiprocessingZPoolOSErrorr
   r   run_distutilsr   r   )r)   r(   poolr   pathsext_modulesr   r3   r   r&   1   sX    




r&   c                 C   s   zddl m} W nB tk
rR   zddlm} W n tk
rL   tdY nX Y nX | \}}ddg}t }d }z:|rt| tj|d}|d|g |d||d	 W 5 |rt| |rtj|rt	
| X d S )
Nr   )setupzL'distutils' is not available. Please install 'setuptools' for binary builds.	build_ext-i)dirz--build-tempzsetup.py)script_namescript_argsrC   )distutils.corerD   r   
setuptoolsr   getcwdchdirr   r6   shutilrmtreetempfilemkdtempextend)r   rD   r!   rC   rI   cwdtemp_dirr   r   r   r@   e   s2    


r@   c               
   C   s  ddl m} m} ddlm}m}m} | |dd}|jddd	d
i t|dd |jddd	di t|dd |jddddi 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 d%d |jd&d'dd(d)d*d+ |jd,dd-d)d.d+ |jd/d0d1d2d3g d4d5 |jd6d7d8d9d d:d; |jd<d=d>d9d d?d; |jd@dAdBdCt	t
dDt
 p^dEdF |jdGdHdId9d dJd; |jdKdLdMd9d dNd; |jdOdPd9d dQd; |jdRdSdTd9d dUd; |jdVdWd9d dXd; |jdYdZd9d[d\ |jd]d^d_ |S )`Nr   )ArgumentParserRawDescriptionHelpFormatterr   )ParseDirectivesActionParseOptionsActionParseCompileTimeEnvActionaa  Environment variables:
  CYTHON_FORCE_REGEN: if set to 1, forces cythonize to regenerate the output files regardless
        of modification times and changes.
  Environment variables accepted by setuptools are supported to configure the C compiler and build:
  https://setuptools.pypa.io/en/latest/userguide/ext_modules.html#compiler-and-linker-options)formatter_classepilogz-Xz--directivezNAME=VALUE,...r;   zset a compiler directive)metavardestdefaulttypeactionhelpz-Ez--compile-time-envr,   z'set a compile time environment variablez-sz--optionz
NAME=VALUEr(   zset a cythonize optionz-2language_levelstore_constz#use Python 2 syntax mode by default)r]   r`   constr^   ra   z-3   z#use Python 3 syntax mode by default)r]   r`   rd   ra   z--3str3strz-+z--cplusr0   zc++zCompile as C++ rather than Cz-az
--annotater^   annotatez/Produce a colorized HTML version of the source.)r`   rd   r]   ra   z--annotate-fullcZfullczZProduce a colorized HTML version of the source which includes entire generated C/C++-code.z-xz	--excludeZPATTERNr:   appendz2exclude certain file patterns from the compilation)r\   r]   r`   r^   ra   z-bz--buildr<   
store_truez2build extension modules using distutils/setuptools)r]   r`   r^   ra   rF   z	--inplacer5   zHbuild extension modules in place using distutils/setuptools (implies -b)z-jz
--parallelr8   Nz+run builds in N parallel jobs (default: %d)r   )r]   r\   r_   r^   ra   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-goingr9   z8compile as much as possible, ignore compilation failuresz--no-docstringsno_docstringszstrip docstringsz-Mz	--depfilez produce depfiles for the sources)r`   ra   sources*)nargs)argparserU   rV   ZCompiler.CmdLinerW   rX   rY   add_argumentstrintparallel_compiles)rU   rV   rW   rX   rY   parserr   r   r   create_args_parser   s    

  
  
    rv   c                 C   sN   |  |\}}|j}|D ](}|dr6| d|  q|| q|`||fS )N-zunknown option )parse_known_argsrm   
startswitherrorrh   )ru   r   r(   unknownrm   optionr   r   r   parse_args_raw   s    
r}   c                 C   s   t  }t|| \}} | s"|d |jr.d|_td kr<d|_|jr\|jdksPt|j|j	d< |j
rndt_dt_|jr||jt_|jrdt_|| fS )Nzno source files providedTr   )r   re   rf   rb   F)rv   r}   rz   r5   r<   r>   r8   rb   AssertionErrorr(   rk   r	   Zerror_on_unknown_namesZerror_on_uninitializedrg   rl   Z
docstrings)r   ru   r(   r   r   r   
parse_args   s&    
r   c                 C   sv   t | \}}g }|D ]R}dd t|D }|s\dd l}td|jd ||jd |d || qt	|| d S )Nc                 S   s   g | ]}t j|qS r   )r   r   r%   )r1   pr   r   r   r4      s     zmain.<locals>.<listcomp>r   z#{}: No such file or directory: '{}')filer   )
r   r   sysprintformatargvstderrexitrR   r&   )r   r(   rB   r)   r   Zexpanded_pathr   r   r   r   main   s    
r   __main__)N)
__future__r   r   r   rN   rP   ZDependenciesr   r   ZUtilsr   ZCompilerr	   r>   rs   	cpu_countrt   r   objectr
   r$   r*   r&   r@   rv   r}   r   r   r   r   r   r   r   <module>   s.   
4C
