
    sgV                        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j6                  dk(  rdZn?ej6                  dk(  rd	Zn- ej:                  d
j=                  ej6                               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-y)'    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: {}c                    i }||j                         D ]u  \  }}	t        |t              r*t        j                  |j                        D ]  }
|	||
<   	 @t        |t
              r!t        |j                  |      D ]  }
|	||
<   	 q|	||<   w |xs d}t        j                  j                  |      sDt        j                  j                  |      rt        dj                  |            t        |       |d}| D ]  }t        ||dd        g }| D ]  }|r#t        j                  j!                  |      \  }}n?t        j                  j!                  t        j                  j#                  |            \  }}|j                         }|j%                  |j'                  |i              |j)                  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).
    .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                   [/var/www/html/venv/lib/python3.12/site-packages/sympy/utilities/_compilation/compilation.pycompile_sourcesr<      s   8 "#))+ 	(DAq!T" IIajj1 /D-.$T*/A12)!**c: /D-.$T*/ '( #	( nG77==!77>>'"188ABBg
{ 	AAG4@	A H D((+ID#(()9)9!)<=ID#kkm+//2676BsBkBCD O    c                     | xs  t         j                  j                  dd      } | j                         dk(  r|rt        dddgi| fS t        ddgi| fS | j                         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lib_optionsfortran)r!   environr*   lowerr	   r   
ValueErrorvendorcplusr   s      r;   get_mixed_fort_c_linkerrK   `   s    Erzz~~&=uEF||~ )}i896C C *}o.8 8	5	 F%"YK0&: : *   r=   c                 x   |Rt         j                  j                  t         j                  j                  | d               \  }}	|r|t	        d      z  }|sj|rYt        |j                  dd      ||      \  }}
}|
j                         D ]#  \  }}||v r||   j                  |       |||<   % n|rt        }nt        }|j                  dg       }|rd|vr|j                  d       |j                  dd	      }|st        d
      t        ||      } || |xs g z   ||fd|i|}|j                          |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_SUFFIXrI   rH   rB   z-shared
run_linkerTz*run_linker was set to False (nonsensical).r   r   )r!   r"   r'   r(   r   rK   r*   r   expandr   r   popr+   rG   r
   run)	obj_filesout_filesharedr.   r   rJ   fort
extra_objsr2   r9   extra_kwargsrI   r4   r5   rB   rO   runners                    r;   linkr[   u   sF   D (()9)9)B-)HI#|44H'!::h5 )FL& %**, "1;1I$$Q' !F1I	" *(JJw#EE!LL#L$/JEFF8-HIz/R0(EUsUfUF
JJLOr=   c                 (   |xs g }|j                  dg       }|j                  dg       }	t        j                  dk(  rt        j                  d       nxt        j                  dk(  rt               }
|j                  dg       |
d   gz   |d<   |	|
d   gz  }	d	}|
d
   j                         D ][  }|r|j                  dg       d|gz   |d<   d	}"|j                  d      r|j                  |dd        H|j                  d      sZd}] |
d   }dj                  |j                  d      dd       dd }|j                  |       nt        j                  dd dk(  rnot        d      rct               }
|j                  dg       |
d   gz   |d<   |	|
d   gz  }	|
d   j                         D ]  }|j                  d      s||dd gz  } n	 |j                  dg       }d}|D ]  }||vs|j                  |        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   rM      aixPy_ENABLE_SHARED
BLDLIBRARYrB   )-pthread)	rV   rB   r   rJ   rW   r]   	librariesr^   rX   )rR   sysplatformwarningswarnr   r*   split
startswithr+   joinr   r[   )rT   so_filer   rl   rJ   rW   rX   r2   r]   r^   cfgDictis_frameworkoptlibfilelibnamerB   needed_flagsflags                     r;   
link_py_sor|      sU   > RI::nb1L::nb1L
 ||w23		!!##ZZ
B779;M:NNz*++ 6?((* 	$C%+ZZ
B%?<QTBU%Uz"$%  QR)-#	$ )$((7==-cr23AB7!	bq	U	",-%'G!'J!;wy?Q>R!RF:WX.//L|,224 +>>$'#ab'*I+ JJw#E L uLL 	 L$eEPT)Y)jLDJL Lr=   c                    ddl m}m} ddl m} | j	                         j                  d      s!| j	                         j                  d      sJ |xs d}|xs d}|j                  dd      rd	nd
}t        j                  j                  t        j                  j                  |             d   |z   }t        j                  j                  ||      }	|rt        j                         }
nd}
t        j                  |       	  ||      }|j                  j                  |       d|vrd|j                  d<    || g|      }|j                   dkD  rt#        d      t        j                  j%                  t        j                  j'                  |             t        j                  j%                  |      k7  rt        j                  j)                  |	      rt        j*                  |	       t-        j.                  t        j                  j                  t        j                  j'                  |       |      |       t        j                  |
       |	S # t        j                  |
       w xY w)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   rJ   F.cpp.clanguage_levelrg   zCython compilation failed.)Cython.Compiler.Mainr~   r   r   rF   endswithr*   r!   r"   r'   r(   rs   getcwdchdir__dict__r)   
num_errorsrG   realpathdirnamer$   unlinkshutilmove)srcr/   r   	cy_kwargsr~   r   
cy_compiler9   c_namedstfileori_dir
cy_options	cy_results                r;   simple_cythonizer     s     ;99;'399;+?+?+FFF
*CnGMM'51&tCWWbgg..s34Q7#=Fggll7F+G
))+HHSM'8
""9- 9,45J 01uj1	!#9::
 77BGGOOC01RWW5E5Eg5NNww~~g&		'"KKRWW__S%96BGL
N 	s   D;I I+f95f2003f2008)
r   r   z.cxxz.fz.forz.ftnz.f90z.f95z.f03z.f08c                 z   t         j                  j                  t         j                  j                  |             \  }}|Gt         j                  j	                  |       rd}n%t         j                  j                  |       }|xs d}t         j                  j                  |      r't         j                  j                  ||t        z         }|j                  dg       }|r t        d      }	|	|vr|j                  |	       |j                         dk(  rt        | f|||d|S |#t        |j                            \  }}
d|vr|
|d<   |j                  dg       }d}|D ]  }||vs|j                  |        |j                  d	d
      }|rt        d       || g|f||||d|}|j!                          |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

    r   r]   includer   )objpathr]   r   stdrB   )-fPICrO   Fz#src2obj called with run_linker=True)r]   rO   r   rB   )r!   r"   r'   r(   isabsr   r#   rs   objextrR   r   r+   rF   pyx2objextension_mappingr   rS   )srcpathr.   r   r   inc_pyr2   r8   r9   r]   
py_inc_dirr   rB   rz   r{   rO   rZ   s                   r;   r,   r,   \  s   .   !1!1'!:;ID#77==!Gggoog.GnG	ww}}W'',,wv6::nb1Li(
\)
+
yy{fw !lPS !! 	! ~'		4F5MJJw#EL uLL
 L%0J@AAWIw K\)s%KCIKF
JJLNr=   c                 J   | j                  d      sJ |xs d}|xs d}|xs t        j                  j                  |      }t	        ||      }t        j                  j                  |      rht        j                  j                  |       }	t        j                  j                  |	      \  }
}t        j                  j                  ||
t        z         }|xs i }||d<   |t        |       }||d<   t        | f||d|}|xs g }|j                  dg       }d}|D ]  }||vs|j                  |        |j                  d	g       }|j                  d
d      rt        d      |r|j                  dd      }n|j                  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   rP   
output_dirrJ   r/   r   rB   )z-fwrapvrk   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'   rs   r   r   r   rR   r+   r   r,   )pyxpathr   r/   r   r]   r   rJ   r2   abs_objpath	pyx_fnamer8   r9   interm_c_filerB   rz   r{   r   r   s                     r;   r   r     s   J F###
*CnG11Gg3/K	ww}}[!GG$$W-	GG$$Y/	c'',,wv6RI!Il}W%Ig$WTg3T)TM%2LJJw#E3L uLL jjB'Gzz#U+LMM jj(jj&= 's ,Es"4  r=   c                     | D ]N  }t         j                  j                  |      \  }}|j                         }|t        v s>t        |   d   |k(  sN y y)Nr   TF)r!   r"   r'   rF   r   )srcsclsr   r8   r9   keys         r;   _any_Xr     sW     GG$$S)	ciik## %a(C/ r=   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=   c           	         |Bt         j                  j                  t         j                  j                  | d               d   }|xs i }|xs i }	 t	        t         j                  j                  ||      |       }|S # t        $ rX t        t        t        t        |             f||d|}t        |f|t        |       t        |       |d|}t	        |      }Y |S w xY w)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.
    rM   r   r   )r   rW   rJ   rX   )r!   r"   r'   r(   r   rs   ImportErrorr<   listmapr
   r|   r   r   )	sourcesextname	build_dircompile_kwargslink_kwargsrX   modobjssos	            r;   compile_link_import_py_extr     s    : ''""277#3#3GBK#@A!D#)rN#K*%bggll9g&FP J  *tCW$=> @	#,@0>@ \)/'2J+G4\OZ\%b)J*s   *A> >ACCc                 Z   |xs t        j                         }t        j                  j	                  |      st        d|      g }| D ]9  \  }}t        j                  j                  ||      }d}t        |j                  d            j                         }t        j                  j                  |      rht        j                  j                  |dz         r(t        |dz         5 }|j                         }	d d d        nt        |      j                         }		|k7  }|rOt        |d      5 }|j                  |       d d d        t        |dz   d      5 }|j                  |       d d d        |j                  |       < ||fS # 1 sw Y   wxY w# 1 sw Y   VxY w# 1 sw Y   9xY w)NzNon-existent directory: Tutf-8z.sha256wt)tempfilemkdtempr!   r"   r#   r%   rs   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   /  st   /X--/I77==#0)<<L "	cww||It,(G)<=GGI77>>$ww~~dY./$*+ /r%'WWYN/ / "0!5!?!?!A$5GdD! RdY&- ('(D!#"$ ""/ / ( (s$   (F	.FF!	F	F	!F*	c                 L    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  s=    * :'9ML)
$\
QY
Q&
QC#D9r=   c                    |r|t        d      	 t        | |      \  }}t        t        t	        t
        |            f||d|xs i }t        |f|t        |      t        |      d|xs i }t        j                  |gt        j                  t        j                        }|j                         }	|j                         D 
cg c]  }
|
j                  d       c}
\  }}|r7t        j                   j#                  |      rt%        j&                  |       d}	 |	|d}||f|fS c c}
w # |r8t        j                   j#                  |      rt%        j&                  |       d}w w w xY w)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   rW   rJ   )stdoutstderrr   )exit_statusr   )rG   r   r<   r   r   r
   r[   r   r   
subprocessPopenPIPEwaitcommunicatedecoder!   r"   r#   r   rmtree)r   r   cleanr   r   r   r   progpr   txtr   r   r   s                 r;   compile_run_stringsr   e  sP   6 &dee"=gy"QitC\$BC HY#,H1?1E2HD Ni(6'5N:E:KN dVJOOJOOTffh9:I##**W-IRWW]]9-MM)$I&Y?DFT!! JRWW]]9-MM)$I .5s   B6D. D)D. )D. .<E*)NNNFN)NFN)NFNNFFN)NNNFFN)NN)NNNF)NNNNNN)Nr   NNNr   )NFNN).r   r!   r   r   rm   r   ro   	sysconfigr   r   r   runnersr   r   r	   utilr
   r   r   r   r   r   r   r   r   r   r   r8   r   rp   r&   r<   rK   r[   r|   r   r   r,   r   r   r   r   r   r   r   r    r=   r;   <module>r      s\    	   
   ? ? 
    77gFWW_FHMM'..rww78F QV$(?D-* 9=7;EP =A37TLn7v D
!%% $
'"D)"D)"D)"E*"G,"G, ?D 6:59Nb/+ UY<@+\#66,"r=   