U
    ÉZjÞm  ã                   @   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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„ Z-e,ede-ƒ dMdd„Z.e,ede.ƒ dNdd„Z/e,ede/ƒ dOdd„Z0e,ede0ƒ dPdd„Z1e,ede1ƒ d d!„ Z2d"d#„ Z3e,ed$e3ƒ dQd%d&„Z4e,ed'e4ƒ dRd)d*„Z5d+d gfd,d-„Z6e,ed.e6ƒ d/d0„ Z7e,ed1e7ƒ d2e
d3< d4e
d5< d6e
d7< d8e
d9< d:e
d;< d<e
d=< d>e
d?< e j8d@7  _8ej9dAk�rNdBe
dC< e!ƒ �rNe :dD¡ dEej8 e_8eZ;dSdFdG„Zee_eZ<dHdI„ Zee_dJD ]0Z=ej> ?dKe= dL ¡Z@e@dk	�rxeAe@dIeƒ �qxdS )Té    N)Úcopy)Ú	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|dƒ�}| ¡ }W 5 Q R X t|||ƒ}|d }||krVdS d |dd… ¡}	dd„ tj|	dd	�D ƒ}
z2t  	| ¡j
}|
D ]}t  	|¡j
|kr’ W dS q’W n tk
rÈ   Y dS X d
S )z®
    Check if an objects needs to be rebuild based on its dependencies

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

    Returns
    -------
    bool
    ú.dTÚréÿÿÿÿÚ Nc                 S   s"   g | ]}|d kr|  d¡s|‘qS )Ú
ú:)Úendswith)Ú.0Úx© r"   ú\/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/numpy/distutils/ccompiler.pyÚ
<listcomp>E   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_optsZdep_fileÚfÚlinesZcmdlineZlast_cmdlineÚcontentsÚdepsZt_objr"   r"   r#   Ú_needs_build%   s&    r9   c                    s   ‡ fdd„}t | ||ƒ d S )Nc                    s   ˆ | f|ž|ŽS ©Nr"   )ÚselfÚargsÚkw©Úfuncr"   r#   Ú<lambda>Y   ó    z replace_method.<locals>.<lambda>)Úsetattr)ÚklassÚmethod_namer?   Úmr"   r>   r#   Úreplace_methodW   s    rF   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_executablesb   s    rH   Úfind_executablesc           	      C   s^  |dk	r|nt tjƒ}|dkr8|}t|ƒr8d t|ƒ¡}t |¡ z,| jrZt	j
||d� nt	j
|t	j|d� W n” t	jk
rž } z|j}|j}W 5 d}~X Y nj tk
�r } zFd|› d�}z| tjj¡}W n tk
rì   | d¡}Y nX d}W 5 d}~X Y nX dS t|ƒ�r d t|ƒ¡}| j�r0t|ƒ t d	|¡�rDd
}nd}td|||f ƒ‚dS )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)ÚstderrrK   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ÚdisplayrK   ÚexcÚoÚsÚeÚmsgr"   r"   r#   ÚCCompiler_spawnp   s>    

ÿrh   Úspawnr   c                 C   sê   |dkrd}g }|D ]Ð}t j t j |¡¡\}}t j |¡d }|t j |¡d… }| d¡rœ| d¡d }|d|… }	t j t j 	|	¡¡}	|	||d…  }|| j
kr¶td||f ƒ‚|rÆt 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ÚabspathZsrc_extensionsr   r+   Zobj_extensionÚappend)r;   Zsource_filenamesZ	strip_dirÚ
output_dirZ	obj_namesÚsrc_nameÚbaseÚextÚiÚdÚobj_namer"   r"   r#   ÚCCompiler_object_filenames¹   s&    

