o
    j4                     @   s  d dl Zd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 ddl
mZmZ ddlmZ ddlmZ zd dlZW n eyE   dZY nw d	d
 Zdd ZdefddZe	dd Zdd Zdd Zd!ddZdd Zdd Zdd Zd"ddZed kre  dS dS )#    N)defaultdict)contextmanager   )	cythonizeextended_iglob   )is_package_dir)Optionsc                 C   sD   t j| \}}t|rt j|\}}d||f }t|s||fS )Nz%s/%s)ospathsplitr   )r   base_dirpackage_pathparent r   W/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/Cython/Build/Cythonize.pyfind_package_base   s   r   c                 C   s4   t tjjt| }t||}tt| |j	 d S N)
mapr
   r   abspathr   _cython_compile_files_buildlistitemsparallel)path_patternoptions	all_pathsext_modules_by_basedirr   r   r   cython_compile   s   
r   returnc                 C   s   t t}| D ]_}|jr(|}tj|rt|r'tj|}tj|rt|snd }tj|r:tj|ddg}n|g}t	|f|j
|j|j|j|j|j|j|j|jd	|j}|re|jre|| | qt|S )Nz**z
*.{py,pyx})	ZnthreadsZexclude_failuresexcludeZcompiler_directivescompile_time_envforcequietdepfilelanguage)r   r   build_inplacer
   r   isdirr   dirnamejoinr   r   
keep_goingexcludes
directivesr"   r#   r$   r%   r&   r   buildextenddict)r   r   Zext_modules_to_buildr   r   pathsext_modulesr   r   r   r   !   s>   
r   c              	   c   s\    | !}z|V  W n t y   |  |jdd  w W d    d S 1 s'w   Y  d S )NT)Zcancel_futures)KeyboardInterruptZterminate_workersshutdown)pool_cm	proc_poolr   r   r   _interruptible_poolF   s   
"r7   c                    s  t dd | D }|sd S |dkp|d uo|dk }z|rd ntjj|d}W n ttfy3   d}Y nw |rA| D ]}t| q8d S t|t  fdd| D }tjj|tjj	d	 g }|D ]}z|
  W q] ty| }	 z||	 W Y d }	~	q]d }	~	ww |rd
}
|
ddgtt|R 7 }
|
d7 }
dd |D }tjd d dkr|rt|
|t|
|d W d    d S 1 sw   Y  d S )Nc                 s   s    | ]	\}}t |V  qd S r   )len).0_modulesr   r   r   	<genexpr>R   s    z_build.<locals>.<genexpr>r   r   )max_workersTc                    s,   g | ]\}}|D ]}  t||gfqqS r   )Zsubmitrun_distutils)r9   r   r;   extr6   r   r   
<listcomp>i   s    z_build.<locals>.<listcomp>)Zreturn_whenz4Compiling Cython modules failed with these errors:

z
	*  z

c                 S   s   g | ]	}t |tr|qS r   )
isinstance	Exception)r9   excr   r   r   rA   }   s    )      r   )sum
concurrentZfuturesProcessPoolExecutorOSErrorImportErrorr>   r7   waitZFIRST_EXCEPTIONresultBaseExceptionappendr*   r   strsysversion_infoExceptionGroupRuntimeError)r2   r   ZmodcountZserial_execution_moder5   r?   Zcompiler_tasksZworker_exceptionstaskZproc_errZexc_msgZnon_base_exceptionsr   r@   r   r   Q   sT   



"r   c                 C   s
  zddl m} W n ty%   zddlm} W n ty"   tdw Y nw | \}}ddg}t }d }z8|rIt| tj|d}|	d|g |d||d	 W |rgt| |ritj
|rkt| d S d S d S d S |rt| |rtj
|rt| w w w w )
Nr   )setupzL'distutils' is not available. Please install 'setuptools' for binary builds.Z	build_ext-i)dirz--build-tempzsetup.py)script_namescript_argsr2   )Zdistutils.corerW   rL   
setuptoolsr
   getcwdchdirtempfilemkdtempr/   r   r(   shutilrmtree)argsrW   r   r2   r[   cwdtemp_dirr   r   r   r>      sH   


r>   c              	      s   ddl m} || |||dd\}}ddddd	}d
d t| D   fdd}|  t|d@ dks7J |d |t|d  |d }	}
}t| dt| d||	 d||
 d ||	d krvtd|| d||	 d d S d S )Nr   )cymeit	   )repeatg&.>gư>gMbP?g      ?)ZnsecZusecZmsecsecc                 S   s   g | ]\}}||fqS r   r   )r9   unitscaler   r   r   rA          zbenchmark.<locals>.<listcomp>c                    s6    D ]
