
    gV                        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m	Z	m
Z
 ddlmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZ ej        dk    rdZn8ej        dk    rd	Zn* ej        d
                    ej                             dZ	 	 ddZd dZ 	 	 d!dZ!	 	 d"dZ"d#dZ#edfedfedfedfedfedfedfedfedfedfd
Z$d$dZ%	 	 d%dZ&d Z'd Z(d Z)	 	 d&dZ*d Z+d'dZ,d(dZ-dS ))    N)get_config_varget_config_varsget_path   )CCompilerRunnerCppCompilerRunnerFortranCompilerRunner)get_abspath	make_dirscopyGlobArbitraryDepthGlobglob_at_depthimport_module_from_filepyx_is_cplussha256_of_stringsha256_of_fileCompileErrorposixz.ontz.objzUnknown os.name: {}Fc                    i }||                                 D ]t\  }}	t          |t                    r"t          j        |j                  D ]}
|	||
<   <t          |t
                    rt          |j        |          D ]}
|	||
<   o|	||<   u|pd}t          j	        
                    |          sPt          j	                            |          r"t          d                    |                    t          |           |d}| D ]}t          ||dd           g }| D ]}|r#t          j	                            |          \  }}n?t          j	                            t          j	                            |                    \  }}|                                }|                    |                    |i                      |                    t+          ||fd|i|           |S )a   Compile source code files to object files.

    Parameters
    ==========

    files : iterable of str
        Paths to source files, if ``cwd`` is given, the paths are taken as relative.
    Runner: CompilerRunner subclass (optional)
        Could be e.g. ``FortranCompilerRunner``. Will be inferred from filename
        extensions if missing.
    destdir: str
        Output directory, if cwd is given, the path is taken as relative.
    cwd: str
        Working directory. Specify to have compiler run in other directory.
        also used as root of relative paths.
    keep_dir_struct: bool
        Reproduce directory structure in `destdir`. default: ``False``
    per_file_kwargs: dict
        Dict mapping instances in ``files`` to keyword arguments.
    \*\*kwargs: dict
        Default keyword arguments to pass to ``Runner``.

    Returns
    =======
    List of strings (paths of object files).
    N.z{} is not a directoryT)only_updatedest_is_dircwd)items