r|   Zobject_filenamesc	              	      sH  t ƒ }	t� tdkrt |	¡aW 5 Q R X |s0g S ddlm}
m}m} t	ˆ|
ƒr˜g }dD ]4}t
ˆd| ƒ}|dkrrqV| d|d |¡f ¡ qVd |¡}nˆj}d	d |¡f }t |¡ ˆ |||||ˆ¡\}}‰‰}ˆ ˆ||¡‰ d
d ˆ ¡ }ˆ�r
|dd ˆ¡ 7 }t |¡ ‡ ‡‡‡fdd„}t	ˆ|
ƒ�rÚt| ¡ ƒ}g g  }}|D ]r}||k�rL|| \}}ˆjdk�r‚t|ƒ}t|ƒ}||ƒ�rª||ƒ�sª| |||ff¡ n| |||ff¡ �qL|}|D ]}||ƒ �qÈn| ¡ }t|ƒdk�r0|	dk�r0ddlm} ||	ƒ�}| ||¡}W 5 Q R X t|ƒ n|D ]}||ƒ �q4|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Ú	is_f_fileÚhas_f90_header)Zf77Úf90ZfixZ	compiler_zFortran %s compiler: %srJ   r   zC compiler: %s
zcompile options: '%s'z
extra options: '%s'c                    s¢   | \}\}}t |ˆ ˆˆƒsd S t�$ |tkrBt |¡ W 5 Q R £ qXW 5 Q R X t d¡ qz(t� ˆ |||ˆ ˆˆ¡ W 5 Q R X W 5 t� t |¡ W 5 Q R X X d S )Ngš™™™™™¹?)	r9   Ú_global_lockÚ_processing_filesÚaddÚtimeÚsleepÚremoveÚ_job_semaphoreÚ_compile)r<   r1   Úsrcrx   ©r2   r3   r4   r;   r"   r#   Úsingle_compile1  s    
"z)CCompiler_compile.<locals>.single_compileZabsoftrj   )ÚThreadPoolExecutor)r   r�   r‡   Ú	threadingÚ	SemaphoreZnumpy.distutils.fcompilerr}   r~   r   Ú
isinstanceÚgetattrrt   r+   Úcompiler_sor   rR   Z_setup_compileZ_get_cc_argsrQ   ÚkeysÚcompiler_typer   ÚitemsÚlenÚconcurrent.futuresrŒ   Úmap)r;   Úsourcesru   ÚmacrosÚinclude_dirsÚdebugÚextra_preargsr3   ÚdependsÚjobsr}   r~   r   rb   ÚfcZfcompZccompÚobjectsÚbuildr‹   Zobjects_to_buildZf77_objectsZother_objectsr1   r‰   rx   Zbuild_itemsrd   rŒ   ÚpoolÚresr"   rŠ   r#   ÚCCompiler_compileè   sj    (

 ÿÿ




r¤   Úcompiler"   c                    s  t  d| jjˆ jjf ¡ t| dƒrJd| jd krJ| j d¡ | j d¡ ‡ ‡fdd„}|dƒrl|  ˆ j	¡ |d	ƒr�ˆ j
D ]\}}|  ||¡ qz|d
ƒr®ˆ jD ]}|  |¡ qž|dƒrÈ|  | jˆ j ¡ |dƒrâ|  | jˆ j ¡ |dƒrö|  ˆ j¡ |dƒ�r|  ˆ j¡ 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   z-ftrapping-mathc                    s   t ˆ | d ƒd k	o| ˆkS r:   )r�   )Úattr©ra   Úignorer"   r#   Úallow�  s    z&CCompiler_customize_cmd.<locals>.allowrš   ÚdefineÚundefÚ	librariesÚlibrary_dirsÚrpathÚlink_objectsN)r   rR   Ú	__class__Ú__name__Úhasattrr¦   rt   r‘   Zset_include_dirsrš   r¬   Zdefine_macror­   Zundefine_macroZset_librariesr®   Zset_library_dirsr¯   Zset_runtime_library_dirsr°   Zset_link_objectsr±   )r;   ra   rª   r«   ÚnameÚvalueÚmacror"   r©   r#   ÚCCompiler_customize_cmdt  s.    ÿ