\}}| |kr nqt d| | dd| S )Nz"Timing is below nanoseconds: {t:f}z.3f )rU   )trk   rj   scalesr   r   format_time   s   zbenchmark.<locals>.format_timer   r   z loops, best of z: z per loop (median: )   z3The timings are likely unreliable. The worst time (z6) was more than four times slower than the best time (z).)ZCython.Build.Inlinerf   reversedr   sortr8   print)codeZ
setup_codeimport_moduler-   rf   ZtimingsnumberZunitsrq   ZfastestZmedianZslowestr   ro   r   	benchmark   s$   $,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@dAdBtd dCdD |jdEdFdBtd dGdD |jdHdIdJdKt	d dLdD |jdMdNdOd9d dPd; |jdQdRdSd9d dTd; |jdUdVd9d dWd; |jdXdYdZd9d d[d; |jd\d]d9d d^d; |jd_d`d9dadb |jdcddde |S )fNr   )ArgumentParserRawDescriptionHelpFormatterr   )ParseDirectivesActionParseOptionsActionParseCompileTimeEnvActiona  Environment variables:
  CYTHON_FORCE_REGEN: if set to 1, forces cythonize to regenerate the output files regardless
        of modification times and changes.
  CYTHON_CACHE_DIR: the base directory containing Cython's caches.
  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   r   z-3rF   z#use Python 3 syntax mode by default)r   r   r   r   z--3strz=use Python 3 syntax mode by default (deprecated alias for -3)z-+z--cplusr&   zc++zCompile as C++ rather than Cz-az
--annotater   annotatez/Produce a colorized HTML version of the source.)r   r   r   r   z--annotate-fullcZfullczZProduce a colorized HTML version of the source which includes entire generated C/C++-code.z-xz	--excludeZPATTERNr,   rP   z2exclude certain file patterns from the compilation)r   r   r   r   r   z-bz--buildr.   
store_truez2build extension modules using distutils/setuptools)r   r   r   r   rX   z	--inplacer'   zHbuild extension modules in place using distutils/setuptools (implies -b)z--timeitr{   Z
CODESTRINGzabuild in place, then compile+run CODESTRING as benchmark in first module's namespace (implies -i))r   r   r   r   r   z--setupbenchmark_setupz6use CODESTRING as pre-benchmark setup code for --benchz-jz
--parallelr   Nz2run builds in N parallel jobs (default: CPU count)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-goingr+   z8compile as much as possible, ignore compilation failuresz--no-docstringsno_docstringszstrip docstringsz-Mz	--depfilez produce depfiles for the sources)r   r   sources*)nargs)
argparser|   r}   ZCompiler.CmdLiner~   r   r   add_argumentrQ   int)r|   r}   r~   r   r   parserr   r   r   create_args_parser   s   


r   c                 C   sN   |  |\}}|j}|D ]}|dr| d|  q|| q|`||fS )N-zunknown option )parse_known_argsr   
startswitherrorrP   )r   rc   r   unknownr   optionr   r   r   parse_args_raw  s   
r   c                 C   s   t  }t|| \}} |jd urd|_n| s|d |jr d|_td u r'd|_|jr7|jdv s1J |j|j	d< |j
r@dt_dt_|jrG|jt_|jrMdt_|| fS )NTzno source files providedr   )r   rF   Z3strr   F)r   r   r{   r'   r   r.   multiprocessingr   r   r   r   r	   Zerror_on_unknown_namesZerror_on_uninitializedr   r   Z
docstrings)rc   r   r   r   r   r   
parse_args  s*   

r   c           
      C   s   t | \}}g }|D ]%}dd t|D }|s*tdtjd |tjd td || q
t	||}|rD|j
rDtt| |j |jd ur|d  }}|r\| \}}	|	r\|	d j}|d urgtjd| t|j|j|d |d ur~tj| d S d S d S )Nc                 S   s   g | ]}t j|qS r   )r
   r   r   )r9   pr   r   r   rA   >  rl   zmain.<locals>.<listcomp>z#{}: No such file or directory: '{}'r   )filer   )ry   )r   r   rw   formatrR   argvstderrexitr/   r   r.   r   r   r   r   r{   popitemnamer   insertr   remove)
rc   r   r1   r   r   Zexpanded_pathr   r   ry   Zfirst_extensionsr   r   r   main9  s6   




r   __main__)NNNr   ) concurrent.futuresrI   r
   ra   rR   r_   collectionsr   
contextlibr   ZDependenciesr   r   ZUtilsr   ZCompilerr	   r   rL   r   r   r0   r   r7   r   r>   r{   r   r   r   r   __name__r   r   r   r   <module>   s<    %

6
I
#
