
    ڏDj 6                         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 	 d dlZd	 Zd
 ZdefdZe	d        Zd Zd ZddZd Zd Zd ZddZedk(  r e        yy# e$ r dZY Bw xY w)    N)defaultdict)contextmanager   )	cythonizeextended_iglob   )is_package_dir)Optionsc                     t         j                  j                  |       \  }}t        |      r5t         j                  j                  |      \  }}|d|}t        |      r5||fS )N/)ospathsplitr	   )r   base_dirpackage_pathparents       ZC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\Cython/Build/Cythonize.pyfind_package_baser      sY    WW]]40Hl

"77==2&"(,7 
" \!!    c                     t        t        j                  j                  t	        |             }t        ||      }t        t        |j                               |j                         y N)
mapr   r   abspathr   _cython_compile_files_buildlistitemsparallel)path_patternoptions	all_pathsext_modules_by_basedirs       r   cython_compiler#      sG    BGGOO^L%ABI29gF
4&,,./1A1ABr   returnc                    t        t              }| D ]n  }|j                  rx|}t        j                  j                  |      rt        |      rNt        j                  j                  |      }t        j                  j                  |      s?t        |      rKnd }t        j                  j                  |      r#t        j                  j                  |dd      g}n|g}t        |f|j                  |j                  |j                  |j                  |j                  |j                  |j                   |j"                  |j$                  d	|j&                  }|sM|j(                  s[||   j+                  |       q t-        |      S )Nz**z
*.{py,pyx})	nthreadsexclude_failuresexclude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    ext_modules_to_buildr   r   pathsext_moduless          r   r   r   !   s<   &t, ?  HggmmH-1I77??84 ggmmH-1I H77==WW\\$l;<E FE%%$//$$ ' 2 2$55----OO%% oo 7== *11+>;?> $%%r   c              #      K   | 5 }	 | 	 d d d        y # t         $ r$ |j                          |j                  d        w xY w# 1 sw Y   y xY ww)NT)cancel_futures)KeyboardInterruptterminate_workersshutdown)pool_cm	proc_pools     r   _interruptible_poolrC   F   s_     	 I	O  ! 	'')d3	 s*   AA	A-AAA
Ac                    t        d | D              }|sy |dk(  xs |d uxr |dk  }	 |rd nt        j                  j                  |      }|r| D ]  }t        |        y t              5 }| D cg c]%  \  }}|D ]  }|j                  t        ||gf       ' }	}}}t        j                  j                  |	t        j                  j                         g }
|	D ]  }	 |j                           |
rd}|dj                  d	gt        t         |
            z  }|d
z  }|
D cg c]  }t#        |t$              r| }}t&        j(                  d d dk\  r|rt+        ||      t-        |      |
d   	 d d d        y # t        t
        f$ r d}Y Gw xY wc c}}}w # t        $ r}|
j                  |       Y d }~d }~ww xY wc c}w # 1 sw Y   y xY w)Nc              3   8   K   | ]  \  }}t        |        y wr   )len).0_moduless      r   	<genexpr>z_build.<locals>.<genexpr>R   s     >JAw3w<>s   r   r   )max_workersT)return_whenz4Compiling Cython modules failed with these errors:

z
	*  z

)      r   )sum
concurrentfuturesProcessPoolExecutorOSErrorImportErrorrun_distutilsrC   submitwaitFIRST_EXCEPTIONresultBaseExceptionappendr2   r   str
isinstance	Exceptionsysversion_infoExceptionGroupRuntimeError)r;   r   modcountserial_execution_moderA   extrB   r   rI   compiler_tasksworker_exceptionstaskproc_errexc_msgexcnon_base_exceptionss                   r   r   r   Q   s-   >+>>H$M /-A %)D##77H7M 	  	C#		W	% F &1
 
!'
  ]Xu,=>
>
 
 	J<N<N<^<^_" 	3D3	3 NGx}}b%G3s4E+F%GHHGvG  1#c9- # # #w.3F$W.ABB"7+1B11EE !F F [! % !%%
 ! 3!((223#+F Fsf   $F  -G4*F
AG#F35G(G5G FFG	G(F>9G>GGGc                    	 ddl m} | \  }}ddg}t	        j
                         }d }	 |r>t	        j                  |       t        j                  |      }|j                  d|g        |d||	       |rNt	        j                  |       |r6t        j                  j                  |      rt        j                  |       y y y y # t        $ r# 	 ddlm} n# t        $ r t        d      w xY wY w xY w# |rNt	        j                  |       |r6t        j                  j                  |      rt        j                  |       w w w w xY w)
