K iV ddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZmZmZddlmZmZmZmZmZmZmZmZmZmZmZej:dk(rdZn?ej:d k(rd Zn-ej>d jAej:dZ dd Z!dd Z" d dZ# d!dZ$d"dZ%edfedfedfedfedfedfedfedfedfedfd Z&d#dZ' d$dZ(dZ)dZ*dZ+ d%dZ,dZ-d&dZ.d'dZ/y)(N)Path)get_config_varget_config_varsget_path)CCompilerRunnerCppCompilerRunnerFortranCompilerRunner) get_abspath make_dirscopyGlobArbitraryDepthGlob glob_at_depthimport_module_from_file pyx_is_cplussha256_of_stringsha256_of_file CompileErrorposixz.ontz.objzUnknown os.name: {}c i}||jD]u\}} t|tr*tj|jD]} | || < @t|t r!t |j|D]} | || < q| ||<w|xsd}tjj|sDtjj|rtdj|t||d}|D]} t| |ddg} |D]} |r#tjj!| \} }n?tjj!tjj#| \} }|j}|j%|j'| i| j)t+| |fd|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_dircwd)items isinstancerglobpathnamerrfilenameospathisdirexistsOSErrorformatr r splitextbasenameupdategetappendsrc2obj)filesRunnerdestdirrkeep_dir_structper_file_kwargskwargs_per_file_kwargskvr#fdstpathsnameext file_kwargss n/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/utilities/_compilation/compilation.pycompile_sourcesr=s8"#))+ (DAq!T" IIajj1/D-.$T*/A12)!**c:/D-.$T*/'( # (nG 77== ! 77>>' "188AB B g  { AA G4 @ AH D ((+ID#(()9)9!)<=ID#kkm +//2676BsBkBCD Oc|xs tjjdd}|jdk(r|r tdddgi|fStddgi|fS|jdk(s |r t ddgi|fSti|fS) NSYMPY_COMPILER_VENDORgnuintelflagsz -nofor_mainz-cxxlib lib_optionsfortran)r"environr+lowerr r ValueErrorvendorcplusrs r<get_mixed_fort_c_linkerrLas  Erzz~~&=uEF ||~ )}i896C C*}o.8 8 5 F %"YK0&: :*  r>c x|Rtjjtjj|d\}} |r|t dz }|sj|rYt |j dd||\}} } | jD]#\} } | |vr|| j| | || <%n|rt}nt}|jdg}|rd|vr|jd|jdd }|s td t|| }|||xsgz||fd |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_SUFFIXrJrIrCz-shared run_linkerTz*run_linker was set to False (nonsensical).rr)r"r#r(r)rrLr+rexpandr rpopr,rHr run) obj_filesout_filesharedr/rrKfort extra_objsr3r: extra_kwargsrJr5r6rCrPrunners r<linkr\vsFD(()9)9)B-)HI #  |4 4H  '!::h5 )FL& %**, "1;1I$$Q' !F1I  " *( JJw #E E ! LL #L$/J EFF8-H Iz/R0(E Us Uf UF JJL Or>c (|xsg}|jdg}|jdg} tjdk(rtjdnxtjdk(rt } |j dg| dgz|d<| | dgz } d } | d jD][} | r|j dgd | gz|d<d } "| jd r|j| d dH| jd sZd} ]| d} dj| jddddd}|j|ntjdddk(rnotdrct } |j dg| dgz|d<| | dgz } | djD]} | jd s|| d dgz }n |jdg}d}|D]}||vs|j|t|fd||||||| |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_dirswin32zWindows not yet supported.darwinlinklineLDFLAGSLIBDIRFLIBSz -frameworkz-lNTLIBRARYrrNaixPy_ENABLE_SHARED BLDLIBRARYrC)-pthread) rWrCrrKrXr^ librariesr_rY) rSsysplatformwarningswarnrr+split startswithr,joinrr\)rUso_filerrmrKrXrYr3r^r_cfgDict is_frameworkoptlibfilelibnamerC needed_flagsflags r< link_py_sor}sU>RI::nb1L::nb1L  ||w 23  !!##ZZ B779;M:NNz*++  6?((* $C%+ZZ B%?R!RF:  WX./ /L|,224 +>>$'#ab'*I +  JJw #E L u  LL    L$eEPT)Y)j LDJ LLr>c ddlm}m}ddlm}|j j ds!|j j dsJ|xsd}|xsd}|j ddrd nd }tjjtjj|d|z}tjj||} |rtj} nd} tj| ||} | jj|d |vrd | jd <||g| } | j dkDr t#d tjj%tjj'|tjj%|k7rtjj)| rtj*| t-j.tjjtjj'|||tj| | S#tj| wxYw)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_optionsCompilationOptions)compile.pyxz.pyrrKF.cpp.clanguage_levelrhzCython compilation failed.)Cython.Compiler.MainrrrrGendswithr+r"r#r(r)rtgetcwdchdir__dict__r* num_errorsrHrealpathdirnamer%unlinkshutilmove) srcr0r cy_kwargsrr cy_compiler:c_namedstfileori_dir cy_options cy_results r<simple_cythonizers ; 99;   '399;+?+?+FF F *CnGMM'51&tC WW  bgg..s3 4Q 7# =Fggll7F+G ))+HHSM'8 ""9- 9 ,45J   0 1uj1   ! #9: : 77  BGGOOC0 1RWW5E5Eg5N Nww~~g& '" KK RWW__S%96BG L  N s D;II+f95f2003f2008) rrz.cxxz.fz.forz.ftnz.f90z.f95z.f03z.f08c ztjjtjj|\}}|Gtjj |rd}n%tjj |}|xsd}tjj |r'tjj||tz}|jdg}|r td} | |vr|j| |jdk(rt|f|||d|S|#t|j\}} d|vr| |d<|jdg} d} | D]} | | vs| j| |jd d }|r td ||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 rr^includer)objpathr^rstdrC)-fPICrPFz#src2obj called with run_linker=True)r^rPrrC)r"r#r(r)isabsrr$rtobjextrSrr,rGpyx2objextension_mappingrrT)srcpathr/rrinc_pyr3r9r:r^ py_inc_dirrrCr{r|rPr[s r<r-r-]s.  !1!1'!:;ID# 77== !Gggoog.GnG ww}}W'',,wv 6::nb1L i( \ )    + yy{fw!lPS!! !~' 4   F5M JJw #EL u  LL  L%0J@AA WIwK\)s%KCIKF JJL Nr>c J|jdsJ|xsd}|xsd}|xstjj|}t ||}tjj |rhtjj |} tjj| \} } tjj|| tz}|xsi}||d<| t|}||d<t|f||d|} |xsg}|jdg} d}|D]}|| vs| j||jd g}|jd d r td |r|jd d}n|jd d}t| f|||| ||dd 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. rrrQ output_dirrKr0rrC)z-fwrapvrlroptionsstrict_aliasingFz/Cython requires strict aliasing to be disabled.rzc++98c99T)rrr^rCrrrr)rr"r#rr r$r)r(rtrrrrSr,rr-)pyxpathrr0rr^rrKr3 abs_objpath pyx_fnamer9r: interm_c_filerCr{r|rrs r<rrsJ   F ## # *CnG11Gg3/K ww}}[!GG$$W- GG$$Y/ c'',,wv 6RI!Il }W%Ig$WTg3T)TM%2L JJw #E3L u  LL jjB'G zz#U+LMM jj(jj& = 's ,Es"4  r>c|D]N}tjj|\}}|j}|tvs>t|d|k(sNyy)NrTF)r"r#r(rGr)srcsclsrr9r:keys r<_any_XrsWGG$$S) ciik # # %a(C/  r>c"t|tSN)rr rs r<any_fortran_srcrs $- ..r>c"t|tSr)rr rs r< any_cplus_srcrs $) **r>c |Btjjtjj|dd}|xsi}|xsi} t tjj |||}|S#t $rXtttt|f||d|}t|f|t|t||d|}t |}Y|SwxYw)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. rNrr)rrXrKrY)r"r#r(r)rrt ImportErrorr=listmapr r}rr) sourcesextname build_dircompile_kwargs link_kwargsrYmodobjssos r<compile_link_import_py_extrs:''""277#3#3GBK#@A!D#)rN#K*%bggll9g&FP J *tC W$=>@ #,@0>@ \)/'2J+G4\OZ\%b) J *s*A>>ACCc,|xstj}tjj |s t d|g}|D].\}}tjj ||}d}t|jdj}tjj|r]tjj|dzrt|dzj}nt|j}||k7}|rOt|d5} | j|dddt|dzd5} | j|ddd|j!|1||fS#1swYJxYw#1swY-xYw)NzNon-existent directory: Tutf-8z.sha256wt)tempfilemkdtempr"r#r$r&rtrencode hexdigestr%r read_textropenwriter,) rr source_filesr9rdestdiffers sha256_in_memsha256_on_diskfhs r<_write_sources_to_build_dirr0sV/X--/I 77== #0)<<L" cww||It,(G)<=GGI 77>>$ ww~~dY./!%dY&6!7!A!A!C!/!5!?!?!A$ 5G dD! R  dY&- (' (D!!""  ""    ( (s#E> F >F F c Lt||\}}t|fd|i|}d|i}||fS)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)rr)rrr3rrinfos r<compile_link_import_stringsrJs=*:'9ML) $\ QY Q& QC  #D 9r>c|r | td t||\}}ttt t |f||d|xsi}t |f|t|t|d|xsi}tj|gtjtj}|j} |jD cgc]} | jdc} \} } |r7tj j#|rt%j&|d} | |d} | | f| fScc} w#|r8tj j#|rt%j&|d}wwwxYw)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)rrXrK)stdoutstderrr) exit_statusr)rHrr=rrr r\rr subprocessPopenPIPEwait communicatedecoder"r#r$rrmtree)rrcleanrrrrprogprtxtrrrs r<compile_run_stringsresP6 &dee "=gy"Q itC \$BCHY#,H1?1E2HDNi(6' 5N:E:KN   dVJOOJOO Tffh 9:I##**W-I RWW]]9- MM) $I&Y ?D F T !! J RWW]]9- MM) $I.5sB6D.D)D.)D..r<rs_  ??  77g FWW_ FHMM'..rww78 FQV$(?D-*9=7;EP=A37TLn7v D !  %  % $ ' "D ) "D ) "D ) "E * "G , "G , ?D6:59Nb/+UY<@+\#46,"r>