r¸   Zcustomize_cmdc                    s    g }d}t | j ¡ ƒ}dD ]}||kr| |¡ q|D ]8}t| |ƒr6t| |ƒ}t|t|ƒƒ}| |t|ƒf¡ q6dt|d ƒ d ‰ ‡ fdd„|D ƒ}d 	|¡S )	Nr   )
Úversionr®   r¯   Zobject_switchZcompile_switchrš   r¬   r­   r°   r±   z%-rj   zs = %sc                    s   g | ]}ˆ | ‘qS r"   r"   )r    Úprop©Úfmtr"   r#   r$   µ  s     z'_compiler_to_string.<locals>.<listcomp>r   )
rQ   Zexecutablesr’   rt   r´   r�   Úmaxr•   Úreprr+   )r¦   ÚpropsZmxr’   ÚkeyÚvr6   r"   r»   r#   Ú_compiler_to_string¦  s    

rÂ   c                 C   sX   z|   ¡  W n tk
r    Y nX tjjdk rTtdƒ t| jƒ tt| ƒƒ tdƒ 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.

    rk   zP********************************************************************************N)Úget_versionÚ	Exceptionr   Ú_global_logÚ	thresholdÚprintr²   rÂ   rG   r"   r"   r#   ÚCCompiler_show_customization¸  s    
rÈ   Zshow_customizationc           
   	   C   sÖ  t  d| jj ¡ t| ƒ |ræz| j d¡ W n ttfk
rF   Y nX t	| dƒr®d| j
d kr®| jsæ| j
d  d¡r€d\}}nd\}}| j
d  ||¡g| j
d	d
…  | _n8t	| dƒrÊt  d| j
f ¡ t	| dƒsæt  d| jj ¡ t	| dƒ�r*d| j
d k�s"d| j
d k�s"d| j
d k�r*d| _n¨tjdk�rÒdd
l}dd
l}| ¡ }zvzTtj |d¡}t|dƒ�}	|	 d¡ W 5 Q R X | j|g|dd|d gd� d| _W n tk
�rÀ   d| _Y nX W 5 | |¡ X 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++rj   Nz#### %s #######Úcompiler_cxxzMissing compiler_cxx fix for rË   r§   Tr%   zfile.cÚwzint a;
z-MMDz-MFr   )ru   rœ   F)r   rR   r²   r³   r   r‘   r†   r^   Ú
ValueErrorr´   r¦   rÌ   rp   ÚreplaceÚwarnZ_auto_dependsr&   rµ   ÚtempfileÚshutilÚmkdtempÚrmtreer'   r+   r)   Úwriter¥   r   )
r;   ÚdistZneed_cxxÚaÚbrÑ   rÒ   ZtmpdirÚfnr5   r"   r"   r#   ÚCCompiler_customizeÕ  sR    
ÿ

