a
    �¥»aXj  ã                   @   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# d dl$Z$da%e$ &¡ Z'e(ƒ Z)dd„ Z*dd„ Z+dd„ Z,e+ede,ƒ dKdd„Z-e+ede-ƒ dLdd„Z.e+ede.ƒ dMdd„Z/e+ede/ƒ dNdd„Z0e+ede0ƒ d d!„ Z1d"d#„ Z2e+ed$e2ƒ dOd%d&„Z3e+ed'e3ƒ dPd)d*„Z4d+d gfd,d-„Z5e+ed.e5ƒ d/d0„ Z6e+ed1e6ƒ d2e
d3< d4e
d5< d6e
d7< d8e
d9< d:e
d;< d<e
d=< e j7d>7  _7ej8d?k�rBd@e
dA< e!ƒ �rBe 9dB¡ dCej7 e_7eZ:dQdDdE„Zee_eZ;dFdG„ Zee_dHD ]0Z<ej= >dIe< dJ ¡Z?e?du�rle@e?dGeƒ �qldS )Ré    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_stringc                 C   sà   | d }t j |¡sdS t|dƒ�}| ¡ }W d  ƒ n1 s@0    Y  t|||ƒ}|d }||krjd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yÚ   Y dS 0 d
S )z®
    Check if an objects needs to be rebuild based on its dependencies

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

    Returns
    -------
    bool
    ú.dTÚrNéÿÿÿÿÚ c                 S   s"   g | ]}|d kr|  d¡s|‘qS )Ú