isinstancer   globpathnamer   r   filenameospathisdirexistsOSErrorformatr   r   splitextbasenameupdategetappendsrc2obj)filesRunnerdestdirr   keep_dir_structper_file_kwargskwargs_per_file_kwargskvr"   fdstpathsnameextfile_kwargss                   d/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/utilities/_compilation/compilation.pycompile_sourcesr<      s   8 "#))++ 	( 	(DAq!T"" ( Iaj11 / /D-.$T**/A122 ()!*c:: / /D-.$T**/ '( ## nG7==!! 7>>'"" 	188AABBBg
{ 	A 	AAG4@@@@@ H D D 	>((++ID##(()9)9!)<)<==ID#kkmm+//2667776BBsBkBBCCCCO    c                    | pt           j                            dd          } |                                 dk    r|rt          dddgi| fS t          ddgi| fS |                                 dk    s	 |rt
          dd	gi| fS t          i | fS )
NSYMPY_COMPILER_VENDORgnuintelflagsz-nofor_mainz-cxxlibllvmlib_optionsfortran)r!   environr*   lowerr	   r   
ValueErrorvendorcplusr   s      r;   get_mixed_fort_c_linkerrL   `   s    Erz~~&=uEEF||~~   	8)}i896C C *}o.8 8	5	 	 	  	 %"YK0&: : *   r=   c                    |Yt           j                            t           j                            | d                             \  }}	|r|t	          d          z  }|s}|rjt          |                    dd          ||          \  }}
}|
                                D ]*\  }}||v r||                             |           %|||<   +n|rt          }nt          }|                    dg           }|rd|vr|                    d           |                    dd	          }|st          d
          t          ||          } || |pg z   ||fd|i|}|                                 |S )a   Link object files.

    Parameters
    ==========

    obj_files: iterable of str
        Paths to object files.
    out_file: str (optional)
        Path to executable/shared library, if ``None`` it will be
        deduced from the last item in obj_files.
    shared: bool
        Generate a shared library?
    Runner: CompilerRunner subclass (optional)
        If not given the ``cplus`` and ``fort`` flags will be inspected
        (fallback is the C compiler).
    cwd: str
        Path to the root of relative paths and working directory for compiler.
    cplus: bool
        C++ objects? default: ``False``.
    fort: bool
        Fortran objects? default: ``False``.
    extra_objs: list
        List of paths to extra object files / static libraries.
    \*\*kwargs: dict
        Keyword arguments passed to ``Runner``.

    Returns
    =======

    The absolute path to the generated shared object / executable.

    N
EXT_SUFFIXrJ   rI   rB   z-shared
run_linkerTz*run_linker was set to False (nonsensical).r   r   )r!   r"   r'   r(   r   rL   r*   r   expandr   r   popr+   rH   r
   run)	obj_filesout_filesharedr.   r   rK   fort
extra_objsr2   r9   extra_kwargsrJ   r4   r5   rB   rP   runners                    r;   linkr\   u   s   D (()9)9)B-)H)HII# 	5|444H ) 	)'!::h55   )FL& %**,, " "1;;1I$$Q'''' !F1II	"  )*(JJw##E $E!!LL###L$//J GEFFF8---HVIz/R0(EUUsUfUUF
JJLLLOr=   c                    |pg }|                     dg           }|                     dg           }	t          j        dk    rt          j        d           nt          j        dk    rt                      }
|                    dg           |
d         gz   |d<   |	|
d         gz  }	d	}|
d
                                         D ]o}|r!|                    dg           d|gz   |d<   d	}%|                    d          r|	                    |dd                    X|                    d          rd}p|
d         }d
                    |                    d          dd                   dd         }|	                    |           nt          j        dd         dk    rnt          d          r~t                      }
|                    dg           |
d         gz   |d<   |	|
d         gz  }	|
d                                         D ]%}|                    d          r||dd         gz  }&n	 |                     dg           }d}|D ]}||vr|	                    |           t          | fd|||||||	|d	|S )a   Link Python extension module (shared object) for importing

    Parameters
    ==========

    obj_files: iterable of str
        Paths to object files to be linked.
    so_file: str
        Name (path) of shared object file to create. If not specified it will
        have the basname of the last object file in `obj_files` but with the
        extension '.so' (Unix).
    cwd: path string
        Root of relative paths and working directory of linker.
    libraries: iterable of strings
        Libraries to link against, e.g. ['m'].
    cplus: bool
        Any C++ objects? default: ``False``.
    fort: bool
        Any Fortran objects? default: ``False``.
    extra_objs: list
        List of paths of extra object files / static libraries to link against.
    kwargs**: dict
        Keyword arguments passed to ``link(...)``.

    Returns
    =======

    Absolute path to the generate shared object.
    include_dirslibrary_dirswin32zWindows not yet supported.darwinlinklineLDFLAGSLIBDIRFLIBSz
-frameworkz-l   NTLIBRARYr   rN      aixPy_ENABLE_SHARED
BLDLIBRARYrB   )-pthread)	rW   rB   r   rK   rX   r^   	librariesr_   rY   )rS   sysplatformwarningswarnr   r*   split
startswithr+   joinr   r\   )rU   so_filer   rm   rK   rX   rY   r2   r^   r_   cfgDictis_frameworkoptlibfilelibnamerB   needed_flagsflags                     r;   
link_py_sor}      s   > RI::nb11L::nb11L
 |w23333		!	!!###ZZ
B7779;M:NNz*++ 6?((** 	$ 	$C $%+ZZ
B%?%?<QTBU%Uz"$%% $  QRR))))-- $#)$((7==--crc233ABB7!!!!	bqb	U	"	",-- 	%''G!'J!;!;wy?Q>R!RF:WX.//L|,2244 + +>>$'' +#abb'*I+ JJw##E L  uLL	 L$eEPT)Y)jL LDJL L Lr=   c                    ddl m}m} ddl m} |                                                     d          s)|                                                     d          sJ |pd}|pd}|                    dd          rd	nd
}t          j        	                    t          j        
                    |                     d         |z   }t          j                            ||          }	|rt          j                    }
nd}
t          j        |           	  ||          }|j                            |           d|vr
d|j        d<    || g|          }|j        dk    rt#          d          t          j                            t          j                            |                     t          j                            |          k    rt          j                            |	          rt          j        |	           t-          j        t          j                            t          j                            |           |          |           t          j        |
           n# t          j        |
           w xY w|	S )a   Generates a C file from a Cython source file.

    Parameters
    ==========

    src: str
        Path to Cython source.
    destdir: str (optional)
        Path to output directory (default: '.').
    cwd: path string (optional)
        Root of relative paths (default: '.').
    **cy_kwargs:
        Second argument passed to cy_compile. Generates a .cpp file if ``cplus=True`` in ``cy_kwargs``,
        else a .c file.
    r   )default_optionsCompilationOptions)compile.pyxz.pyr   rK   F.cpp.clanguage_levelrh   zCython compilation failed.)Cython.Compiler.Mainr   r   r   rG   endswithr*   r!   r"   r'   r(   rt   getcwdchdir__dict__r)   
num_errorsrH   realpathdirnamer$   unlinkshutilmove)srcr/   r   	cy_kwargsr   r   
cy_compiler9   c_namedstfileori_dir
cy_options	cy_results                r;   simple_cythonizer     sJ            ;:::::99;;''F399;;+?+?+F+FFFF
*CnGMM'511
;&&tCWbg..s3344Q7#=Fgll7F++G
 )++HSMMM''88
""9--- 9,,45J 01Juj11	!##9:::
 7BGOOC0011RW5E5Eg5N5NNNw~~g&& #	'"""KRW__S%9%96BBGLLL
Ns   D:I" "I8f95f2003f2008)
r   r   z.cxxz.fz.forz.ftnz.f90z.f95z.f03z.f08c                    t           j                            t           j                            |                     \  }}|Et           j                            |           rd}n#t           j                            |           }|pd}t           j                            |          r(t           j                            ||t          z             }|	                    dg           }|r(t          d          }	|	|vr|                    |	           |                                dk    rt          | f|||d|S |+t          |                                         \  }}
d|vr|
|d<   |	                    dg           }d	}|D ]}||vr|                    |           |	                    d
d          }|rt          d           || g|f||||d|}|                                 |S )a   Compiles a source code file to an object file.

    Files ending with '.pyx' assumed to be cython files and
    are dispatched to pyx2obj.

    Parameters
    ==========

    srcpath: str
        Path to source file.
    Runner: CompilerRunner subclass (optional)
        If ``None``: deduced from extension of srcpath.
    objpath : str (optional)
        Path to generated object. If ``None``: deduced from ``srcpath``.
    cwd: str (optional)
        Working directory and root of relative paths. If ``None``: current dir.
    inc_py: bool
        Add Python include path to kwarg "include_dirs". Default: False
    \*\*kwargs: dict
        keyword arguments passed to Runner or pyx2obj

    Nr   r^   includer   )objpathr^   r   stdrB   )-fPICrP   Fz#src2obj called with run_linker=True)r^   rP   r   rB   )r!   r"   r'   r(   isabsr   r#   rt   objextrS   r   r+   rG   pyx2objextension_mappingr   rT   )srcpathr.   r   r   inc_pyr2   r8   r9   r^   
py_inc_dirr   rB   r{   r|   rP   r[   s                   r;   r,   r,   \  s   .   !1!1'!:!:;;ID#7==!! 	%GGgoog..GnG	w}}W 7',,wv66::nb11L ,i((
\))
+++
yy{{fw !lPS ! !! ! 	! ~'		4F5MJJw##EL  uLL L%00J B@AAAVWIw K\)s%K KCIK KF
JJLLLNr=   c                    |                      d          sJ |pd}|pd}|pt          j                            |          }t	          ||          }t          j                            |          rit          j                            |           }	t          j                            |	          \  }
}t          j                            ||
t          z             }|pi }||d<   |t          |           }||d<   t          | f||d|}|pg }|                    dg           }d	}|D ]}||vr|                    |           |                    d
g           }|                    dd          rt          d          |r|                    dd          }n|                    dd          }t          |f||||||ddd|S )a9  
    Convenience function

    If cwd is specified, pyxpath and dst are taken to be relative
    If only_update is set to `True` the modification time is checked
    and compilation is only run if the source is newer than the
    destination

    Parameters
    ==========

    pyxpath: str
        Path to Cython source file.
    objpath: str (optional)
        Path to object file to generate.
    destdir: str (optional)
        Directory to put generated C file. When ``None``: directory of ``objpath``.
    cwd: str (optional)
        Working directory and root of relative paths.
    include_dirs: iterable of path strings (optional)
        Passed onto src2obj and via cy_kwargs['include_path']
        to simple_cythonize.
    cy_kwargs: dict (optional)
        Keyword arguments passed onto `simple_cythonize`
    cplus: bool (optional)
        Indicate whether C++ is used. default: auto-detect using ``.util.pyx_is_cplus``.
    compile_kwargs: dict
        keyword arguments passed onto src2obj

    Returns
    =======

    Absolute path of generated object file.

    r   r   rQ   
output_dirNrK   r/   r   rB   )z-fwrapvrl   r   optionsstrict_aliasingFz/Cython requires strict aliasing to be disabled.r   zc++98c99T)r   r   r^   rB   r   r   r   r   )r   r!   r"   r   r
   r#   r(   r'   rt   r   r   r   rS   r+   r   r,   )pyxpathr   r/   r   r^   r   rK   r2   abs_objpath	pyx_fnamer8   r9   interm_c_filerB   r{   r|   r   r   s                     r;   r   r     s   J F#####
*CnG111Gg3///K	w}}[!! 7G$$W--	G$$Y//	c',,wv66RI!Il}W%%Ig$WTg3TT)TTM%2LJJw##E3L  uLLjjB''Gzz#U++ NLMMM  'jj((jj&&= 's ,Es"4    r=   c                     | D ][}t           j                            |          \  }}|                                }|t          v rt          |         d         |k    r dS \dS )Nr   TF)r!   r"   r'   rG   r   )srcsclsr   r8   r9   keys         r;   _any_Xr     se      G$$S))	ciikk### %a(C//tt5r=   c                 ,    t          | t                    S N)r   r	   r   s    r;   any_fortran_srcr     s    $-...r=   c                 ,    t          | t                    S r   )r   r   r   s    r;   any_cplus_srcr     s    $)***r=   r   c           	          |Ht           j                            t           j                            | d                             d         }|pi }|pi }	 t	          t           j                            ||          |           }n{# t          $ rn t          t          t          t          |                     f||d|}t          |f|t          |           t          |           |d|}t	          |          }Y nw xY w|S )a~   Compiles sources to a shared object (Python extension) and imports it

    Sources in ``sources`` which is imported. If shared object is newer than the sources, they
    are not recompiled but instead it is imported.

    Parameters
    ==========

    sources : list of strings
        List of paths to sources.
    extname : string
        Name of extension (default: ``None``).
        If ``None``: taken from the last file in ``sources`` without extension.
    build_dir: str
        Path to directory in which objects files etc. are generated.
    compile_kwargs: dict
        keyword arguments passed to ``compile_sources``
    link_kwargs: dict
        keyword arguments passed to ``link_py_so``
    extra_objs: list
        List of paths to (prebuilt) object files / static libraries to link against.

    Returns
    =======

    The imported module from of the Python extension.
    NrN   r   r   )r   rX   rK   rY   )r!   r"   r'   r(   r   rt   ImportErrorr<   listmapr
   r}   r   r   )	sourcesextname	build_dircompile_kwargslink_kwargsrY   modobjssos	            r;   compile_link_import_py_extr     s$   : '""27#3#3GBK#@#@AA!D#)rN#K*%bgll9g&F&FPP * * *tCW$=$=>> @	#,@ @0>@ @ \)/'2J2J+G44\ \OZ\ \%b))* Js   .B A5C;:C;c                    |pt          j                    }t          j                            |          st          d|          g }| D ]\  }}t          j                            ||          }d}t          |                    d                    	                                }t          j        
                    |          rt          j        
                    |dz             r?t          |dz             5 }|                                }	d d d            n# 1 swxY w Y   n!t          |          	                                }	|	|k    }|r}t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          |dz   d          5 }|                    |           d d d            n# 1 swxY w Y   |                    |           ||fS )NzNon-existent directory: Tutf-8z.sha256wt)tempfilemkdtempr!   r"   r#   r%   rt   r   encode	hexdigestr$   openreadr   writer+   )
r   r   source_filesr8   r   destdifferssha256_in_memfhsha256_on_disks
             r;   _write_sources_to_build_dirr   /  sq   /X-//I7==## =0)<<<L " "	cw||It,,(G)<)<==GGII7>>$ 	6w~~dY.// B$*++ /r%'WWYYN/ / / / / / / / / / / / / / / "0!5!5!?!?!A!A$5G 	(dD!! R              dY&-- ('''( ( ( ( ( ( ( ( ( ( ( ( ( ( (D!!!!""s6   8DD	 D	F  F	F	G  G	G	c                 V    t          | |          \  }}t          |fd|i|}d|i}||fS )a   Compiles, links and imports extension module from source.

    Parameters
    ==========

    sources : iterable of name/source pair tuples
    build_dir : string (default: None)
        Path. ``None`` implies use a temporary directory.
    **kwargs:
        Keyword arguments passed onto `compile_link_import_py_ext`.

    Returns
    =======

    mod : module
        The compiled and imported extension module.
    info : dict
        Containing ``build_dir`` as 'build_dir'.

    r   )r   r   )r   r   r2   r   r   infos         r;   compile_link_import_stringsr   J  sF    * :'9MML)
$\
Q
QY
Q&
Q
QC#D9r=   c                    |r|t          d          	 t          | |          \  }}t          t          t	          t
          |                    f||d|pi }t          |f|t          |          t          |          d|pi }t          j
        |gt          j        t          j                  }|                                }	d |                                D             \  }
}|r5t          j                            |          rt#          j        |           d}n<# |r5t          j                            |          rt#          j        |           d}w xY w|	|d}|
|f|fS )ay   Compiles, links and runs a program built from sources.

    Parameters
    ==========

    sources : iterable of name/source pair tuples
    build_dir : string (default: None)
        Path. ``None`` implies use a temporary directory.
    clean : bool
        Whether to remove build_dir after use. This will only have an
        effect if ``build_dir`` is ``None`` (which creates a temporary directory).
        Passing ``clean == True`` and ``build_dir != None`` raises a ``ValueError``.
        This will also set ``build_dir`` in returned info dictionary to ``None``.
    compile_kwargs: dict
        Keyword arguments passed onto ``compile_sources``
    link_kwargs: dict
        Keyword arguments passed onto ``link``

    Returns
    =======

    (stdout, stderr): pair of strings
    info: dict
        Containing exit status as 'exit_status' and ``build_dir`` as 'build_dir'

    NzIAutomatic removal of build_dir is only available for temporary directory.r   )r   rX   rK   )stdoutstderrc                 8    g | ]}|                     d           S )r   )decode).0txts     r;   
<listcomp>z'compile_run_strings.<locals>.<listcomp>  s$    III##**W--IIIr=   )exit_statusr   )rH   r   r<   r   r   r
   r\   r   r   
subprocessPopenPIPEwaitcommunicater!   r"   r#   r   rmtree)r   r   cleanr   r   r   r   progpr   r   r   r   s                r;   compile_run_stringsr   e  s   6  f&deee"=gy"Q"QitC\$B$BCC HY#,H H1?1E2H HD Ni(66'55N N:E:KN N dVJOJOTTTffhhIIIII 	RW]]9-- 	M)$$$I  	RW]]9-- 	M)$$$I&Y??DFT!!s   CD   9E)NNNFN)NFN)NFNNFFN)NNNFFN)NN)NNNF)NNNNNN)Nr   NNNr   )NFNN).r   r!   r   r   rn   r   rp   	sysconfigr   r   r   runnersr   r   r	   utilr
   r   r   r   r   r   r   r   r   r   r   r8   r   rq   r&   r<   rL   r\   r}   r   r   r,   r   r   r   r   r   r   r   r    r=   r;   <module>r      s    				      



   ? ? ? ? ? ? ? ? ? ?         
                          7gFFW__FFHM'..rw77888F QV$(? ? ? ?D- - - -* 9=7;E E E EP =A37TL TL TL TLn7 7 7 7v D
!%% $
'"D)"D)"D)"E*"G,"G,  ? ? ? ?D 6:59N N N Nb  / / /+ + + UY<@+ + + +\# # #6   6," ," ," ," ," ,"r=   