Nr   )setupzL'distutils' is not available. Please install 'setuptools' for binary builds.	build_ext-i)dirz--build-tempzsetup.py)script_namescript_argsr;   )distutils.corero   rU   
setuptoolsr   getcwdchdirtempfilemkdtempr7   r   r0   shutilrmtree)argsro   r   r;   rt   cwdtemp_dirs          r   rV   rV      s,   n( !Hk%K
))+CH(HHX''H5H9:"##	
 HHSMBGGMM(3h' 4x +  n	n( 	nlmm	n )n* HHSMBGGMM(3h' 4x s6   C AC3 	C0CC0C**C0/C03AEc                    ddl m}  || |||d      \  }}ddddd	}t        |j                               D 	cg c]	  \  }}	|	|f c}	}fd
}
|j	                          t        |      dz  dk(  sJ |d   |t        |      dz     |d   }}}t        | dt        |       d |
|       d |
|       d       ||dz  kD  rt        d |
|       d |
|       d       y y c c}	}w )Nr   )cymeit	   )repeatg&.>gư>gMbP?g      ?)nsecusecmsecsecc                 R    D ]  \  }}| |k\  s n t        d      | |z  dd| S )Nz"Timing is below nanoseconds: {t:f}z.3f )rc   )tscaleunitscaless      r   format_timezbenchmark.<locals>.format_time   sH    ! 	EKE4Ez	E CDDe)S!4&))r   r   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).)Cython.Build.Inliner   reversedr   sortrF   print)code
setup_codeimport_moduler5   r   timingsnumberunitsr   r   r   fastestmedianslowestr   s                 @r   	benchmarkr      s   *T:}jQRSOGV 4cBE/7/FGeudmGF* LLNw<!q  &qz73w<13D+Ewr{WVG	VH$S\N"[5I4JJ]^ijp^q]rrs
tu1*734 5**5g*>)?rC	D ! Hs   C$c            
      ^   ddl m} m} ddlm}m}m}  | |d      }|j                  ddd	d
i t        |d       |j                  ddd	di t        |d       |j                  ddddi t        |d       |j                  ddddd d       |j                  ddddd       |j                  ddddd        |j                  d!d"d#dd$d d%       |j                  d&d'dd(d)d*+       |j                  d,dd-d)d.+       |j                  d/d0d1d2d3g d45       |j                  d6d7d8d9d d:;       |j                  d<d=d>d9d d?;       |j                  d@dAdBt        d dCD       |j                  dEdFdBt        d dGD       |j                  dHdIdJdKt        d dLD       |j                  dMdNdOd9d dP;       |j                  dQdRdSd9d dT;       |j                  dUdVd9d dW;       |j                  dXdYdZd9d d[;       |j                  d\d]d9d d^;       |j                  d_d`d9dab       |j                  dcdde       |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,...r5   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-3rN   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-fullcfullczZProduce a colorized HTML version of the source which includes entire generated C/C++-code.z-xz	--excludePATTERNr4   r\   z2exclude certain file patterns from the compilation)r   r   r   r   r   z-bz--buildr6   
store_truez2build extension modules using distutils/setuptools)r   r   r   r   rq   z	--inplacer/   zHbuild extension modules in place using distutils/setuptools (implies -b)z--timeitr   
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-goingr3   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   Compiler.CmdLiner   r   r   add_argumentr]   int)r   r   r   r   r   parsers         r   create_args_parserr      s    Dgg3a	F m5E'#25  7 2<L-r6D  F j,$bs/3  5 #3MQR\`@  B
#3MQR@  B
'7UVZ  \
ijV[ei;  =
l=	XbL  N
*=V`I  J k9:%rO  Q iglTXO  Q
k^be  g 
lQT^b~  @
	(9<VYcgS  U lSO  Q iglTX0  2
iglTX?  A )LRV_  a
n<^bU  W
)^b-  /
k,Egh
	-Mr   c                     | j                  |      \  }}|j                  }|D ]9  }|j                  d      r| j                  d|z          )|j	                  |       ; |`||fS )N-zunknown option )parse_known_argsr   
startswitherrorr\   )r   r}   r    unknownr   options         r   parse_args_rawr     so    ..t4GWooG  #S!LL*612NN6"	#
 	Wr   c                    t               }t        ||       \  }} |j                  d|_        n| s|j	                  d       |j                  rd|_        t        d|_        |j                  r)|j                  dv sJ |j                  |j                  d<   |j                  rdt        _        dt        _        |j                  r|j                  t        _        |j                  rdt        _        || fS )NTzno source files providedr   )r   rN   3strr   F)r   r   r   r/   r   r6   multiprocessingr   r   r    r   r
   error_on_unknown_nameserror_on_uninitializedr   r   
docstrings)r}   r   r    s      r   
parse_argsr     s    !F"640MGT$ $/0%%77,3,B,B()).&).&"++"D=r   c                 6   t        |       \  }}g }|D ]  }t        |      D cg c]!  }t        j                  j	                  |      # }}|sQt        dj                  t        j                  d   |      t        j                         t        j                  d       |j                  |        t        ||      }|r9|j                  r-t        t        |j!                               |j"                         |j$                  d x}}	|r$|j'                         \  }}
|
r|
d   j(                  }	| t        j                  j+                  d|       t%        |j$                  |j,                  |	       | t        j                  j/                  |       y y y c c}w )Nz#{}: No such file or directory: '{}'r   )filer   )r   )r   r   r   r   r   r   formatr`   argvstderrexitr7   r   r6   r   r   r   r   r   popitemnameinsertr   remove)r}   r    r:   r!   r   pexpanded_pathr"   r   r   first_extensionss              r   mainr   9  s_   %NGUI (5CD5IJ+JJ7>>sxx{DQX[XbXbcHHQK'( 39gF'--t*0023W5E5EF$#''=!)?)G)G)I&H& 0 3 8 8HHOOAx(w66'	

 HHOOH%   % Ks   &F__main__)NNNr   ) concurrent.futuresrQ   r   r{   r`   ry   collectionsr   
contextlibr   Dependenciesr   r   Utilsr	   Compilerr
   r   rU   r   r#   r8   r   rC   r   rV   r   r   r   r   r   __name__ r   r   <module>r      s     	  
  # % 3 " 
"C"& "&J  3Fl(<D<FR> &F zF [
  Os   A3 3A=<A=