U ã€C^ lã@sÖddlmZmZmZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl m Z ddlTddlmZmZmZmZddlmZddlmZdd lmZdd lmZdd lmZmZdd lm Z m!Z!m"Z"m#Z#m$Z$z ddl%Z%Wne&k �r ddl'Z%YnXda(e% )¡Z*e+ƒZ,d d„Z-dd„Z.dd„Z/e.e0de/ƒdMdd„Z1e.e0de1ƒdNdd„Z2e.e0de2ƒdOdd„Z3e.e0de3ƒdPdd „Z4e.e0d!e4ƒd"d#„Z5d$d%„Z6e.e0d&e6ƒdQd'd(„Z7e.e0d)e7ƒdRd+d,„Z8d-dgfd.d/„Z9e.e0d0e9ƒd1d2„Z:e.e0d3e:ƒd4e;d5<d6e;d7<d8e;d9<d:e;d;<de;d?<e jdD¡dEe j<e _Es ÿz _needs_build..)ÚposixF) ÚosÚpathÚexistsÚopenÚ readlinesrÚjoinÚshlexÚsplitÚstatÚst_mtimeÚOSError) ÚobjÚcc_argsÚextra_postargsÚpp_optsZdep_fileÚfÚlinesZcmdlineZ last_cmdlineÚcontentsÚdepsZt_objr r r!Ú _needs_build%s&    r7cs:tjddkrt ˆd|¡}n ‡fdd„}t|||ƒdS)Nrécsˆ|f|ž|ŽS©Nr )ÚselfÚargsÚkw©Úfuncr r!Ú\óz replace_method..)ÚsysÚ version_infoÚtypesÚ MethodTypeÚsetattr)ÚklassÚ method_namer>Úmr r=r!Úreplace_methodWs rIcCsdS)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_executablesesrKÚfind_executablesc Csò|dkr"|}t|ƒr"d t|ƒ¡}t |¡z&|jr@t |¡ntj|tjd�WnJtj k r‚}z|j }|j }W5d}~XYn t k rœd}d}YnXdSt|ƒr¸d t|ƒ¡}|jrÆt |ƒt d|¡rØd}nd}td |||fƒ‚dS) 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@ésToo many open filesz2 Try rerunning setup command until build succeeds.rz)Command "%s" failed with exit status %d%s)rr)ÚlistrÚinfoÚverboseÚ subprocessÚ check_outputÚSTDOUTÚCalledProcessErrorÚoutputÚ returncoder.rÚreÚsearchr)r:ÚcmdÚdisplayÚexcÚoÚsÚmsgr r r!ÚCCompiler_spawnss4    ÿrbÚspawnrc Csê|dkr d}g}|D]Ð}tj tj |¡¡\}}tj |¡d}|tj |¡d…}| d¡rœ| d¡d}|d|…} tj tj  | ¡¡} | ||d…}||j kr¶t d||fƒ‚|rÆtj |¡}tj  |||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ÚabspathZsrc_extensionsÚUnknownFileErrorr)Z obj_extensionÚappend) r:Zsource_filenamesZ strip_dirÚ output_dirZ obj_namesÚsrc_nameÚbaseÚextÚiÚdZobj_namer r r!ÚCCompiler_object_filenames´s&     rvZobject_filenamesc  s`tƒ} t�tdkrt | ¡aW5QRX|s0gStjddkrTddlm} m } m } nddl m} m } m } t ˆ| ƒr¼g} dD]4}t ˆd|ƒ}|dkr–qz|  d|d  |¡f¡qzd  | ¡} nˆj}d d  |¡f} t | ¡ˆ |||||ˆ¡\}}‰‰}ˆ ˆ||¡‰d d  ˆ¡} ˆ�r.| d d  ˆ¡7} t | ¡‡‡‡‡fdd„}t ˆ| ƒ�rþt| ¡ƒ}gg}}|D]r}||k�rp||\}}ˆjdk�r¦t|ƒ}t|ƒ}| |ƒ�rÎ| |ƒ�sÎ| |||ff¡n| |||ff¡�qp|}|D]}||ƒ�qìn| ¡}t|ƒdk�rH| dk�rHddl}|j | ¡}| ||¡| ¡n|D]}||ƒ�qL|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. Nrr8rd)Ú FCompilerÚ is_f_fileÚhas_f90_header)Zf77Zf90ZfixZ compiler_zFortran %s compiler: %srMrzC compiler: %s zcompile options: '%s'z extra options: '%s'cs¢|\}\}}t|ˆˆˆƒsdSt�$|tkrBt |¡W5QR£qXW5QRXt d¡qz(t�ˆ |||ˆˆˆ¡W5QRXW5t�t |¡W5QRXXdS)Ngš™™™™™¹?) r7Ú _global_lockÚ_processing_filesÚaddÚtimeÚsleepÚremoveÚ_job_semaphoreÚ_compile)r;r/Úsrcrs©r0r1r2r:r r!Úsingle_compile3s   "z)CCompiler_compile..single_compileZabsoft) rrzr€Ú threadingÚ SemaphorerArBZ fcompilerrwrxryZnumpy.distutils.fcompilerÚ isinstanceÚgetattrror)Ú compiler_sorrRZ_setup_compileZ _get_cc_argsrQÚkeysÚ compiler_typerÚitemsÚlenZmultiprocessing.poolÚpoolZ ThreadPoolÚmapÚclose)r:ÚsourcesrpÚmacrosÚ include_dirsÚdebugÚ extra_preargsr1ÚdependsÚjobsrwrxryr]ZfcZfcompZccompZobjectsÚbuildr„Zobjects_to_buildZ f77_objectsZ other_objectsr/r‚rsZ build_itemsr_ÚmultiprocessingrŽr rƒr!ÚCCompiler_compileãsn+    ÿÿ            ršÚcompiler csÞt d|jjˆjjf¡‡‡fdd„}|dƒr<| ˆj¡|dƒr`ˆjD]\}}| ||¡qJ|dƒr~ˆjD]}|  |¡qn|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 zcustomize %s using %scstˆ|dƒdk o|ˆkSr9)rˆ)Úattr©r\Úignorer r!Úallow‹sz&CCompiler_customize_cmd..allowr“ÚdefineÚundefÚ librariesÚ library_dirsÚrpathÚ link_objectsN)rrRÚ __class__Ú__name__Zset_include_dirsr“r Z define_macror¡Zundefine_macroZ set_librariesr¢Zset_library_dirsr£Zset_runtime_library_dirsr¤Zset_link_objectsr¥)r:r\ržrŸÚnameÚvalueÚmacror r�r!ÚCCompiler_customize_cmdvs( ÿ    r«Z customize_cmdcs g}d}t|j ¡ƒ}dD]}||kr| |¡q|D]8}t||ƒr6t||ƒ}t|t|ƒƒ}| |t|ƒf¡q6dt|dƒd‰‡fdd„|Dƒ}d  |¡S) Nr) Úversionr¢r£Z object_switchZcompile_switchr“r r¡r¤r¥z%-rdzs = %scsg|] }ˆ|‘qSr r )rÚprop©Úfmtr r!r"°sz'_compiler_to_string..r) rQZ executablesrŠroÚhasattrrˆÚmaxr�Úreprr))ÚcompilerÚpropsZmxrŠÚkeyÚvr4r r®r!Ú_compiler_to_string¡s   r·cCsXz | ¡Wntk r YnXtjjdkrTtdƒt|jƒtt|ƒƒtdƒdS)z× Print the compiler customizations to stdout. Parameters ---------- None Returns ------- None Notes ----- Printing is only done if the distutils log threshold is < 2. rezP********************************************************************************N) rˆrÚ get_versionÚ ExceptionÚ _global_logÚ thresholdÚprintr¦r·rJr r r!ÚCCompiler_show_customization³s    r½Zshow_customizationc CsÖt d|jj¡t|ƒ|ræz|j d¡Wnttfk rFYnXt |dƒr®d|j dkr®|j sæ|j d  d¡r€d\}}nd\}}|j d  ||¡g|j d d …|_ n8t |dƒrÊt d |j f¡t |d ƒsæt d |jj¡t |dƒ�r*d|j dk�s"d|j dk�s"d|j dk�r*d|_n¨tjdk�rÒdd l}dd l}| ¡}zvzTtj |d¡}t|dƒ�} |  d¡W5QRX|j|g|dd|dgd�d|_Wntk �rÀd|_YnXW5| |¡Xd 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¾zc++rdNz#### %s #######Ú compiler_cxxzMissing compiler_cxx fix for rÀZclangTr#zfile.cÚwzint a; z-MMDz-MFr)rpr•F)rrRr¦r§r r‰rÚAttributeErrorÚ ValueErrorr°r³rÁrjÚreplaceÚwarnZ _auto_dependsr$r¨ÚtempfileÚshutilÚmkdtempÚrmtreer%r)r'Úwriter›r ) r:ÚdistZneed_cxxÚaÚbrÇrÈZtmpdirÚfnr3r r r!ÚCCompiler_customizeØsR  ÿ   ÿ þ    ÿ  rÐZ customizeú[-.\d]+cs‡‡‡fdd„}|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. csz| dd¡}d}ˆr0t ˆ|¡}|s(dS| ¡}t ˆ||d…¡}|sLdSˆrpt ˆ| d¡¡rp| ¡}q0qpq0| d¡S)NrrMr)rÅrZÚmatchÚendr[Úgroup)r:Úversion_stringÚposrH©ržÚpatÚstartr r!ÚmatcherEs  z%simple_version_match..matcherr )rØržrÙrÚr r×r!Úsimple_version_match+srÛFc s:|st|dƒr|jS| ¡z |j}Wntk r<YdSX|rJ|dsNdSz |j}WnDtk rœz |j‰Wntk rŠYYdSX‡fdd„}YnXztj|tj d�}WnLtj k râ}z|j }|j }W5d}~XYn*t k �rþd}d}YnXt|ƒ}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¬Nrcs"t ˆ|¡}|sdS| d¡}|S)Nr¬)rZrÒrÔ)rÕrHr¬©rØr r!rÚ~s   z&CCompiler_get_version..matcherrNrPr@)r°r¬rLÚ version_cmdrÃZ version_matchZversion_patternrTrUrVrWrXrYr.rr ) r:ÚforceZ ok_statusrÝrÚrXr^Ústatusr¬r rÜr!ÚCCompiler_get_versionZsD       ràr¸cCs’|jdkr|St|ƒ}|jdg|jdd…|_tj d¡rrd|jdkrr|jd|jdg|jdd…|_n|jdg|jdd…|_|S)z² Return the C++ compiler. Parameters ---------- None Returns ------- cxx : class instance The C++ compiler, as a `CCompiler` instance. )ÚmsvcÚintelwÚintelemwrrdNÚaixZ ld_so_aixre)r‹rrÁr‰rAÚplatformrjÚ linker_so)r:Úcxxr r r!ÚCCompiler_cxx_compilerŸs  ÿrèZ cxx_compiler)ÚintelccompilerZIntelCCompilerz(Intel C Compiler for 32-bit applicationsÚintel)réZIntelItaniumCCompilerz7Intel C Itanium Compiler for Itanium-based applicationsÚintele)réZIntelEM64TCCompilerz(Intel C Compiler for 64-bit applicationsÚintelem)réZIntelCCompilerWz3Intel C Compiler for 32-bit applications on Windowsrâ)réZIntelEM64TCCompilerWz3Intel C Compiler for 64-bit applications on Windowsrã)Z pathccompilerZPathScaleCCompilerz2PathScale Compiler for SiCortex-based applicationsÚpathcc))úlinux.*rê)rîrë)rîrì)rîrí)Úntrâ)rïrãÚwin32)Zmingw32ccompilerZMingw32CCompilerz>Mingw32 port of GNU C Compiler for Win32(for MSC built Python)rz+Setting mingw32 as default compiler for nt.))rïrc Csr|dkrt ¡tjk}|dkr$tj}z"|dkr6t|ƒ}t|\}}}Wn8tk r~d|}|dk rr|d|}t|ƒ‚YnXd|}z t |ƒWnvt k �r t t ƒƒ}t  dt |ƒ¡|dd…}z t |ƒWn,t k �rt t ƒƒ}td|ƒ‚YnXYnXztj|} t| ƒ|} Wn&tk �rLtd||fƒ‚YnX| d||ƒ}||_t d| ¡|S) Nz5don't know how to compile C/C++ code on platform '%s'z with '%s' compilerznumpy.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'znew_compiler returns %s)rZ get_thresholdÚINFOr$r¨Zget_default_compilerÚcompiler_classÚKeyErrorr Ú __import__Ú ImportErrorÚstrrrRr rAÚmodulesÚvarsrSr”) Úplatr³rSÚdry_runrÞÚ module_nameÚ class_nameÚlong_descriptionraÚmodulerFr r r!Ú new_compilerÜsP   ÿ   ÿ ÿ  rcCsBt||||ƒ}g}|D]&}t|ƒr2| t|ƒ¡q| |¡q|Sr9)Ú_distutils_gen_lib_optionsrÚextendrQro)r³r£Úruntime_library_dirsr¢rZlib_optsrtr r r!Úgen_lib_options sÿ r)Zmsvc9ráZ_msvcZbcppZcygwincZemxcZunixcz distutils.r³)N)rr)NNNrNNN)r )r)rÑrr)NNNrr)HÚ __future__rrrr$rZrArCr*r}rTrÚ distutilsrÚdistutils.ccompilerÚdistutils.errorsrr r r Údistutils.sysconfigr Zdistutils.versionr Znumpy.distutilsrZnumpy.distutils.compatrZnumpy.distutils.exec_commandrrZnumpy.distutils.misc_utilrrrrrr…röZdummy_threadingr€ÚLockrzÚsetr{r7rIrKZ CCompilerrbrvršr«r·r½rÐrÛràrèróZ_default_compilersrårRrZ_distutils_new_compilerrrZ_ccrøÚgetÚ_mrEr r r r!Ús¤       2  ?  - þ   ) #  Q  /C    ÿü ,