ÿþ
ÿ
rÚ   Z	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}ˆr0t ˆ|¡}|s(d S | ¡ }t ˆ||d … ¡}|sLd S ˆ rpt ˆ | d¡¡rp| ¡ }q0qpq0| d¡S )Nr   rJ   r   )rÏ   r_   ÚmatchÚendr`   Úgroup)r;   Úversion_stringÚposrE   ©rª   ÚpatÚstartr"   r#   ÚmatcherB  s    z%simple_version_match.<locals>.matcherr"   )râ   rª   rã   rä   r"   rá   r#   Úsimple_version_match(  s    rå   Fc           	         s:  |st | dƒr| jS |  ¡  z
| j}W n tk
r<   Y dS X |rJ|d sNdS z
| j}W nD tk
rœ   z
| j‰ W n tk
rŠ   Y Y dS X ‡ fdd„}Y nX ztj|tj	d�}W nL tj
k
râ } z|j}|j}W 5 d}~X Y n* tk
� rþ   d}d}Y nX t|ƒ}d}d}||k�r0||ƒ}|�r0t|ƒ}|| _|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¹   )r_   rÜ   rÞ   )rß   rE   r¹   ©râ   r"   r#   rä   {  s
    
z&CCompiler_get_version.<locals>.matcher)rL   rN   rA   )r´   r¹   rI   Úversion_cmdr^   Zversion_matchZversion_patternrT   rU   rV   rW   rX   rY   r0   r   r   )	r;   ÚforceZ	ok_statusrç   rä   rX   rc   Ústatusr¹   r"   ræ   r#   ÚCCompiler_get_versionW  sD    





rê   rÃ   c                 C   sÎ   | j dkr| S t| ƒ}|j|_|jd gt|jdd… ƒ |_tj d¡r|d|jd kr||jd |jd g|jdd…  |_tj d¡r®|j 	d	¡ |j 	d
¡ |j 	d
¡ n|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   rj   N)ÚaixÚos400Z	ld_so_aixrk   rï   z-D__STDC_FORMAT_MACROSz-fno-extern-tls-init)
r“   r   rÌ   r   r‘   r[   Úplatformrp   Ú	linker_sort   )r;   Úcxxr"   r"   r#   ÚCCompiler_cxx_compilerœ  s&    

ÿÿÿró   Zcxx_compiler)ÚintelccompilerZIntelCCompilerz(Intel C Compiler for 32-bit applicationsÚintel)rô   ZIntelItaniumCCompilerz7Intel C Itanium Compiler for Itanium-based applicationsÚintele)rô   ZIntelEM64TCCompilerz(Intel C Compiler for 64-bit applicationsÚintelem)rô   ZIntelCCompilerWz3Intel C Compiler for 32-bit applications on Windowsrì   )rô   ZIntelEM64TCCompilerWz3Intel C Compiler for 64-bit applications on Windowsrí   )ZpathccompilerZPathScaleCCompilerz2PathScale Compiler for SiCortex-based applicationsÚpathcc)ZarmccompilerZArmCCompilerzArm C CompilerÚarm))úlinux.*rõ   )rú   rö   )rú   r÷   )rú   rø   )Úntrì   )rû   rí   Úwin32)Zmingw32ccompilerZMingw32CCompilerz>Mingw32 port of GNU C Compiler for Win32(for MSC built Python)r   z+Setting mingw32 as default compiler for nt.))rû   r   c                 C   sŠ  |d krt  ¡ t jk}| d kr$tj} z"|d kr6t| ƒ}t| \}}}W n8 tk
r~   d|  }|d k	rr|d|  }t|ƒ‚Y nX d| }zt	|ƒ W nŽ t
k
�r" }	 znt|	ƒ}t  dt|ƒ¡ |dd … }zt	|ƒ W n8 t
k
�r }	 zt|	ƒ}td| ƒ‚W 5 d }	~	X Y nX W 5 d }	~	X Y nX ztj| }
t|
ƒ| }W n& tk
�rd   td||f ƒ‚Y nX |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   Zget_thresholdÚINFOr&   rµ   r   r   ÚKeyErrorr   Ú
__import__ÚImportErrorÚstrrR   r
   r[   ÚmodulesÚvarsrS   r›   )Úplatr¦   rS   Údry_runrè   Úmodule_nameÚ
class_nameÚlong_descriptionrg   rf   ÚmodulerC   r"   r"   r#   r   å  sP    ÿÿ*
ÿr   c                 C   sB   t | |||ƒ}g }|D ]&}t|ƒr2| t|ƒ¡ q| |¡ q|S r:   )Ú_distutils_gen_lib_optionsr   ÚextendrQ   rt   )r¦   r¯   Úruntime_library_dirsr®   r   Zlib_optsry   r"   r"   r#   r     s     ÿr   )Zmsvc9rë   Z_msvcZbcppZcygwincZemxcZunixcz
distutils.r¦   )NN)r   r   )NNNr   NNN)r"   )r   )rÛ   r   r   )NNNr   r   )Br&   r_   r[   r,   r„   rT   r   Ú	distutilsr   Údistutils.ccompilerr   r   r   r   r   Údistutils.errorsr	   r
   r   r   r   Údistutils.sysconfigr   Zdistutils.versionr   Znumpy.distutilsr   Znumpy.distutils.exec_commandr   r   Znumpy.distutils.misc_utilr   r   r   r   r   r   r�   r‡   ÚLockr�   Úsetr‚   r9   rF   rH   rh   r|   r¤   r¸   rÂ   rÈ   rÚ   rå   rê   ró   Z_default_compilersrð   rR   Z_distutils_new_compilerr  Z_ccr  ÚgetÚ_mrB   r"   r"   r"   r#   Ú<module>   sš    2

G
-         þ
 
0
Q
/C$
ÿ     ü
,