ú:)Úendswith)Ú.0Úx© r!   úS/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numpy/distutils/ccompiler.pyÚ
<listcomp>D   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&    &r8   c                    s   ‡ fdd„}t | ||ƒ d S )Nc                    s   ˆ | g|¢R i |¤ŽS ©Nr!   )ÚselfÚargsÚkw©Úfuncr!   r"   Ú<lambda>X   ó    z replace_method.<locals>.<lambda>)Úsetattr)ÚklassÚmethod_namer>   Úmr!   r=   r"   Úreplace_methodV   s    rE   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_executablesa   s    rG   Úfind_executablesc              
   C   sò   |du r"|}t |ƒr"d t|ƒ¡}t |¡ z&| jr@t |¡ ntj|tjd� W nJ tj	y„ } z|j
}|j}W Y d}~n&d}~0  tyœ   d}d}Y n0 dS t |ƒr¸d t|ƒ¡}| jrÆt|ƒ t d|¡rØd}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`.

    Returns
    -------
    None

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

    Nú ©Ústderrr@   é   s   Too many open filesz2
Try rerunning setup command until build succeeds.r   z)Command "%s" failed with exit status %d%s)r   r*   Úlistr   ÚinfoÚverboseÚ
subprocessÚcheck_outputÚSTDOUTÚCalledProcessErrorÚoutputÚ
returncoder/   r   ÚreÚsearchr	   )r:   ÚcmdÚdisplayÚexcÚoÚsÚmsgr!   r!   r"   ÚCCompiler_spawno   s4    

ÿr^   Úspawnr   c                 C   sê   |du 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
v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ÚdZobj_namer!   r!   r"   ÚCCompiler_object_filenames°   s&    

rq   Zobject_filenamesc	                    sP  t ƒ }	t�" tdu rt |	¡aW d  ƒ n1 s20    Y  |sDg S ddlm}
m}m} t	ˆ|
ƒr¬g }dD ]4}t
ˆd| ƒ}|du r†qj| d|d |¡f ¡ qjd |¡}nˆj}d	d |¡f }t |¡ ˆ |||||ˆ¡\}}‰‰}ˆ ˆ||¡‰ d
d ˆ ¡ }ˆ�r|dd ˆ¡ 7 }t |¡ ‡ ‡‡‡fdd„}t	ˆ|
ƒ�rît| ¡ ƒ}g g  }}|D ]r}||v �r`|| \}}ˆjdk�r–t|ƒ}t|ƒ}||ƒ�r¾||ƒ�s¾| |||ff¡ n| |||ff¡ �q`|}|D ]}||ƒ �qÜn| ¡ }t|ƒdk�r8|	dk�r8ddl}|j |	¡}| ||¡ | ¡  n|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Ú	is_f_fileÚhas_f90_header)Zf77Zf90ZfixZ	compiler_zFortran %s compiler: %srI   r   zC compiler: %s
zcompile options: '%s'z
extra options: '%s'c                    s  | \}\}}t |ˆ ˆˆƒsd S t�0 |tvrDt |¡ W d   ƒ qnW d   ƒ n1 sX0    Y  t d¡ qzjt�$ ˆ |||ˆ ˆˆ¡ W d   ƒ n1 sž0    Y  W t� t |¡ W d   ƒ n1 sÎ0    Y  n0t� t |¡ W d   ƒ n1 sþ0    Y  0 d S )Ngš™™™™™¹?)	r8   Ú_global_lockÚ_processing_filesÚaddÚtimeÚsleepÚ_job_semaphoreÚ_compileÚremove)r;   r0   Úsrcrn   ©r1   r2   r3   r:   r!   r"   Úsingle_compile+  s    
,4*ÿz)CCompiler_compile.<locals>.single_compileZabsoftr`   )r   ru   rz   Ú	threadingÚ	SemaphoreZnumpy.distutils.fcompilerrr   rs   rt   Ú
isinstanceÚgetattrrj   r*   Úcompiler_sor   rN   Z_setup_compileZ_get_cc_argsrM   ÚkeysÚcompiler_typer   ÚitemsÚlenZmultiprocessing.poolÚpoolZ
ThreadPoolÚmapÚclose)r:   Úsourcesrk   ÚmacrosÚinclude_dirsÚdebugÚextra_preargsr2   ÚdependsÚjobsrr   rs   rt   rY   ZfcZfcompZccompZobjectsÚbuildr   Zobjects_to_buildZf77_objectsZother_objectsr0   r}   rn   Zbuild_itemsr[   Úmultiprocessingr‰   r!   r~   r"   ÚCCompiler_compileß   sh    +(

ÿÿ



r•   Úcompiler!   c                    s  t  d| jjˆ jjf ¡ t| dƒr>d| jd v r>| j d¡ ‡ ‡fdd„}|dƒr`|  ˆ j¡ |d	ƒr„ˆ j	D ]\}}|  
||¡ qn|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-ffp-exception-behavior=strictc                    s   t ˆ | d ƒd uo| ˆvS r9   )rƒ   )Úattr©rX   Úignorer!   r"   Úallow‰  s    z&CCompiler_customize_cmd.<locals>.allowrŽ   ÚdefineÚundefÚ	librariesÚlibrary_dirsÚrpathÚlink_objectsN)r   rN   Ú	__class__Ú__name__Úhasattrr—   rj   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:   rX   r›   rœ   ÚnameÚvalueÚmacror!   rš   r"   ÚCCompiler_customize_cmdn  s,    ÿ
r©   Zcustomize_cmdc                    s    g }d}t | j ¡ ƒ}dD ]}||v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%-r`   zs = %sc                    s   g | ]}ˆ | ‘qS r!   r!   )r   Úprop©Úfmtr!   r"   r#   ®  r@   z'_compiler_to_string.<locals>.<listcomp>r   )
rM   Zexecutablesr…   rj   r¥   rƒ   Úmaxrˆ   Úreprr*   )r—   ÚpropsZmxr…   ÚkeyÚvr5   r!   r¬   r"   Ú_compiler_to_stringŸ  s    

r³   c                 C   sV   z|   ¡  W n ty   Y n0 tjjdk rRt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.

    ra   zP********************************************************************************N)Úget_versionÚ	Exceptionr   Ú_global_logÚ	thresholdÚprintr£   r³   rF   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yD   Y n0 t	| dƒr¬d| j
