o
    Ô­jÊo  ã                   @   sÚ  d dl Z d dlZ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 d dlmZmZmZmZmZ d dlmZmZmZmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZm Z  d dl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d dl(Z(da)e( *¡ Z+e,ƒ Z-dd„ Z.dd„ Z/dd„ Z0e/ede0ƒ dPdd„Z1e/ede1ƒ dQdd„Z2e/ede2ƒ 			dRdd„Z3e/ede3ƒ dSdd„Z4e/ed e4ƒ d!d"„ Z5d#d$„ Z6e/ed%e6ƒ dTd&d'„Z7e/ed(e7ƒ dUd*d+„Z8d,d gfd-d.„Z9e/ed/e9ƒ d0d1„ Z:e/ed2e:ƒ d3ed4< d5ed6< d7ed8< d9ed:< d;ed<< d=ed>< d?ed@< dAedB< e j;dC7  _;ejdDk�r8dEedF< e$ƒ �r8e <dG¡ dHej; e_;eZ=				 	 dVdIdJ„Zee_eZ>dKdL„ Zee_dMD ]Z?ej@ AdNe? dO ¡ZBeBdu�rieCeBdLeƒ �qRdS )Wé    N)Úcopy)ÚPath)Ú	ccompiler)Úcompiler_classÚgen_lib_optionsÚget_default_compilerÚnew_compilerÚ	CCompiler)ÚDistutilsExecErrorÚDistutilsModuleErrorÚDistutilsPlatformErrorÚCompileErrorÚUnknownFileError)Úcustomize_compiler)ÚLooseVersion)Úlog)Úfilepath_from_subprocess_outputÚforward_bytes_to_stdout)Ú	cyg2win32Úis_sequenceÚmingw32Úget_num_build_jobsÚ_commandline_dep_stringÚsanitize_cxx_flagsc                 C   sÜ   | d }t j |¡sdS t|ƒ�}| ¡ }W d  ƒ n1 sw   Y  t|||ƒ}|d }||kr4dS d |dd… ¡}	dd„ tj|	dd�D ƒ}
zt  	| ¡j
}|
D ]}t  	|¡j
|kr` W dS qRW d	S  tym   Y dS w )
z®
    Check if an objects needs to be rebuild based on its dependencies

    Parameters
    ----------
    obj : str
        object file

    Returns
    -------
    bool
    ú.dTNéÿÿÿÿÚ c                 S   s"   g | ]}|d kr|  d¡s|‘qS )Ú
ú:)Úendswith)Ú.0Úx© r"   úV/var/www/html/CropPilot/venv/lib/python3.10/site-packages/numpy/distutils/ccompiler.pyÚ
<listcomp>G   s    ÿz _needs_build.<locals>.<listcomp>)ÚposixF)ÚosÚpathÚexistsÚopenÚ	readlinesr   ÚjoinÚshlexÚsplitÚstatÚst_mtimeÚOSError)ÚobjÚcc_argsÚextra_postargsÚpp_optsÚdep_fileÚfÚlinesÚcmdlineÚlast_cmdlineÚcontentsÚdepsÚt_objr"   r"   r#   Ú_needs_build'   s.   

ÿÿÿüþr=   c                    s   ‡ fdd„}t | ||ƒ d S )Nc                    s   ˆ | g|¢R i |¤ŽS ©Nr"   )ÚselfÚargsÚkw©Úfuncr"   r#   Ú<lambda>[   s    z replace_method.<locals>.<lambda>)Úsetattr)ÚklassÚmethod_namerC   Úmr"   rB   r#   Úreplace_methodY   s   rI   c                 C   s   dS )zÐ
    Does nothing here, but is called by the get_version method and can be
    overridden by subclasses. In particular it is redefined in the `FCompiler`
    class where more documentation can be found.

    Nr"   ©r?   r"   r"   r#   ÚCCompiler_find_executablesd   s   rK   Úfind_executablesc           	      C   sV  |dur|nt tjƒ}|du r|}t|ƒrd t|ƒ¡}t |¡ z| jr/t	j
||d� W dS t	j
|t	j|d� W dS  t	jyS } z|j}|j}W Y d}~n6d}~w ty„ } z&d|› d�}z	| tjj¡}W n tyw   | d¡}Y nw d}W Y d}~nd}~ww t|ƒr�d t|ƒ¡}| jr—t|ƒ t d	|¡r d
}nd}td|||f ƒ‚)aê  
    Execute a command in a sub-process.

    Parameters
    ----------
    cmd : str
        The command to execute.
    display : str or sequence of str, optional
        The text to add to the log file kept by `numpy.distutils`.
        If not given, `display` is equal to `cmd`.
    env : a dictionary for environment variables, optional

    Returns
    -------
    None

    Raises
    ------
    DistutilsExecError
        If the command failed, i.e. the exit status was not 0.

    Nú )Úenv)ÚstderrrN   z

z


Úutf8é   s   Too many open filesz2
Try rerunning setup command until build succeeds.r   z)Command "%s" failed with exit status %d%s)Údictr&   Úenvironr   r+   Úlistr   ÚinfoÚverboseÚ
subprocessÚcheck_outputÚSTDOUTÚCalledProcessErrorÚoutputÚ
returncoder0   ÚencodeÚsysÚstdoutÚencodingÚAttributeErrorr   ÚreÚsearchr
   )	r?   ÚcmdÚdisplayrN   ÚexcÚoÚsÚeÚmsgr"   r"   r#   ÚCCompiler_spawnr   sH   
éê€ÿ€òÿrk   Úspawnr   c                 C   sê   |du rd}g }|D ]h}t j t j |¡¡\}}t j |¡d }|t j |¡d… }| d¡rN| d¡d }|d|… }	t j t j 	|	¡¡}	|	||d…  }|| j
vr[td||f ƒ‚|rct j |¡}t j ||| j ¡}
| |
¡ q
|S )aÞ  
    Return the name of the object files for the given source files.

    Parameters
    ----------
    source_filenames : list of str
        The list of paths to source files. Paths can be either relative or
        absolute, this is handled transparently.
    strip_dir : bool, optional
        Whether to strip the directory from the returned paths. If True,
        the file name prepended by `output_dir` is returned. Default is False.
    output_dir : str, optional
        If given, this path is prepended to the returned paths to the
        object files.

    Returns
    -------
    obj_names : list of str
        The list of paths to the object files corresponding to the source
        files in `source_filenames`.

    Nr   é   z..é   z"unknown file type '%s' (from '%s'))r&   r'   ÚsplitextÚnormpathÚ
splitdriveÚisabsÚ
startswithÚrfindÚbasenameÚabspathÚsrc_extensionsr   r+   Úobj_extensionÚappend)r?   Úsource_filenamesÚ	strip_dirÚ
output_dirÚ	obj_namesÚsrc_nameÚbaseÚextÚiÚdÚobj_namer"   r"   r#   ÚCCompiler_object_filenames»   s&   

r„   Úobject_filenamesc	                    sn  t ƒ }	t� tdu rt |	¡aW d  ƒ n1 sw   Y  |s"g S ddlm}
m}m} t	ˆ|
ƒrVg }dD ]}t
ˆd| ƒ}|du rCq5| d|d |¡f ¡ q5d |¡}nˆj}d	d |¡f }t |¡ ˆ |||||ˆ¡\}}‰‰}ˆ ˆ||¡‰ d
d ˆ ¡ }ˆrŽ|dd ˆ¡ 7 }t |¡ ‡ ‡‡‡fdd„}t	ˆ|
ƒrôt| ¡ ƒ}g g }}|D ]9}||v rç|| \}}ˆjdkrÇt|ƒ}t|ƒ}t|ƒj ¡ |v rÞ||ƒsÞ| |||ff¡ q®| |||ff¡ q®|}|D ]}||ƒ qìn| ¡ }t|ƒdk�r+|	dk�r+ddlm} ||	ƒ�}| ||¡}W d  ƒ n	1 �s w   Y  t|ƒ |S |D ]}||ƒ �q-|S )aÁ  
    Compile one or more source files.

    Please refer to the Python distutils API reference for more details.

    Parameters
    ----------
    sources : list of str
        A list of filenames
    output_dir : str, optional
        Path to the output directory.
    macros : list of tuples
        A list of macro definitions.
    include_dirs : list of str, optional
        The directories to add to the default include file search path for
        this compilation only.
    debug : bool, optional
        Whether or not to output debug symbols in or alongside the object
        file(s).
    extra_preargs, extra_postargs : ?
        Extra pre- and post-arguments.
    depends : list of str, optional
        A list of file names that all targets depend on.

    Returns
    -------
    objects : list of str
        A list of object file names, one per source file `sources`.

    Raises
    ------
    CompileError
        If compilation fails.

    Nr   )Ú	FCompilerÚFORTRAN_COMMON_FIXED_EXTENSIONSÚhas_f90_header)Úf77Úf90ÚfixÚ	compiler_zFortran %s compiler: %srM   r   zC compiler: %s
zcompile options: '%s'z
extra options: '%s'c                    s  | \}\}}t |ˆ ˆˆƒsd S 	 t� |tvr$t |¡ 	 W d   ƒ nW d   ƒ n1 s.w   Y  t d¡ qz7t� ˆ |||ˆ ˆˆ¡ W d   ƒ n1 sQw   Y  W t� t |¡ W d   ƒ d S 1 sjw   Y  d S t� t |¡ W d   ƒ w 1 sƒw   Y  w )NTgš™™™™™¹?)	r=   Ú_global_lockÚ_processing_filesÚaddÚtimeÚsleepÚ_job_semaphoreÚ_compileÚremove)r@   r1   Úsrcr€   ©r2   r3   r4   r?   r"   r#   Úsingle_compile4  s.   
üþ
ø
ÿ€(ÿÿz)CCompiler_compile.<locals>.single_compileÚabsoftrm   )ÚThreadPoolExecutor)r   r�   r’   Ú	threadingÚ	SemaphoreÚnumpy.distutils.fcompilerr†   r‡   rˆ   Ú
isinstanceÚgetattrry   r+   Úcompiler_sor   rU   Ú_setup_compileÚ_get_cc_argsrT   ÚkeysÚcompiler_typer   r   ÚsuffixÚlowerÚitemsÚlenÚconcurrent.futuresr™   Úmap)r?   Úsourcesr|   ÚmacrosÚinclude_dirsÚdebugÚextra_preargsr3   ÚdependsÚjobsr†   r‡   rˆ   re   ÚfcÚfcompÚccompÚobjectsÚbuildr—   Úobjects_to_buildÚf77_objectsÚother_objectsr1   r•   r€   Úbuild_itemsrg   r™   ÚpoolÚresr"   r–   r#   ÚCCompiler_compileê   sx   (
€þ

ÿÿ



ÿ€
ÿ
ÿür¼   Úcompiler"   c                    s(  t  d| jjˆ jjf ¡ t| dƒr0d| jd v r0t ¡ dkr$tjdks0| j 	d¡ | j
 	d¡ ‡ ‡fdd	„}|d
ƒrA|  ˆ j¡ |dƒrSˆ jD ]
\}}|  ||¡ qH|dƒrbˆ jD ]}|  |¡ qZ|dƒro|  | jˆ j ¡ |dƒr||  | jˆ j ¡ |dƒr†|  ˆ j¡ |dƒr’|  ˆ j¡ dS dS )aã  
    Customize compiler using distutils command.

    Parameters
    ----------
    cmd : class instance
        An instance inheriting from `distutils.cmd.Command`.
    ignore : sequence of str, optional
        List of `CCompiler` commands (without ``'set_'``) that should not be
        altered. Strings that are checked for are:
        ``('include_dirs', 'define', 'undef', 'libraries', 'library_dirs',
        'rpath', 'link_objects')``.

    Returns
    -------
    None

    zcustomize %s using %sÚcompilerÚclangr   Úarm64Údarwinz-ftrapping-mathc                    s   t ˆ | d ƒd uo| ˆvS r>   )rž   )Úattr©rd   Úignorer"   r#   Úallowš  s   z&CCompiler_customize_cmd.<locals>.allowr¬   ÚdefineÚundefÚ	librariesÚlibrary_dirsÚrpathÚlink_objectsN)r   rU   Ú	__class__Ú__name__Úhasattrr¾   ÚplatformÚmachiner^   ry   rŸ   Úset_include_dirsr¬   rÆ   Údefine_macrorÇ   Úundefine_macroÚset_librariesrÈ   Úset_library_dirsrÉ   Úset_runtime_library_dirsrÊ   Úset_link_objectsrË   )r?   rd   rÄ   rÅ   ÚnameÚvalueÚmacror"   rÃ   r#   ÚCCompiler_customize_cmdx  s6   ÿÿ
ÿrÛ   Úcustomize_cmdc                    s    g }d}t | j ¡ ƒ}dD ]}||vr| |¡ q|D ]}t| |ƒr7t| |ƒ}t|t|ƒƒ}| |t|ƒf¡ qdt|d ƒ d ‰ ‡ fdd„|D ƒ}d 	|¡S )	Nr   )
ÚversionrÈ   rÉ   Úobject_switchÚcompile_switchr¬   rÆ   rÇ   rÊ   rË   z%-rm   zs = %sc                    s   g | ]}ˆ | ‘qS r"   r"   )r    Úprop©Úfmtr"   r#   r$   ¿  s    z'_compiler_to_string.<locals>.<listcomp>r   )
rT   Úexecutablesr¢   ry   rÎ   rž   Úmaxr§   Úreprr+   )r¾   ÚpropsÚmxr¢   ÚkeyÚvr7   r"   rá   r#   Ú_compiler_to_string°  s    
€

€
rê   c                 C   sZ   z|   ¡  W n	 ty   Y nw tjjdk r+tdƒ t| jƒ tt| ƒƒ tdƒ dS dS )z×
    Print the compiler customizations to stdout.

    Parameters
    ----------
    None

    Returns
    -------
    None

    Notes
    -----
    Printing is only done if the distutils log threshold is < 2.

    rn   zP********************************************************************************N)Úget_versionÚ	Exceptionr   Ú_global_logÚ	thresholdÚprintrÌ   rê   rJ   r"   r"   r#   ÚCCompiler_show_customizationÂ  s   ÿ
ürð   Úshow_customizationc           
   	   C   sø  t  d| jj ¡ t| ƒ |rrz| j d¡ W n ttfy"   Y nw t	| dƒrVd| j
d v rV| jsU| j
d  d¡r?d\}}nd\}}| j
d  ||¡g| j
d	d
…  | _nt	| dƒrdt  d| j
f ¡ t	| dƒsrt  d| jj ¡ t	| dƒr‘d| j
d v sŒd| j
d v sŒd| j
d v r‘d| _d
S tjdkrúdd
l}dd
l}| ¡ }zQz4tj |d¡}t|dƒ�}	|	 d¡ W d
  ƒ n1 sÀw   Y  | j|g|dd|d gd� d| _W n tyã   d| _Y n	w W | |¡ d
S W | |¡ d
S | |¡ w d
S )am  
    Do any platform-specific customization of a compiler instance.

    This method calls `distutils.sysconfig.customize_compiler` for
    platform-specific customization, as well as optionally remove a flag
    to suppress spurious warnings in case C++ code is being compiled.

    Parameters
    ----------
    dist : object
        This parameter is not used for anything.
    need_cxx : bool, optional
        Whether or not C++ has to be compiled. If so (True), the
        ``"-Wstrict-prototypes"`` option is removed to prevent spurious
        warnings. Default is False.

    Returns
    -------
    None

    Notes
    -----
    All the default options used by distutils can be extracted with::

      from distutils import sysconfig
      sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS',
                                'CCSHARED', 'LDSHARED', 'SO')

    zcustomize %sz-Wstrict-prototypesr¾   Úccr   Úgcc)ró   úg++)rò   zc++rm   Nz#### %s #######Úcompiler_cxxzMissing compiler_cxx fix for rô   r¿   Tr%   zfile.cÚwzint a;
z-MMDz-MFr   )r|   r®   F)r   rU   rÌ   rÍ   r   rŸ   r”   ra   Ú
ValueErrorrÎ   r¾   rõ   rs   ÚreplaceÚwarnÚ_auto_dependsr&   rØ   ÚtempfileÚshutilÚmkdtempr'   r+   r)   Úwriter½   r   Úrmtree)
r?   ÚdistÚneed_cxxÚaÚbrû   rü   ÚtmpdirÚfnr6   r"   r"   r#   ÚCCompiler_customizeß  sd   ÿ
ÿ€


ðÿ
ÿ

ÿÿ
ü
þr  Ú	customizeú[-.\d]+c                    s   ‡ ‡‡fdd„}|S )aU  
    Simple matching of version numbers, for use in CCompiler and FCompiler.

    Parameters
    ----------
    pat : str, optional
        A regular expression matching version numbers.
        Default is ``r'[-.\d]+'``.
    ignore : str, optional
        A regular expression matching patterns to skip.
        Default is ``''``, in which case nothing is skipped.
    start : str, optional
        A regular expression matching the start of where to start looking
        for version numbers.
        Default is ``''``, in which case searching is started at the
        beginning of the version string given to `matcher`.

    Returns
    -------
    matcher : callable
        A function that is appropriate to use as the ``.version_match``
        attribute of a `CCompiler` class. `matcher` takes a single parameter,
        a version string.

    c                    sz   |  dd¡}d}ˆrt ˆ|¡}|sd S | ¡ }	 t ˆ||d … ¡}|s'd S ˆ r7t ˆ | d¡¡r7| ¡ }q	 | d¡S )Nr   rM   r   )rø   rb   ÚmatchÚendrc   Úgroup)r?   Úversion_stringÚposrH   ©rÄ   ÚpatÚstartr"   r#   ÚmatcherL  s    
z%simple_version_match.<locals>.matcherr"   )r  rÄ   r  r  r"   r  r#   Úsimple_version_match2  s   r  Fc           	         s.  |s
t | dƒr
| jS |  ¡  z| j}W n
 ty   Y dS w |r$|d s&dS z| j}W n  tyK   z| j‰ W n tyB   Y Y dS w ‡ fdd„}Y nw z
tj|tj	d�}W n% tj
yo } z|j}|j}W Y d}~nd}~w ty{   d}d}Y nw t|ƒ}d}d}||v r’||ƒ}|r’t|ƒ}|| _|S )	a…  
    Return compiler version, or None if compiler is not available.

    Parameters
    ----------
    force : bool, optional
        If True, force a new determination of the version, even if the
        compiler already has a version attribute. Default is False.
    ok_status : list of int, optional
        The list of status values returned by the version look-up process
        for which a version string is returned. If the status value is not
        in `ok_status`, None is returned. Default is ``[0]``.

    Returns
    -------
    version : str or None
        Version string, in the format of `distutils.version.LooseVersion`.

    rÝ   Nr   c                    s"   t  ˆ | ¡}|s
d S | d¡}|S )NrÝ   )rb   r	  r  )r  rH   rÝ   ©r  r"   r#   r  …  s
   
z&CCompiler_get_version.<locals>.matcher)rO   rQ   ó    )rÎ   rÝ   rL   Úversion_cmdra   Úversion_matchÚversion_patternrW   rX   rY   rZ   r[   r\   r0   r   r   )	r?   ÚforceÚ	ok_statusr  r  r[   rf   ÚstatusrÝ   r"   r  r#   ÚCCompiler_get_versiona  sN   
ÿ

ÿû€ür  rë   c                 C   sÐ   | j dv r| S t| ƒ}|j|_|jd gt|jdd… ƒ |_tj d¡r>d|jd v r>|jd |jd g|jdd…  |_tj d¡rX|j 	d	¡ |j 	d
¡ |j 	d
¡ |S |jd g|jdd…  |_|S )z²
    Return the C++ compiler.

    Parameters
    ----------
    None

    Returns
    -------
    cxx : class instance
        The C++ compiler, as a `CCompiler` instance.

    )ÚmsvcÚintelwÚintelemwr   rm   N)ÚaixÚos400Ú	ld_so_aixrn   r   z-D__STDC_FORMAT_MACROSz-fno-extern-tls-init)
r£   r   rõ   r   rŸ   r^   rÏ   rs   Ú	linker_sory   )r?   Úcxxr"   r"   r#   ÚCCompiler_cxx_compiler¦  s&   

ÿÿÿr$  Úcxx_compiler)ÚintelccompilerÚIntelCCompilerz(Intel C Compiler for 32-bit applicationsÚintel)r&  ÚIntelItaniumCCompilerz7Intel C Itanium Compiler for Itanium-based applicationsÚintele)r&  ÚIntelEM64TCCompilerz(Intel C Compiler for 64-bit applicationsÚintelem)r&  ÚIntelCCompilerWz3Intel C Compiler for 32-bit applications on Windowsr  )r&  ÚIntelEM64TCCompilerWz3Intel C Compiler for 64-bit applications on Windowsr  )ÚpathccompilerÚPathScaleCCompilerz2PathScale Compiler for SiCortex-based applicationsÚpathcc)ÚarmccompilerÚArmCCompilerzArm C CompilerÚarm)ÚfujitsuccompilerÚFujitsuCCompilerzFujitsu C CompilerÚfujitsu))úlinux.*r(  )r8  r*  )r8  r,  )r8  r1  )Úntr  )r9  r  Úwin32)Úmingw32ccompilerÚMingw32CCompilerz>Mingw32 port of GNU C Compiler for Win32(for MSC built Python)r   z+Setting mingw32 as default compiler for nt.))r9  r   c                 C   sp  |d u rt  ¡ t jk}| d u rtj} z|d u rt| ƒ}t| \}}}W n ty<   d|  }|d ur8|d|  }t|ƒ‚w d| }zt	|ƒ W nA t
yˆ }	 z5t|	ƒ}t  dt|ƒ¡ |dd … }zt	|ƒ W n t
y} }	 z
t|	ƒ}td| ƒ‚d }	~	ww W Y d }	~	nd }	~	ww ztj| }
t|
ƒ| }W n ty¥   td||f ƒ‚w |d ||ƒ}||_t  d| ¡ |S )	Nz5don't know how to compile C/C++ code on platform '%s'z with '%s' compilerznumpy.distutils.z,%s in numpy.distutils; trying from distutilsé   z4can't compile C/C++ code: unable to load module '%s'zBcan't compile C/C++ code: unable to find class '%s' in module '%s'znew_compiler returns %s)r   Úget_thresholdÚINFOr&   rØ   r   r   ÚKeyErrorr   Ú
__import__ÚImportErrorÚstrrU   r   r^   ÚmodulesÚvarsrV   r­   )Úplatr¾   rV   Údry_runr  Úmodule_nameÚ
class_nameÚlong_descriptionrj   ri   ÚmodulerF   r"   r"   r#   r   ñ  s^   üÿÿ€þÿ€ú
ÿÿr   c                 C   sB   t | |||ƒ}g }|D ]}t|ƒr| t|ƒ¡ q| |¡ q|S r>   )Ú_distutils_gen_lib_optionsr   ÚextendrT   ry   )r¾   rÉ   Úruntime_library_dirsrÈ   ÚrÚlib_optsr�   r"   r"   r#   r      s   ÿr   )Úmsvc9r  Ú_msvcÚbcppÚcygwincÚemxcÚunixcz
distutils.r¾   )NN)r   r   )NNNr   NNN)r"   )r   )r  r   r   )NNNr   r   )Dr&   rb   r^   rÏ   r,   r�   rW   r   Úpathlibr   Ú	distutilsr   Údistutils.ccompilerr   r   r   r   r	   Údistutils.errorsr
   r   r   r   r   Údistutils.sysconfigr   Údistutils.versionr   Únumpy.distutilsr   Únumpy.distutils.exec_commandr   r   Únumpy.distutils.misc_utilr   r   r   r   r   r   rš   r’   ÚLockr�   ÚsetrŽ   r=   rI   rK   rk   r„   r¼   rÛ   rê   rð   r  r  r  r$  Ú_default_compilersrU   Ú_distutils_new_compilerrL  Ú_ccrD  ÚgetÚ_mrE   r"   r"   r"   r#   Ú<module>   s      2

G
-
þ 
6
Q
/C$
ÿ
ü,
€ý