d v 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 v �s d| j
d v �s d| j
d v �r(d| _nÆtjdk�rîdd
l}dd
l}| ¡ }z”zjtj |d¡}t|dƒ�}	|	 d¡ W d
  ƒ n1 �sŠ0    Y  | j|g|dd|d gd� d| _W n t�yÒ   d| _Y n0 W | |¡ n| |¡ 0 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++r`   Nz#### %s #######Úcompiler_cxxzMissing compiler_cxx fix for r¼   r˜   Tr$   zfile.cÚwzint a;
z-MMDz-MFr   )rk   r�   F)r   rN   r£   r¤   r   r„   r|   ÚAttributeErrorÚ
ValueErrorr¥   r—   r½   rf   ÚreplaceÚwarnZ_auto_dependsr%   r¦   ÚtempfileÚshutilÚmkdtempr&   r*   r(   Úwriter–   r   Úrmtree)
r:   ÚdistZneed_cxxÚaÚbrÃ   rÄ   ZtmpdirÚfnr4   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   rI   r   )rÁ   rV   ÚmatchÚendrW   Úgroup)r:   Úversion_stringÚposrD   ©r›   ÚpatÚstartr!   r"   Úmatcher;  s    z%simple_version_match.<locals>.matcherr!   )rÔ   r›   rÕ   rÖ   r!   rÓ   r"   Úsimple_version_match!  s    r×   Fc           	         s2  |st | dƒr| jS |  ¡  z
| j}W n ty:   Y dS 0 |rH|d sLdS z
| j}W n@ ty–   z
| j‰ W n ty„   Y Y dS 0 ‡ fdd„}Y n0 ztj|tj	d�}W nJ tj
yÞ } z|j}|j}W Y d}~n.d}~0  työ   d}d}Y n0 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ª   )rV   rÎ   rÐ   )rÑ   rD   rª   ©rÔ   r!   r"   rÖ   t  s
    
z&CCompiler_get_version.<locals>.matcherrJ   rL   r@   )r¥   rª   rH   Úversion_cmdr¿   Zversion_matchZversion_patternrP   rQ   rR   rS   rT   rU   r/   r   r   )	r:   ÚforceZ	ok_statusrÙ   rÖ   rT   rZ   Ústatusrª   r!   rØ   r"   ÚCCompiler_get_versionP  sD    





rÜ   r´   c                 C   s’   | j dv r| S t| ƒ}|jd g|jdd…  |_tj d¡rrd|jd v rr|jd |jd g|jd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   r`   NÚaixZ	ld_so_aixra   )r†   r   r½   r„   ÚsysÚplatformrf   Ú	linker_so)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))ú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 u rt  ¡ t jk}| d u r$tj} z"|d u r6t| ƒ}t| \}}}W n6 ty|   d|  }|d urp|d|  }t|ƒ‚Y n0 d| }zt	|ƒ W n’ t
�y$ }	 zxt|	ƒ}t  dt|ƒ¡ |dd … }zt	|ƒ W n: t
�y }	 z t|	ƒ}td| ƒ‚W Y d }	~	n
d }	~	0 0 W Y d }	~	n
d }	~	0 0 ztj| }
t|
ƒ| }W n$ t�yd   td||f ƒ‚Y n0 |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ÚstrrN   r
   rá   ÚmodulesÚvarsrO   r�   )Úplatr—   rO   Údry_runrÚ   Úmodule_nameÚ
class_nameÚlong_descriptionr]   ÚeÚmodulerB   r!   r!   r"   r   Ò  sP    ÿÿ2
ÿr   c                 C   sB   t | |||ƒ}g }|D ]&}t|ƒr2| t|ƒ¡ q| |¡ q|S r9   )Ú_distutils_gen_lib_optionsr   ÚextendrM   rj   )r—   r    Úruntime_library_dirsrŸ   r   Zlib_optsro   r!   r!   r"   r     s    ÿr   )Zmsvc9rÝ   Z_msvcZbcppZcygwincZemxcZunixcz
distutils.r—   )N)r   r   )NNNr   NNN)r!   )r   )rÍ   r   r   )NNNr   r   )Ar%   rV   rá   r+   rx   rP   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€   rz   ÚLockru   Úsetrv   r8   rE   rG   r^   rq   r•   r©   r³   r¹   rÌ   r×   rÜ   rå   Z_default_compilersrâ   rN   Z_distutils_new_compilerrý   Z_ccrô   ÚgetÚ_mrA   r!   r!   r!   r"   Ú<module>   s’   2

?
-   þ
 
/
Q
/C
ÿ     ü
,
