system_info.py 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116
  1. #!/usr/bin/env python3
  2. """
  3. This file defines a set of system_info classes for getting
  4. information about various resources (libraries, library directories,
  5. include directories, etc.) in the system. Usage:
  6. info_dict = get_info(<name>)
  7. where <name> is a string 'atlas','x11','fftw','lapack','blas',
  8. 'lapack_src', 'blas_src', etc. For a complete list of allowed names,
  9. see the definition of get_info() function below.
  10. Returned info_dict is a dictionary which is compatible with
  11. distutils.setup keyword arguments. If info_dict == {}, then the
  12. asked resource is not available (system_info could not find it).
  13. Several *_info classes specify an environment variable to specify
  14. the locations of software. When setting the corresponding environment
  15. variable to 'None' then the software will be ignored, even when it
  16. is available in system.
  17. Global parameters:
  18. system_info.search_static_first - search static libraries (.a)
  19. in precedence to shared ones (.so, .sl) if enabled.
  20. system_info.verbosity - output the results to stdout if enabled.
  21. The file 'site.cfg' is looked for in
  22. 1) Directory of main setup.py file being run.
  23. 2) Home directory of user running the setup.py file as ~/.numpy-site.cfg
  24. 3) System wide directory (location of this file...)
  25. The first one found is used to get system configuration options The
  26. format is that used by ConfigParser (i.e., Windows .INI style). The
  27. section ALL is not intended for general use.
  28. Appropriate defaults are used if nothing is specified.
  29. The order of finding the locations of resources is the following:
  30. 1. environment variable
  31. 2. section in site.cfg
  32. 3. DEFAULT section in site.cfg
  33. 4. System default search paths (see ``default_*`` variables below).
  34. Only the first complete match is returned.
  35. Currently, the following classes are available, along with their section names:
  36. Numeric_info:Numeric
  37. _numpy_info:Numeric
  38. _pkg_config_info:None
  39. accelerate_info:accelerate
  40. agg2_info:agg2
  41. amd_info:amd
  42. atlas_3_10_blas_info:atlas
  43. atlas_3_10_blas_threads_info:atlas
  44. atlas_3_10_info:atlas
  45. atlas_3_10_threads_info:atlas
  46. atlas_blas_info:atlas
  47. atlas_blas_threads_info:atlas
  48. atlas_info:atlas
  49. atlas_threads_info:atlas
  50. blas64__opt_info:ALL # usage recommended (general ILP64 BLAS, 64_ symbol suffix)
  51. blas_ilp64_opt_info:ALL # usage recommended (general ILP64 BLAS)
  52. blas_ilp64_plain_opt_info:ALL # usage recommended (general ILP64 BLAS, no symbol suffix)
  53. blas_info:blas
  54. blas_mkl_info:mkl
  55. blas_opt_info:ALL # usage recommended
  56. blas_src_info:blas_src
  57. blis_info:blis
  58. boost_python_info:boost_python
  59. dfftw_info:fftw
  60. dfftw_threads_info:fftw
  61. djbfft_info:djbfft
  62. f2py_info:ALL
  63. fft_opt_info:ALL
  64. fftw2_info:fftw
  65. fftw3_info:fftw3
  66. fftw_info:fftw
  67. fftw_threads_info:fftw
  68. flame_info:flame
  69. freetype2_info:freetype2
  70. gdk_2_info:gdk_2
  71. gdk_info:gdk
  72. gdk_pixbuf_2_info:gdk_pixbuf_2
  73. gdk_pixbuf_xlib_2_info:gdk_pixbuf_xlib_2
  74. gdk_x11_2_info:gdk_x11_2
  75. gtkp_2_info:gtkp_2
  76. gtkp_x11_2_info:gtkp_x11_2
  77. lapack64__opt_info:ALL # usage recommended (general ILP64 LAPACK, 64_ symbol suffix)
  78. lapack_atlas_3_10_info:atlas
  79. lapack_atlas_3_10_threads_info:atlas
  80. lapack_atlas_info:atlas
  81. lapack_atlas_threads_info:atlas
  82. lapack_ilp64_opt_info:ALL # usage recommended (general ILP64 LAPACK)
  83. lapack_ilp64_plain_opt_info:ALL # usage recommended (general ILP64 LAPACK, no symbol suffix)
  84. lapack_info:lapack
  85. lapack_mkl_info:mkl
  86. lapack_opt_info:ALL # usage recommended
  87. lapack_src_info:lapack_src
  88. mkl_info:mkl
  89. numarray_info:numarray
  90. numerix_info:numerix
  91. numpy_info:numpy
  92. openblas64__info:openblas64_
  93. openblas64__lapack_info:openblas64_
  94. openblas_clapack_info:openblas
  95. openblas_ilp64_info:openblas_ilp64
  96. openblas_ilp64_lapack_info:openblas_ilp64
  97. openblas_info:openblas
  98. openblas_lapack_info:openblas
  99. sfftw_info:fftw
  100. sfftw_threads_info:fftw
  101. system_info:ALL
  102. umfpack_info:umfpack
  103. wx_info:wx
  104. x11_info:x11
  105. xft_info:xft
  106. Note that blas_opt_info and lapack_opt_info honor the NPY_BLAS_ORDER
  107. and NPY_LAPACK_ORDER environment variables to determine the order in which
  108. specific BLAS and LAPACK libraries are searched for.
  109. This search (or autodetection) can be bypassed by defining the environment
  110. variables NPY_BLAS_LIBS and NPY_LAPACK_LIBS, which should then contain the
  111. exact linker flags to use (language will be set to F77). Building against
  112. Netlib BLAS/LAPACK or stub files, in order to be able to switch BLAS and LAPACK
  113. implementations at runtime. If using this to build NumPy itself, it is
  114. recommended to also define NPY_CBLAS_LIBS (assuming your BLAS library has a
  115. CBLAS interface) to enable CBLAS usage for matrix multiplication (unoptimized
  116. otherwise).
  117. Example:
  118. ----------
  119. [DEFAULT]
  120. # default section
  121. library_dirs = /usr/lib:/usr/local/lib:/opt/lib
  122. include_dirs = /usr/include:/usr/local/include:/opt/include
  123. src_dirs = /usr/local/src:/opt/src
  124. # search static libraries (.a) in preference to shared ones (.so)
  125. search_static_first = 0
  126. [fftw]
  127. libraries = rfftw, fftw
  128. [atlas]
  129. library_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas
  130. # for overriding the names of the atlas libraries
  131. libraries = lapack, f77blas, cblas, atlas
  132. [x11]
  133. library_dirs = /usr/X11R6/lib
  134. include_dirs = /usr/X11R6/include
  135. ----------
  136. Note that the ``libraries`` key is the default setting for libraries.
  137. Authors:
  138. Pearu Peterson <pearu@cens.ioc.ee>, February 2002
  139. David M. Cooke <cookedm@physics.mcmaster.ca>, April 2002
  140. Copyright 2002 Pearu Peterson all rights reserved,
  141. Pearu Peterson <pearu@cens.ioc.ee>
  142. Permission to use, modify, and distribute this software is given under the
  143. terms of the NumPy (BSD style) license. See LICENSE.txt that came with
  144. this distribution for specifics.
  145. NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
  146. """
  147. import sys
  148. import os
  149. import re
  150. import copy
  151. import warnings
  152. import subprocess
  153. import textwrap
  154. from glob import glob
  155. from functools import reduce
  156. from configparser import NoOptionError
  157. from configparser import RawConfigParser as ConfigParser
  158. # It seems that some people are importing ConfigParser from here so is
  159. # good to keep its class name. Use of RawConfigParser is needed in
  160. # order to be able to load path names with percent in them, like
  161. # `feature%2Fcool` which is common on git flow branch names.
  162. from distutils.errors import DistutilsError
  163. from distutils.dist import Distribution
  164. import sysconfig
  165. from numpy.distutils import log
  166. from distutils.util import get_platform
  167. from numpy.distutils.exec_command import (
  168. find_executable, filepath_from_subprocess_output,
  169. )
  170. from numpy.distutils.misc_util import (is_sequence, is_string,
  171. get_shared_lib_extension)
  172. from numpy.distutils.command.config import config as cmd_config
  173. from numpy.distutils import customized_ccompiler as _customized_ccompiler
  174. from numpy.distutils import _shell_utils
  175. import distutils.ccompiler
  176. import tempfile
  177. import shutil
  178. __all__ = ['system_info']
  179. # Determine number of bits
  180. import platform
  181. _bits = {'32bit': 32, '64bit': 64}
  182. platform_bits = _bits[platform.architecture()[0]]
  183. global_compiler = None
  184. def customized_ccompiler():
  185. global global_compiler
  186. if not global_compiler:
  187. global_compiler = _customized_ccompiler()
  188. return global_compiler
  189. def _c_string_literal(s):
  190. """
  191. Convert a python string into a literal suitable for inclusion into C code
  192. """
  193. # only these three characters are forbidden in C strings
  194. s = s.replace('\\', r'\\')
  195. s = s.replace('"', r'\"')
  196. s = s.replace('\n', r'\n')
  197. return '"{}"'.format(s)
  198. def libpaths(paths, bits):
  199. """Return a list of library paths valid on 32 or 64 bit systems.
  200. Inputs:
  201. paths : sequence
  202. A sequence of strings (typically paths)
  203. bits : int
  204. An integer, the only valid values are 32 or 64. A ValueError exception
  205. is raised otherwise.
  206. Examples:
  207. Consider a list of directories
  208. >>> paths = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']
  209. For a 32-bit platform, this is already valid:
  210. >>> np.distutils.system_info.libpaths(paths,32)
  211. ['/usr/X11R6/lib', '/usr/X11/lib', '/usr/lib']
  212. On 64 bits, we prepend the '64' postfix
  213. >>> np.distutils.system_info.libpaths(paths,64)
  214. ['/usr/X11R6/lib64', '/usr/X11R6/lib', '/usr/X11/lib64', '/usr/X11/lib',
  215. '/usr/lib64', '/usr/lib']
  216. """
  217. if bits not in (32, 64):
  218. raise ValueError("Invalid bit size in libpaths: 32 or 64 only")
  219. # Handle 32bit case
  220. if bits == 32:
  221. return paths
  222. # Handle 64bit case
  223. out = []
  224. for p in paths:
  225. out.extend([p + '64', p])
  226. return out
  227. if sys.platform == 'win32':
  228. default_lib_dirs = ['C:\\',
  229. os.path.join(sysconfig.get_config_var('exec_prefix'),
  230. 'libs')]
  231. default_runtime_dirs = []
  232. default_include_dirs = []
  233. default_src_dirs = ['.']
  234. default_x11_lib_dirs = []
  235. default_x11_include_dirs = []
  236. _include_dirs = [
  237. 'include',
  238. 'include/suitesparse',
  239. ]
  240. _lib_dirs = [
  241. 'lib',
  242. ]
  243. _include_dirs = [d.replace('/', os.sep) for d in _include_dirs]
  244. _lib_dirs = [d.replace('/', os.sep) for d in _lib_dirs]
  245. def add_system_root(library_root):
  246. """Add a package manager root to the include directories"""
  247. global default_lib_dirs
  248. global default_include_dirs
  249. library_root = os.path.normpath(library_root)
  250. default_lib_dirs.extend(
  251. os.path.join(library_root, d) for d in _lib_dirs)
  252. default_include_dirs.extend(
  253. os.path.join(library_root, d) for d in _include_dirs)
  254. # VCpkg is the de-facto package manager on windows for C/C++
  255. # libraries. If it is on the PATH, then we append its paths here.
  256. vcpkg = shutil.which('vcpkg')
  257. if vcpkg:
  258. vcpkg_dir = os.path.dirname(vcpkg)
  259. if platform.architecture()[0] == '32bit':
  260. specifier = 'x86'
  261. else:
  262. specifier = 'x64'
  263. vcpkg_installed = os.path.join(vcpkg_dir, 'installed')
  264. for vcpkg_root in [
  265. os.path.join(vcpkg_installed, specifier + '-windows'),
  266. os.path.join(vcpkg_installed, specifier + '-windows-static'),
  267. ]:
  268. add_system_root(vcpkg_root)
  269. # Conda is another popular package manager that provides libraries
  270. conda = shutil.which('conda')
  271. if conda:
  272. conda_dir = os.path.dirname(conda)
  273. add_system_root(os.path.join(conda_dir, '..', 'Library'))
  274. add_system_root(os.path.join(conda_dir, 'Library'))
  275. else:
  276. default_lib_dirs = libpaths(['/usr/local/lib', '/opt/lib', '/usr/lib',
  277. '/opt/local/lib', '/sw/lib'], platform_bits)
  278. default_runtime_dirs = []
  279. default_include_dirs = ['/usr/local/include',
  280. '/opt/include',
  281. # path of umfpack under macports
  282. '/opt/local/include/ufsparse',
  283. '/opt/local/include', '/sw/include',
  284. '/usr/include/suitesparse']
  285. default_src_dirs = ['.', '/usr/local/src', '/opt/src', '/sw/src']
  286. default_x11_lib_dirs = libpaths(['/usr/X11R6/lib', '/usr/X11/lib',
  287. '/usr/lib'], platform_bits)
  288. default_x11_include_dirs = ['/usr/X11R6/include', '/usr/X11/include']
  289. if os.path.exists('/usr/lib/X11'):
  290. globbed_x11_dir = glob('/usr/lib/*/libX11.so')
  291. if globbed_x11_dir:
  292. x11_so_dir = os.path.split(globbed_x11_dir[0])[0]
  293. default_x11_lib_dirs.extend([x11_so_dir, '/usr/lib/X11'])
  294. default_x11_include_dirs.extend(['/usr/lib/X11/include',
  295. '/usr/include/X11'])
  296. with open(os.devnull, 'w') as tmp:
  297. try:
  298. p = subprocess.Popen(["gcc", "-print-multiarch"], stdout=subprocess.PIPE,
  299. stderr=tmp)
  300. except (OSError, DistutilsError):
  301. # OSError if gcc is not installed, or SandboxViolation (DistutilsError
  302. # subclass) if an old setuptools bug is triggered (see gh-3160).
  303. pass
  304. else:
  305. triplet = str(p.communicate()[0].decode().strip())
  306. if p.returncode == 0:
  307. # gcc supports the "-print-multiarch" option
  308. default_x11_lib_dirs += [os.path.join("/usr/lib/", triplet)]
  309. default_lib_dirs += [os.path.join("/usr/lib/", triplet)]
  310. if os.path.join(sys.prefix, 'lib') not in default_lib_dirs:
  311. default_lib_dirs.insert(0, os.path.join(sys.prefix, 'lib'))
  312. default_include_dirs.append(os.path.join(sys.prefix, 'include'))
  313. default_src_dirs.append(os.path.join(sys.prefix, 'src'))
  314. default_lib_dirs = [_m for _m in default_lib_dirs if os.path.isdir(_m)]
  315. default_runtime_dirs = [_m for _m in default_runtime_dirs if os.path.isdir(_m)]
  316. default_include_dirs = [_m for _m in default_include_dirs if os.path.isdir(_m)]
  317. default_src_dirs = [_m for _m in default_src_dirs if os.path.isdir(_m)]
  318. so_ext = get_shared_lib_extension()
  319. def get_standard_file(fname):
  320. """Returns a list of files named 'fname' from
  321. 1) System-wide directory (directory-location of this module)
  322. 2) Users HOME directory (os.environ['HOME'])
  323. 3) Local directory
  324. """
  325. # System-wide file
  326. filenames = []
  327. try:
  328. f = __file__
  329. except NameError:
  330. f = sys.argv[0]
  331. else:
  332. sysfile = os.path.join(os.path.split(os.path.abspath(f))[0],
  333. fname)
  334. if os.path.isfile(sysfile):
  335. filenames.append(sysfile)
  336. # Home directory
  337. # And look for the user config file
  338. try:
  339. f = os.path.expanduser('~')
  340. except KeyError:
  341. pass
  342. else:
  343. user_file = os.path.join(f, fname)
  344. if os.path.isfile(user_file):
  345. filenames.append(user_file)
  346. # Local file
  347. if os.path.isfile(fname):
  348. filenames.append(os.path.abspath(fname))
  349. return filenames
  350. def _parse_env_order(base_order, env):
  351. """ Parse an environment variable `env` by splitting with "," and only returning elements from `base_order`
  352. This method will sequence the environment variable and check for their invidual elements in `base_order`.
  353. The items in the environment variable may be negated via '^item' or '!itema,itemb'.
  354. It must start with ^/! to negate all options.
  355. Raises
  356. ------
  357. ValueError: for mixed negated and non-negated orders or multiple negated orders
  358. Parameters
  359. ----------
  360. base_order : list of str
  361. the base list of orders
  362. env : str
  363. the environment variable to be parsed, if none is found, `base_order` is returned
  364. Returns
  365. -------
  366. allow_order : list of str
  367. allowed orders in lower-case
  368. unknown_order : list of str
  369. for values not overlapping with `base_order`
  370. """
  371. order_str = os.environ.get(env, None)
  372. # ensure all base-orders are lower-case (for easier comparison)
  373. base_order = [order.lower() for order in base_order]
  374. if order_str is None:
  375. return base_order, []
  376. neg = order_str.startswith('^') or order_str.startswith('!')
  377. # Check format
  378. order_str_l = list(order_str)
  379. sum_neg = order_str_l.count('^') + order_str_l.count('!')
  380. if neg:
  381. if sum_neg > 1:
  382. raise ValueError(f"Environment variable '{env}' may only contain a single (prefixed) negation: {order_str}")
  383. # remove prefix
  384. order_str = order_str[1:]
  385. elif sum_neg > 0:
  386. raise ValueError(f"Environment variable '{env}' may not mix negated an non-negated items: {order_str}")
  387. # Split and lower case
  388. orders = order_str.lower().split(',')
  389. # to inform callee about non-overlapping elements
  390. unknown_order = []
  391. # if negated, we have to remove from the order
  392. if neg:
  393. allow_order = base_order.copy()
  394. for order in orders:
  395. if not order:
  396. continue
  397. if order not in base_order:
  398. unknown_order.append(order)
  399. continue
  400. if order in allow_order:
  401. allow_order.remove(order)
  402. else:
  403. allow_order = []
  404. for order in orders:
  405. if not order:
  406. continue
  407. if order not in base_order:
  408. unknown_order.append(order)
  409. continue
  410. if order not in allow_order:
  411. allow_order.append(order)
  412. return allow_order, unknown_order
  413. def get_info(name, notfound_action=0):
  414. """
  415. notfound_action:
  416. 0 - do nothing
  417. 1 - display warning message
  418. 2 - raise error
  419. """
  420. cl = {'atlas': atlas_info, # use lapack_opt or blas_opt instead
  421. 'atlas_threads': atlas_threads_info, # ditto
  422. 'atlas_blas': atlas_blas_info,
  423. 'atlas_blas_threads': atlas_blas_threads_info,
  424. 'lapack_atlas': lapack_atlas_info, # use lapack_opt instead
  425. 'lapack_atlas_threads': lapack_atlas_threads_info, # ditto
  426. 'atlas_3_10': atlas_3_10_info, # use lapack_opt or blas_opt instead
  427. 'atlas_3_10_threads': atlas_3_10_threads_info, # ditto
  428. 'atlas_3_10_blas': atlas_3_10_blas_info,
  429. 'atlas_3_10_blas_threads': atlas_3_10_blas_threads_info,
  430. 'lapack_atlas_3_10': lapack_atlas_3_10_info, # use lapack_opt instead
  431. 'lapack_atlas_3_10_threads': lapack_atlas_3_10_threads_info, # ditto
  432. 'flame': flame_info, # use lapack_opt instead
  433. 'mkl': mkl_info,
  434. # openblas which may or may not have embedded lapack
  435. 'openblas': openblas_info, # use blas_opt instead
  436. # openblas with embedded lapack
  437. 'openblas_lapack': openblas_lapack_info, # use blas_opt instead
  438. 'openblas_clapack': openblas_clapack_info, # use blas_opt instead
  439. 'blis': blis_info, # use blas_opt instead
  440. 'lapack_mkl': lapack_mkl_info, # use lapack_opt instead
  441. 'blas_mkl': blas_mkl_info, # use blas_opt instead
  442. 'accelerate': accelerate_info, # use blas_opt instead
  443. 'openblas64_': openblas64__info,
  444. 'openblas64__lapack': openblas64__lapack_info,
  445. 'openblas_ilp64': openblas_ilp64_info,
  446. 'openblas_ilp64_lapack': openblas_ilp64_lapack_info,
  447. 'x11': x11_info,
  448. 'fft_opt': fft_opt_info,
  449. 'fftw': fftw_info,
  450. 'fftw2': fftw2_info,
  451. 'fftw3': fftw3_info,
  452. 'dfftw': dfftw_info,
  453. 'sfftw': sfftw_info,
  454. 'fftw_threads': fftw_threads_info,
  455. 'dfftw_threads': dfftw_threads_info,
  456. 'sfftw_threads': sfftw_threads_info,
  457. 'djbfft': djbfft_info,
  458. 'blas': blas_info, # use blas_opt instead
  459. 'lapack': lapack_info, # use lapack_opt instead
  460. 'lapack_src': lapack_src_info,
  461. 'blas_src': blas_src_info,
  462. 'numpy': numpy_info,
  463. 'f2py': f2py_info,
  464. 'Numeric': Numeric_info,
  465. 'numeric': Numeric_info,
  466. 'numarray': numarray_info,
  467. 'numerix': numerix_info,
  468. 'lapack_opt': lapack_opt_info,
  469. 'lapack_ilp64_opt': lapack_ilp64_opt_info,
  470. 'lapack_ilp64_plain_opt': lapack_ilp64_plain_opt_info,
  471. 'lapack64__opt': lapack64__opt_info,
  472. 'blas_opt': blas_opt_info,
  473. 'blas_ilp64_opt': blas_ilp64_opt_info,
  474. 'blas_ilp64_plain_opt': blas_ilp64_plain_opt_info,
  475. 'blas64__opt': blas64__opt_info,
  476. 'boost_python': boost_python_info,
  477. 'agg2': agg2_info,
  478. 'wx': wx_info,
  479. 'gdk_pixbuf_xlib_2': gdk_pixbuf_xlib_2_info,
  480. 'gdk-pixbuf-xlib-2.0': gdk_pixbuf_xlib_2_info,
  481. 'gdk_pixbuf_2': gdk_pixbuf_2_info,
  482. 'gdk-pixbuf-2.0': gdk_pixbuf_2_info,
  483. 'gdk': gdk_info,
  484. 'gdk_2': gdk_2_info,
  485. 'gdk-2.0': gdk_2_info,
  486. 'gdk_x11_2': gdk_x11_2_info,
  487. 'gdk-x11-2.0': gdk_x11_2_info,
  488. 'gtkp_x11_2': gtkp_x11_2_info,
  489. 'gtk+-x11-2.0': gtkp_x11_2_info,
  490. 'gtkp_2': gtkp_2_info,
  491. 'gtk+-2.0': gtkp_2_info,
  492. 'xft': xft_info,
  493. 'freetype2': freetype2_info,
  494. 'umfpack': umfpack_info,
  495. 'amd': amd_info,
  496. }.get(name.lower(), system_info)
  497. return cl().get_info(notfound_action)
  498. class NotFoundError(DistutilsError):
  499. """Some third-party program or library is not found."""
  500. class AliasedOptionError(DistutilsError):
  501. """
  502. Aliases entries in config files should not be existing.
  503. In section '{section}' we found multiple appearances of options {options}."""
  504. class AtlasNotFoundError(NotFoundError):
  505. """
  506. Atlas (http://github.com/math-atlas/math-atlas) libraries not found.
  507. Directories to search for the libraries can be specified in the
  508. numpy/distutils/site.cfg file (section [atlas]) or by setting
  509. the ATLAS environment variable."""
  510. class FlameNotFoundError(NotFoundError):
  511. """
  512. FLAME (http://www.cs.utexas.edu/~flame/web/) libraries not found.
  513. Directories to search for the libraries can be specified in the
  514. numpy/distutils/site.cfg file (section [flame])."""
  515. class LapackNotFoundError(NotFoundError):
  516. """
  517. Lapack (http://www.netlib.org/lapack/) libraries not found.
  518. Directories to search for the libraries can be specified in the
  519. numpy/distutils/site.cfg file (section [lapack]) or by setting
  520. the LAPACK environment variable."""
  521. class LapackSrcNotFoundError(LapackNotFoundError):
  522. """
  523. Lapack (http://www.netlib.org/lapack/) sources not found.
  524. Directories to search for the sources can be specified in the
  525. numpy/distutils/site.cfg file (section [lapack_src]) or by setting
  526. the LAPACK_SRC environment variable."""
  527. class LapackILP64NotFoundError(NotFoundError):
  528. """
  529. 64-bit Lapack libraries not found.
  530. Known libraries in numpy/distutils/site.cfg file are:
  531. openblas64_, openblas_ilp64
  532. """
  533. class BlasOptNotFoundError(NotFoundError):
  534. """
  535. Optimized (vendor) Blas libraries are not found.
  536. Falls back to netlib Blas library which has worse performance.
  537. A better performance should be easily gained by switching
  538. Blas library."""
  539. class BlasNotFoundError(NotFoundError):
  540. """
  541. Blas (http://www.netlib.org/blas/) libraries not found.
  542. Directories to search for the libraries can be specified in the
  543. numpy/distutils/site.cfg file (section [blas]) or by setting
  544. the BLAS environment variable."""
  545. class BlasILP64NotFoundError(NotFoundError):
  546. """
  547. 64-bit Blas libraries not found.
  548. Known libraries in numpy/distutils/site.cfg file are:
  549. openblas64_, openblas_ilp64
  550. """
  551. class BlasSrcNotFoundError(BlasNotFoundError):
  552. """
  553. Blas (http://www.netlib.org/blas/) sources not found.
  554. Directories to search for the sources can be specified in the
  555. numpy/distutils/site.cfg file (section [blas_src]) or by setting
  556. the BLAS_SRC environment variable."""
  557. class FFTWNotFoundError(NotFoundError):
  558. """
  559. FFTW (http://www.fftw.org/) libraries not found.
  560. Directories to search for the libraries can be specified in the
  561. numpy/distutils/site.cfg file (section [fftw]) or by setting
  562. the FFTW environment variable."""
  563. class DJBFFTNotFoundError(NotFoundError):
  564. """
  565. DJBFFT (https://cr.yp.to/djbfft.html) libraries not found.
  566. Directories to search for the libraries can be specified in the
  567. numpy/distutils/site.cfg file (section [djbfft]) or by setting
  568. the DJBFFT environment variable."""
  569. class NumericNotFoundError(NotFoundError):
  570. """
  571. Numeric (https://www.numpy.org/) module not found.
  572. Get it from above location, install it, and retry setup.py."""
  573. class X11NotFoundError(NotFoundError):
  574. """X11 libraries not found."""
  575. class UmfpackNotFoundError(NotFoundError):
  576. """
  577. UMFPACK sparse solver (https://www.cise.ufl.edu/research/sparse/umfpack/)
  578. not found. Directories to search for the libraries can be specified in the
  579. numpy/distutils/site.cfg file (section [umfpack]) or by setting
  580. the UMFPACK environment variable."""
  581. class system_info:
  582. """ get_info() is the only public method. Don't use others.
  583. """
  584. dir_env_var = None
  585. # XXX: search_static_first is disabled by default, may disappear in
  586. # future unless it is proved to be useful.
  587. search_static_first = 0
  588. # The base-class section name is a random word "ALL" and is not really
  589. # intended for general use. It cannot be None nor can it be DEFAULT as
  590. # these break the ConfigParser. See gh-15338
  591. section = 'ALL'
  592. saved_results = {}
  593. notfounderror = NotFoundError
  594. def __init__(self,
  595. default_lib_dirs=default_lib_dirs,
  596. default_include_dirs=default_include_dirs,
  597. ):
  598. self.__class__.info = {}
  599. self.local_prefixes = []
  600. defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
  601. 'include_dirs': os.pathsep.join(default_include_dirs),
  602. 'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
  603. 'rpath': '',
  604. 'src_dirs': os.pathsep.join(default_src_dirs),
  605. 'search_static_first': str(self.search_static_first),
  606. 'extra_compile_args': '', 'extra_link_args': ''}
  607. self.cp = ConfigParser(defaults)
  608. self.files = []
  609. self.files.extend(get_standard_file('.numpy-site.cfg'))
  610. self.files.extend(get_standard_file('site.cfg'))
  611. self.parse_config_files()
  612. if self.section is not None:
  613. self.search_static_first = self.cp.getboolean(
  614. self.section, 'search_static_first')
  615. assert isinstance(self.search_static_first, int)
  616. def parse_config_files(self):
  617. self.cp.read(self.files)
  618. if not self.cp.has_section(self.section):
  619. if self.section is not None:
  620. self.cp.add_section(self.section)
  621. def calc_libraries_info(self):
  622. libs = self.get_libraries()
  623. dirs = self.get_lib_dirs()
  624. # The extensions use runtime_library_dirs
  625. r_dirs = self.get_runtime_lib_dirs()
  626. # Intrinsic distutils use rpath, we simply append both entries
  627. # as though they were one entry
  628. r_dirs.extend(self.get_runtime_lib_dirs(key='rpath'))
  629. info = {}
  630. for lib in libs:
  631. i = self.check_libs(dirs, [lib])
  632. if i is not None:
  633. dict_append(info, **i)
  634. else:
  635. log.info('Library %s was not found. Ignoring' % (lib))
  636. if r_dirs:
  637. i = self.check_libs(r_dirs, [lib])
  638. if i is not None:
  639. # Swap library keywords found to runtime_library_dirs
  640. # the libraries are insisting on the user having defined
  641. # them using the library_dirs, and not necessarily by
  642. # runtime_library_dirs
  643. del i['libraries']
  644. i['runtime_library_dirs'] = i.pop('library_dirs')
  645. dict_append(info, **i)
  646. else:
  647. log.info('Runtime library %s was not found. Ignoring' % (lib))
  648. return info
  649. def set_info(self, **info):
  650. if info:
  651. lib_info = self.calc_libraries_info()
  652. dict_append(info, **lib_info)
  653. # Update extra information
  654. extra_info = self.calc_extra_info()
  655. dict_append(info, **extra_info)
  656. self.saved_results[self.__class__.__name__] = info
  657. def get_option_single(self, *options):
  658. """ Ensure that only one of `options` are found in the section
  659. Parameters
  660. ----------
  661. *options : list of str
  662. a list of options to be found in the section (``self.section``)
  663. Returns
  664. -------
  665. str :
  666. the option that is uniquely found in the section
  667. Raises
  668. ------
  669. AliasedOptionError :
  670. in case more than one of the options are found
  671. """
  672. found = [self.cp.has_option(self.section, opt) for opt in options]
  673. if sum(found) == 1:
  674. return options[found.index(True)]
  675. elif sum(found) == 0:
  676. # nothing is found anyways
  677. return options[0]
  678. # Else we have more than 1 key found
  679. if AliasedOptionError.__doc__ is None:
  680. raise AliasedOptionError()
  681. raise AliasedOptionError(AliasedOptionError.__doc__.format(
  682. section=self.section, options='[{}]'.format(', '.join(options))))
  683. def has_info(self):
  684. return self.__class__.__name__ in self.saved_results
  685. def calc_extra_info(self):
  686. """ Updates the information in the current information with
  687. respect to these flags:
  688. extra_compile_args
  689. extra_link_args
  690. """
  691. info = {}
  692. for key in ['extra_compile_args', 'extra_link_args']:
  693. # Get values
  694. opt = self.cp.get(self.section, key)
  695. opt = _shell_utils.NativeParser.split(opt)
  696. if opt:
  697. tmp = {key: opt}
  698. dict_append(info, **tmp)
  699. return info
  700. def get_info(self, notfound_action=0):
  701. """ Return a dictionary with items that are compatible
  702. with numpy.distutils.setup keyword arguments.
  703. """
  704. flag = 0
  705. if not self.has_info():
  706. flag = 1
  707. log.info(self.__class__.__name__ + ':')
  708. if hasattr(self, 'calc_info'):
  709. self.calc_info()
  710. if notfound_action:
  711. if not self.has_info():
  712. if notfound_action == 1:
  713. warnings.warn(self.notfounderror.__doc__, stacklevel=2)
  714. elif notfound_action == 2:
  715. raise self.notfounderror(self.notfounderror.__doc__)
  716. else:
  717. raise ValueError(repr(notfound_action))
  718. if not self.has_info():
  719. log.info(' NOT AVAILABLE')
  720. self.set_info()
  721. else:
  722. log.info(' FOUND:')
  723. res = self.saved_results.get(self.__class__.__name__)
  724. if log.get_threshold() <= log.INFO and flag:
  725. for k, v in res.items():
  726. v = str(v)
  727. if k in ['sources', 'libraries'] and len(v) > 270:
  728. v = v[:120] + '...\n...\n...' + v[-120:]
  729. log.info(' %s = %s', k, v)
  730. log.info('')
  731. return copy.deepcopy(res)
  732. def get_paths(self, section, key):
  733. dirs = self.cp.get(section, key).split(os.pathsep)
  734. env_var = self.dir_env_var
  735. if env_var:
  736. if is_sequence(env_var):
  737. e0 = env_var[-1]
  738. for e in env_var:
  739. if e in os.environ:
  740. e0 = e
  741. break
  742. if not env_var[0] == e0:
  743. log.info('Setting %s=%s' % (env_var[0], e0))
  744. env_var = e0
  745. if env_var and env_var in os.environ:
  746. d = os.environ[env_var]
  747. if d == 'None':
  748. log.info('Disabled %s: %s',
  749. self.__class__.__name__, '(%s is None)'
  750. % (env_var,))
  751. return []
  752. if os.path.isfile(d):
  753. dirs = [os.path.dirname(d)] + dirs
  754. l = getattr(self, '_lib_names', [])
  755. if len(l) == 1:
  756. b = os.path.basename(d)
  757. b = os.path.splitext(b)[0]
  758. if b[:3] == 'lib':
  759. log.info('Replacing _lib_names[0]==%r with %r' \
  760. % (self._lib_names[0], b[3:]))
  761. self._lib_names[0] = b[3:]
  762. else:
  763. ds = d.split(os.pathsep)
  764. ds2 = []
  765. for d in ds:
  766. if os.path.isdir(d):
  767. ds2.append(d)
  768. for dd in ['include', 'lib']:
  769. d1 = os.path.join(d, dd)
  770. if os.path.isdir(d1):
  771. ds2.append(d1)
  772. dirs = ds2 + dirs
  773. default_dirs = self.cp.get(self.section, key).split(os.pathsep)
  774. dirs.extend(default_dirs)
  775. ret = []
  776. for d in dirs:
  777. if len(d) > 0 and not os.path.isdir(d):
  778. warnings.warn('Specified path %s is invalid.' % d, stacklevel=2)
  779. continue
  780. if d not in ret:
  781. ret.append(d)
  782. log.debug('( %s = %s )', key, ':'.join(ret))
  783. return ret
  784. def get_lib_dirs(self, key='library_dirs'):
  785. return self.get_paths(self.section, key)
  786. def get_runtime_lib_dirs(self, key='runtime_library_dirs'):
  787. path = self.get_paths(self.section, key)
  788. if path == ['']:
  789. path = []
  790. return path
  791. def get_include_dirs(self, key='include_dirs'):
  792. return self.get_paths(self.section, key)
  793. def get_src_dirs(self, key='src_dirs'):
  794. return self.get_paths(self.section, key)
  795. def get_libs(self, key, default):
  796. try:
  797. libs = self.cp.get(self.section, key)
  798. except NoOptionError:
  799. if not default:
  800. return []
  801. if is_string(default):
  802. return [default]
  803. return default
  804. return [b for b in [a.strip() for a in libs.split(',')] if b]
  805. def get_libraries(self, key='libraries'):
  806. if hasattr(self, '_lib_names'):
  807. return self.get_libs(key, default=self._lib_names)
  808. else:
  809. return self.get_libs(key, '')
  810. def library_extensions(self):
  811. c = customized_ccompiler()
  812. static_exts = []
  813. if c.compiler_type != 'msvc':
  814. # MSVC doesn't understand binutils
  815. static_exts.append('.a')
  816. if sys.platform == 'win32':
  817. static_exts.append('.lib') # .lib is used by MSVC and others
  818. if self.search_static_first:
  819. exts = static_exts + [so_ext]
  820. else:
  821. exts = [so_ext] + static_exts
  822. if sys.platform == 'cygwin':
  823. exts.append('.dll.a')
  824. if sys.platform == 'darwin':
  825. exts.append('.dylib')
  826. return exts
  827. def check_libs(self, lib_dirs, libs, opt_libs=[]):
  828. """If static or shared libraries are available then return
  829. their info dictionary.
  830. Checks for all libraries as shared libraries first, then
  831. static (or vice versa if self.search_static_first is True).
  832. """
  833. exts = self.library_extensions()
  834. info = None
  835. for ext in exts:
  836. info = self._check_libs(lib_dirs, libs, opt_libs, [ext])
  837. if info is not None:
  838. break
  839. if not info:
  840. log.info(' libraries %s not found in %s', ','.join(libs),
  841. lib_dirs)
  842. return info
  843. def check_libs2(self, lib_dirs, libs, opt_libs=[]):
  844. """If static or shared libraries are available then return
  845. their info dictionary.
  846. Checks each library for shared or static.
  847. """
  848. exts = self.library_extensions()
  849. info = self._check_libs(lib_dirs, libs, opt_libs, exts)
  850. if not info:
  851. log.info(' libraries %s not found in %s', ','.join(libs),
  852. lib_dirs)
  853. return info
  854. def _find_lib(self, lib_dir, lib, exts):
  855. assert is_string(lib_dir)
  856. # under windows first try without 'lib' prefix
  857. if sys.platform == 'win32':
  858. lib_prefixes = ['', 'lib']
  859. else:
  860. lib_prefixes = ['lib']
  861. # for each library name, see if we can find a file for it.
  862. for ext in exts:
  863. for prefix in lib_prefixes:
  864. p = self.combine_paths(lib_dir, prefix + lib + ext)
  865. if p:
  866. break
  867. if p:
  868. assert len(p) == 1
  869. # ??? splitext on p[0] would do this for cygwin
  870. # doesn't seem correct
  871. if ext == '.dll.a':
  872. lib += '.dll'
  873. if ext == '.lib':
  874. lib = prefix + lib
  875. return lib
  876. return False
  877. def _find_libs(self, lib_dirs, libs, exts):
  878. # make sure we preserve the order of libs, as it can be important
  879. found_dirs, found_libs = [], []
  880. for lib in libs:
  881. for lib_dir in lib_dirs:
  882. found_lib = self._find_lib(lib_dir, lib, exts)
  883. if found_lib:
  884. found_libs.append(found_lib)
  885. if lib_dir not in found_dirs:
  886. found_dirs.append(lib_dir)
  887. break
  888. return found_dirs, found_libs
  889. def _check_libs(self, lib_dirs, libs, opt_libs, exts):
  890. """Find mandatory and optional libs in expected paths.
  891. Missing optional libraries are silently forgotten.
  892. """
  893. if not is_sequence(lib_dirs):
  894. lib_dirs = [lib_dirs]
  895. # First, try to find the mandatory libraries
  896. found_dirs, found_libs = self._find_libs(lib_dirs, libs, exts)
  897. if len(found_libs) > 0 and len(found_libs) == len(libs):
  898. # Now, check for optional libraries
  899. opt_found_dirs, opt_found_libs = self._find_libs(lib_dirs, opt_libs, exts)
  900. found_libs.extend(opt_found_libs)
  901. for lib_dir in opt_found_dirs:
  902. if lib_dir not in found_dirs:
  903. found_dirs.append(lib_dir)
  904. info = {'libraries': found_libs, 'library_dirs': found_dirs}
  905. return info
  906. else:
  907. return None
  908. def combine_paths(self, *args):
  909. """Return a list of existing paths composed by all combinations
  910. of items from the arguments.
  911. """
  912. return combine_paths(*args)
  913. class fft_opt_info(system_info):
  914. def calc_info(self):
  915. info = {}
  916. fftw_info = get_info('fftw3') or get_info('fftw2') or get_info('dfftw')
  917. djbfft_info = get_info('djbfft')
  918. if fftw_info:
  919. dict_append(info, **fftw_info)
  920. if djbfft_info:
  921. dict_append(info, **djbfft_info)
  922. self.set_info(**info)
  923. return
  924. class fftw_info(system_info):
  925. #variables to override
  926. section = 'fftw'
  927. dir_env_var = 'FFTW'
  928. notfounderror = FFTWNotFoundError
  929. ver_info = [{'name':'fftw3',
  930. 'libs':['fftw3'],
  931. 'includes':['fftw3.h'],
  932. 'macros':[('SCIPY_FFTW3_H', None)]},
  933. {'name':'fftw2',
  934. 'libs':['rfftw', 'fftw'],
  935. 'includes':['fftw.h', 'rfftw.h'],
  936. 'macros':[('SCIPY_FFTW_H', None)]}]
  937. def calc_ver_info(self, ver_param):
  938. """Returns True on successful version detection, else False"""
  939. lib_dirs = self.get_lib_dirs()
  940. incl_dirs = self.get_include_dirs()
  941. opt = self.get_option_single(self.section + '_libs', 'libraries')
  942. libs = self.get_libs(opt, ver_param['libs'])
  943. info = self.check_libs(lib_dirs, libs)
  944. if info is not None:
  945. flag = 0
  946. for d in incl_dirs:
  947. if len(self.combine_paths(d, ver_param['includes'])) \
  948. == len(ver_param['includes']):
  949. dict_append(info, include_dirs=[d])
  950. flag = 1
  951. break
  952. if flag:
  953. dict_append(info, define_macros=ver_param['macros'])
  954. else:
  955. info = None
  956. if info is not None:
  957. self.set_info(**info)
  958. return True
  959. else:
  960. log.info(' %s not found' % (ver_param['name']))
  961. return False
  962. def calc_info(self):
  963. for i in self.ver_info:
  964. if self.calc_ver_info(i):
  965. break
  966. class fftw2_info(fftw_info):
  967. #variables to override
  968. section = 'fftw'
  969. dir_env_var = 'FFTW'
  970. notfounderror = FFTWNotFoundError
  971. ver_info = [{'name':'fftw2',
  972. 'libs':['rfftw', 'fftw'],
  973. 'includes':['fftw.h', 'rfftw.h'],
  974. 'macros':[('SCIPY_FFTW_H', None)]}
  975. ]
  976. class fftw3_info(fftw_info):
  977. #variables to override
  978. section = 'fftw3'
  979. dir_env_var = 'FFTW3'
  980. notfounderror = FFTWNotFoundError
  981. ver_info = [{'name':'fftw3',
  982. 'libs':['fftw3'],
  983. 'includes':['fftw3.h'],
  984. 'macros':[('SCIPY_FFTW3_H', None)]},
  985. ]
  986. class dfftw_info(fftw_info):
  987. section = 'fftw'
  988. dir_env_var = 'FFTW'
  989. ver_info = [{'name':'dfftw',
  990. 'libs':['drfftw', 'dfftw'],
  991. 'includes':['dfftw.h', 'drfftw.h'],
  992. 'macros':[('SCIPY_DFFTW_H', None)]}]
  993. class sfftw_info(fftw_info):
  994. section = 'fftw'
  995. dir_env_var = 'FFTW'
  996. ver_info = [{'name':'sfftw',
  997. 'libs':['srfftw', 'sfftw'],
  998. 'includes':['sfftw.h', 'srfftw.h'],
  999. 'macros':[('SCIPY_SFFTW_H', None)]}]
  1000. class fftw_threads_info(fftw_info):
  1001. section = 'fftw'
  1002. dir_env_var = 'FFTW'
  1003. ver_info = [{'name':'fftw threads',
  1004. 'libs':['rfftw_threads', 'fftw_threads'],
  1005. 'includes':['fftw_threads.h', 'rfftw_threads.h'],
  1006. 'macros':[('SCIPY_FFTW_THREADS_H', None)]}]
  1007. class dfftw_threads_info(fftw_info):
  1008. section = 'fftw'
  1009. dir_env_var = 'FFTW'
  1010. ver_info = [{'name':'dfftw threads',
  1011. 'libs':['drfftw_threads', 'dfftw_threads'],
  1012. 'includes':['dfftw_threads.h', 'drfftw_threads.h'],
  1013. 'macros':[('SCIPY_DFFTW_THREADS_H', None)]}]
  1014. class sfftw_threads_info(fftw_info):
  1015. section = 'fftw'
  1016. dir_env_var = 'FFTW'
  1017. ver_info = [{'name':'sfftw threads',
  1018. 'libs':['srfftw_threads', 'sfftw_threads'],
  1019. 'includes':['sfftw_threads.h', 'srfftw_threads.h'],
  1020. 'macros':[('SCIPY_SFFTW_THREADS_H', None)]}]
  1021. class djbfft_info(system_info):
  1022. section = 'djbfft'
  1023. dir_env_var = 'DJBFFT'
  1024. notfounderror = DJBFFTNotFoundError
  1025. def get_paths(self, section, key):
  1026. pre_dirs = system_info.get_paths(self, section, key)
  1027. dirs = []
  1028. for d in pre_dirs:
  1029. dirs.extend(self.combine_paths(d, ['djbfft']) + [d])
  1030. return [d for d in dirs if os.path.isdir(d)]
  1031. def calc_info(self):
  1032. lib_dirs = self.get_lib_dirs()
  1033. incl_dirs = self.get_include_dirs()
  1034. info = None
  1035. for d in lib_dirs:
  1036. p = self.combine_paths(d, ['djbfft.a'])
  1037. if p:
  1038. info = {'extra_objects': p}
  1039. break
  1040. p = self.combine_paths(d, ['libdjbfft.a', 'libdjbfft' + so_ext])
  1041. if p:
  1042. info = {'libraries': ['djbfft'], 'library_dirs': [d]}
  1043. break
  1044. if info is None:
  1045. return
  1046. for d in incl_dirs:
  1047. if len(self.combine_paths(d, ['fftc8.h', 'fftfreq.h'])) == 2:
  1048. dict_append(info, include_dirs=[d],
  1049. define_macros=[('SCIPY_DJBFFT_H', None)])
  1050. self.set_info(**info)
  1051. return
  1052. return
  1053. class mkl_info(system_info):
  1054. section = 'mkl'
  1055. dir_env_var = 'MKLROOT'
  1056. _lib_mkl = ['mkl_rt']
  1057. def get_mkl_rootdir(self):
  1058. mklroot = os.environ.get('MKLROOT', None)
  1059. if mklroot is not None:
  1060. return mklroot
  1061. paths = os.environ.get('LD_LIBRARY_PATH', '').split(os.pathsep)
  1062. ld_so_conf = '/etc/ld.so.conf'
  1063. if os.path.isfile(ld_so_conf):
  1064. with open(ld_so_conf, 'r') as f:
  1065. for d in f:
  1066. d = d.strip()
  1067. if d:
  1068. paths.append(d)
  1069. intel_mkl_dirs = []
  1070. for path in paths:
  1071. path_atoms = path.split(os.sep)
  1072. for m in path_atoms:
  1073. if m.startswith('mkl'):
  1074. d = os.sep.join(path_atoms[:path_atoms.index(m) + 2])
  1075. intel_mkl_dirs.append(d)
  1076. break
  1077. for d in paths:
  1078. dirs = glob(os.path.join(d, 'mkl', '*'))
  1079. dirs += glob(os.path.join(d, 'mkl*'))
  1080. for sub_dir in dirs:
  1081. if os.path.isdir(os.path.join(sub_dir, 'lib')):
  1082. return sub_dir
  1083. return None
  1084. def __init__(self):
  1085. mklroot = self.get_mkl_rootdir()
  1086. if mklroot is None:
  1087. system_info.__init__(self)
  1088. else:
  1089. from .cpuinfo import cpu
  1090. if cpu.is_Itanium():
  1091. plt = '64'
  1092. elif cpu.is_Intel() and cpu.is_64bit():
  1093. plt = 'intel64'
  1094. else:
  1095. plt = '32'
  1096. system_info.__init__(
  1097. self,
  1098. default_lib_dirs=[os.path.join(mklroot, 'lib', plt)],
  1099. default_include_dirs=[os.path.join(mklroot, 'include')])
  1100. def calc_info(self):
  1101. lib_dirs = self.get_lib_dirs()
  1102. incl_dirs = self.get_include_dirs()
  1103. opt = self.get_option_single('mkl_libs', 'libraries')
  1104. mkl_libs = self.get_libs(opt, self._lib_mkl)
  1105. info = self.check_libs2(lib_dirs, mkl_libs)
  1106. if info is None:
  1107. return
  1108. dict_append(info,
  1109. define_macros=[('SCIPY_MKL_H', None),
  1110. ('HAVE_CBLAS', None)],
  1111. include_dirs=incl_dirs)
  1112. if sys.platform == 'win32':
  1113. pass # win32 has no pthread library
  1114. else:
  1115. dict_append(info, libraries=['pthread'])
  1116. self.set_info(**info)
  1117. class lapack_mkl_info(mkl_info):
  1118. pass
  1119. class blas_mkl_info(mkl_info):
  1120. pass
  1121. class atlas_info(system_info):
  1122. section = 'atlas'
  1123. dir_env_var = 'ATLAS'
  1124. _lib_names = ['f77blas', 'cblas']
  1125. if sys.platform[:7] == 'freebsd':
  1126. _lib_atlas = ['atlas_r']
  1127. _lib_lapack = ['alapack_r']
  1128. else:
  1129. _lib_atlas = ['atlas']
  1130. _lib_lapack = ['lapack']
  1131. notfounderror = AtlasNotFoundError
  1132. def get_paths(self, section, key):
  1133. pre_dirs = system_info.get_paths(self, section, key)
  1134. dirs = []
  1135. for d in pre_dirs:
  1136. dirs.extend(self.combine_paths(d, ['atlas*', 'ATLAS*',
  1137. 'sse', '3dnow', 'sse2']) + [d])
  1138. return [d for d in dirs if os.path.isdir(d)]
  1139. def calc_info(self):
  1140. lib_dirs = self.get_lib_dirs()
  1141. info = {}
  1142. opt = self.get_option_single('atlas_libs', 'libraries')
  1143. atlas_libs = self.get_libs(opt, self._lib_names + self._lib_atlas)
  1144. lapack_libs = self.get_libs('lapack_libs', self._lib_lapack)
  1145. atlas = None
  1146. lapack = None
  1147. atlas_1 = None
  1148. for d in lib_dirs:
  1149. # FIXME: lapack_atlas is unused
  1150. lapack_atlas = self.check_libs2(d, ['lapack_atlas'], [])
  1151. atlas = self.check_libs2(d, atlas_libs, [])
  1152. if atlas is not None:
  1153. lib_dirs2 = [d] + self.combine_paths(d, ['atlas*', 'ATLAS*'])
  1154. lapack = self.check_libs2(lib_dirs2, lapack_libs, [])
  1155. if lapack is not None:
  1156. break
  1157. if atlas:
  1158. atlas_1 = atlas
  1159. log.info(self.__class__)
  1160. if atlas is None:
  1161. atlas = atlas_1
  1162. if atlas is None:
  1163. return
  1164. include_dirs = self.get_include_dirs()
  1165. h = (self.combine_paths(lib_dirs + include_dirs, 'cblas.h') or [None])
  1166. h = h[0]
  1167. if h:
  1168. h = os.path.dirname(h)
  1169. dict_append(info, include_dirs=[h])
  1170. info['language'] = 'c'
  1171. if lapack is not None:
  1172. dict_append(info, **lapack)
  1173. dict_append(info, **atlas)
  1174. elif 'lapack_atlas' in atlas['libraries']:
  1175. dict_append(info, **atlas)
  1176. dict_append(info,
  1177. define_macros=[('ATLAS_WITH_LAPACK_ATLAS', None)])
  1178. self.set_info(**info)
  1179. return
  1180. else:
  1181. dict_append(info, **atlas)
  1182. dict_append(info, define_macros=[('ATLAS_WITHOUT_LAPACK', None)])
  1183. message = textwrap.dedent("""
  1184. *********************************************************************
  1185. Could not find lapack library within the ATLAS installation.
  1186. *********************************************************************
  1187. """)
  1188. warnings.warn(message, stacklevel=2)
  1189. self.set_info(**info)
  1190. return
  1191. # Check if lapack library is complete, only warn if it is not.
  1192. lapack_dir = lapack['library_dirs'][0]
  1193. lapack_name = lapack['libraries'][0]
  1194. lapack_lib = None
  1195. lib_prefixes = ['lib']
  1196. if sys.platform == 'win32':
  1197. lib_prefixes.append('')
  1198. for e in self.library_extensions():
  1199. for prefix in lib_prefixes:
  1200. fn = os.path.join(lapack_dir, prefix + lapack_name + e)
  1201. if os.path.exists(fn):
  1202. lapack_lib = fn
  1203. break
  1204. if lapack_lib:
  1205. break
  1206. if lapack_lib is not None:
  1207. sz = os.stat(lapack_lib)[6]
  1208. if sz <= 4000 * 1024:
  1209. message = textwrap.dedent("""
  1210. *********************************************************************
  1211. Lapack library (from ATLAS) is probably incomplete:
  1212. size of %s is %sk (expected >4000k)
  1213. Follow the instructions in the KNOWN PROBLEMS section of the file
  1214. numpy/INSTALL.txt.
  1215. *********************************************************************
  1216. """) % (lapack_lib, sz / 1024)
  1217. warnings.warn(message, stacklevel=2)
  1218. else:
  1219. info['language'] = 'f77'
  1220. atlas_version, atlas_extra_info = get_atlas_version(**atlas)
  1221. dict_append(info, **atlas_extra_info)
  1222. self.set_info(**info)
  1223. class atlas_blas_info(atlas_info):
  1224. _lib_names = ['f77blas', 'cblas']
  1225. def calc_info(self):
  1226. lib_dirs = self.get_lib_dirs()
  1227. info = {}
  1228. opt = self.get_option_single('atlas_libs', 'libraries')
  1229. atlas_libs = self.get_libs(opt, self._lib_names + self._lib_atlas)
  1230. atlas = self.check_libs2(lib_dirs, atlas_libs, [])
  1231. if atlas is None:
  1232. return
  1233. include_dirs = self.get_include_dirs()
  1234. h = (self.combine_paths(lib_dirs + include_dirs, 'cblas.h') or [None])
  1235. h = h[0]
  1236. if h:
  1237. h = os.path.dirname(h)
  1238. dict_append(info, include_dirs=[h])
  1239. info['language'] = 'c'
  1240. info['define_macros'] = [('HAVE_CBLAS', None)]
  1241. atlas_version, atlas_extra_info = get_atlas_version(**atlas)
  1242. dict_append(atlas, **atlas_extra_info)
  1243. dict_append(info, **atlas)
  1244. self.set_info(**info)
  1245. return
  1246. class atlas_threads_info(atlas_info):
  1247. dir_env_var = ['PTATLAS', 'ATLAS']
  1248. _lib_names = ['ptf77blas', 'ptcblas']
  1249. class atlas_blas_threads_info(atlas_blas_info):
  1250. dir_env_var = ['PTATLAS', 'ATLAS']
  1251. _lib_names = ['ptf77blas', 'ptcblas']
  1252. class lapack_atlas_info(atlas_info):
  1253. _lib_names = ['lapack_atlas'] + atlas_info._lib_names
  1254. class lapack_atlas_threads_info(atlas_threads_info):
  1255. _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names
  1256. class atlas_3_10_info(atlas_info):
  1257. _lib_names = ['satlas']
  1258. _lib_atlas = _lib_names
  1259. _lib_lapack = _lib_names
  1260. class atlas_3_10_blas_info(atlas_3_10_info):
  1261. _lib_names = ['satlas']
  1262. def calc_info(self):
  1263. lib_dirs = self.get_lib_dirs()
  1264. info = {}
  1265. opt = self.get_option_single('atlas_lib', 'libraries')
  1266. atlas_libs = self.get_libs(opt, self._lib_names)
  1267. atlas = self.check_libs2(lib_dirs, atlas_libs, [])
  1268. if atlas is None:
  1269. return
  1270. include_dirs = self.get_include_dirs()
  1271. h = (self.combine_paths(lib_dirs + include_dirs, 'cblas.h') or [None])
  1272. h = h[0]
  1273. if h:
  1274. h = os.path.dirname(h)
  1275. dict_append(info, include_dirs=[h])
  1276. info['language'] = 'c'
  1277. info['define_macros'] = [('HAVE_CBLAS', None)]
  1278. atlas_version, atlas_extra_info = get_atlas_version(**atlas)
  1279. dict_append(atlas, **atlas_extra_info)
  1280. dict_append(info, **atlas)
  1281. self.set_info(**info)
  1282. return
  1283. class atlas_3_10_threads_info(atlas_3_10_info):
  1284. dir_env_var = ['PTATLAS', 'ATLAS']
  1285. _lib_names = ['tatlas']
  1286. _lib_atlas = _lib_names
  1287. _lib_lapack = _lib_names
  1288. class atlas_3_10_blas_threads_info(atlas_3_10_blas_info):
  1289. dir_env_var = ['PTATLAS', 'ATLAS']
  1290. _lib_names = ['tatlas']
  1291. class lapack_atlas_3_10_info(atlas_3_10_info):
  1292. pass
  1293. class lapack_atlas_3_10_threads_info(atlas_3_10_threads_info):
  1294. pass
  1295. class lapack_info(system_info):
  1296. section = 'lapack'
  1297. dir_env_var = 'LAPACK'
  1298. _lib_names = ['lapack']
  1299. notfounderror = LapackNotFoundError
  1300. def calc_info(self):
  1301. lib_dirs = self.get_lib_dirs()
  1302. opt = self.get_option_single('lapack_libs', 'libraries')
  1303. lapack_libs = self.get_libs(opt, self._lib_names)
  1304. info = self.check_libs(lib_dirs, lapack_libs, [])
  1305. if info is None:
  1306. return
  1307. info['language'] = 'f77'
  1308. self.set_info(**info)
  1309. class lapack_src_info(system_info):
  1310. # LAPACK_SRC is deprecated, please do not use this!
  1311. # Build or install a BLAS library via your package manager or from
  1312. # source separately.
  1313. section = 'lapack_src'
  1314. dir_env_var = 'LAPACK_SRC'
  1315. notfounderror = LapackSrcNotFoundError
  1316. def get_paths(self, section, key):
  1317. pre_dirs = system_info.get_paths(self, section, key)
  1318. dirs = []
  1319. for d in pre_dirs:
  1320. dirs.extend([d] + self.combine_paths(d, ['LAPACK*/SRC', 'SRC']))
  1321. return [d for d in dirs if os.path.isdir(d)]
  1322. def calc_info(self):
  1323. src_dirs = self.get_src_dirs()
  1324. src_dir = ''
  1325. for d in src_dirs:
  1326. if os.path.isfile(os.path.join(d, 'dgesv.f')):
  1327. src_dir = d
  1328. break
  1329. if not src_dir:
  1330. #XXX: Get sources from netlib. May be ask first.
  1331. return
  1332. # The following is extracted from LAPACK-3.0/SRC/Makefile.
  1333. # Added missing names from lapack-lite-3.1.1/SRC/Makefile
  1334. # while keeping removed names for Lapack-3.0 compatibility.
  1335. allaux = '''
  1336. ilaenv ieeeck lsame lsamen xerbla
  1337. iparmq
  1338. ''' # *.f
  1339. laux = '''
  1340. bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1
  1341. laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2
  1342. lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre
  1343. larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4
  1344. lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1
  1345. lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf
  1346. stebz stedc steqr sterf
  1347. larra larrc larrd larr larrk larrj larrr laneg laisnan isnan
  1348. lazq3 lazq4
  1349. ''' # [s|d]*.f
  1350. lasrc = '''
  1351. gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak
  1352. gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv
  1353. gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2
  1354. geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd
  1355. gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal
  1356. gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd
  1357. ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein
  1358. hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0
  1359. lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb
  1360. lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp
  1361. laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv
  1362. lartv larz larzb larzt laswp lasyf latbs latdf latps latrd
  1363. latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv
  1364. pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2
  1365. potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri
  1366. pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs
  1367. spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv
  1368. sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2
  1369. tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs
  1370. trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs
  1371. tzrqf tzrzf
  1372. lacn2 lahr2 stemr laqr0 laqr1 laqr2 laqr3 laqr4 laqr5
  1373. ''' # [s|c|d|z]*.f
  1374. sd_lasrc = '''
  1375. laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l
  1376. org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr
  1377. orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3
  1378. ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx
  1379. sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd
  1380. stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd
  1381. sygvx sytd2 sytrd
  1382. ''' # [s|d]*.f
  1383. cz_lasrc = '''
  1384. bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev
  1385. heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv
  1386. hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd
  1387. hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf
  1388. hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7
  1389. laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe
  1390. laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv
  1391. spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq
  1392. ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2
  1393. unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr
  1394. ''' # [c|z]*.f
  1395. #######
  1396. sclaux = laux + ' econd ' # s*.f
  1397. dzlaux = laux + ' secnd ' # d*.f
  1398. slasrc = lasrc + sd_lasrc # s*.f
  1399. dlasrc = lasrc + sd_lasrc # d*.f
  1400. clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f
  1401. zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f
  1402. oclasrc = ' icmax1 scsum1 ' # *.f
  1403. ozlasrc = ' izmax1 dzsum1 ' # *.f
  1404. sources = ['s%s.f' % f for f in (sclaux + slasrc).split()] \
  1405. + ['d%s.f' % f for f in (dzlaux + dlasrc).split()] \
  1406. + ['c%s.f' % f for f in (clasrc).split()] \
  1407. + ['z%s.f' % f for f in (zlasrc).split()] \
  1408. + ['%s.f' % f for f in (allaux + oclasrc + ozlasrc).split()]
  1409. sources = [os.path.join(src_dir, f) for f in sources]
  1410. # Lapack 3.1:
  1411. src_dir2 = os.path.join(src_dir, '..', 'INSTALL')
  1412. sources += [os.path.join(src_dir2, p + 'lamch.f') for p in 'sdcz']
  1413. # Lapack 3.2.1:
  1414. sources += [os.path.join(src_dir, p + 'larfp.f') for p in 'sdcz']
  1415. sources += [os.path.join(src_dir, 'ila' + p + 'lr.f') for p in 'sdcz']
  1416. sources += [os.path.join(src_dir, 'ila' + p + 'lc.f') for p in 'sdcz']
  1417. # Should we check here actual existence of source files?
  1418. # Yes, the file listing is different between 3.0 and 3.1
  1419. # versions.
  1420. sources = [f for f in sources if os.path.isfile(f)]
  1421. info = {'sources': sources, 'language': 'f77'}
  1422. self.set_info(**info)
  1423. atlas_version_c_text = r'''
  1424. /* This file is generated from numpy/distutils/system_info.py */
  1425. void ATL_buildinfo(void);
  1426. int main(void) {
  1427. ATL_buildinfo();
  1428. return 0;
  1429. }
  1430. '''
  1431. _cached_atlas_version = {}
  1432. def get_atlas_version(**config):
  1433. libraries = config.get('libraries', [])
  1434. library_dirs = config.get('library_dirs', [])
  1435. key = (tuple(libraries), tuple(library_dirs))
  1436. if key in _cached_atlas_version:
  1437. return _cached_atlas_version[key]
  1438. c = cmd_config(Distribution())
  1439. atlas_version = None
  1440. info = {}
  1441. try:
  1442. s, o = c.get_output(atlas_version_c_text,
  1443. libraries=libraries, library_dirs=library_dirs,
  1444. )
  1445. if s and re.search(r'undefined reference to `_gfortran', o, re.M):
  1446. s, o = c.get_output(atlas_version_c_text,
  1447. libraries=libraries + ['gfortran'],
  1448. library_dirs=library_dirs,
  1449. )
  1450. if not s:
  1451. warnings.warn(textwrap.dedent("""
  1452. *****************************************************
  1453. Linkage with ATLAS requires gfortran. Use
  1454. python setup.py config_fc --fcompiler=gnu95 ...
  1455. when building extension libraries that use ATLAS.
  1456. Make sure that -lgfortran is used for C++ extensions.
  1457. *****************************************************
  1458. """), stacklevel=2)
  1459. dict_append(info, language='f90',
  1460. define_macros=[('ATLAS_REQUIRES_GFORTRAN', None)])
  1461. except Exception: # failed to get version from file -- maybe on Windows
  1462. # look at directory name
  1463. for o in library_dirs:
  1464. m = re.search(r'ATLAS_(?P<version>\d+[.]\d+[.]\d+)_', o)
  1465. if m:
  1466. atlas_version = m.group('version')
  1467. if atlas_version is not None:
  1468. break
  1469. # final choice --- look at ATLAS_VERSION environment
  1470. # variable
  1471. if atlas_version is None:
  1472. atlas_version = os.environ.get('ATLAS_VERSION', None)
  1473. if atlas_version:
  1474. dict_append(info, define_macros=[(
  1475. 'ATLAS_INFO', _c_string_literal(atlas_version))
  1476. ])
  1477. else:
  1478. dict_append(info, define_macros=[('NO_ATLAS_INFO', -1)])
  1479. return atlas_version or '?.?.?', info
  1480. if not s:
  1481. m = re.search(r'ATLAS version (?P<version>\d+[.]\d+[.]\d+)', o)
  1482. if m:
  1483. atlas_version = m.group('version')
  1484. if atlas_version is None:
  1485. if re.search(r'undefined symbol: ATL_buildinfo', o, re.M):
  1486. atlas_version = '3.2.1_pre3.3.6'
  1487. else:
  1488. log.info('Status: %d', s)
  1489. log.info('Output: %s', o)
  1490. elif atlas_version == '3.2.1_pre3.3.6':
  1491. dict_append(info, define_macros=[('NO_ATLAS_INFO', -2)])
  1492. else:
  1493. dict_append(info, define_macros=[(
  1494. 'ATLAS_INFO', _c_string_literal(atlas_version))
  1495. ])
  1496. result = _cached_atlas_version[key] = atlas_version, info
  1497. return result
  1498. class lapack_opt_info(system_info):
  1499. notfounderror = LapackNotFoundError
  1500. # List of all known LAPACK libraries, in the default order
  1501. lapack_order = ['mkl', 'openblas', 'flame',
  1502. 'accelerate', 'atlas', 'lapack']
  1503. order_env_var_name = 'NPY_LAPACK_ORDER'
  1504. def _calc_info_mkl(self):
  1505. info = get_info('lapack_mkl')
  1506. if info:
  1507. self.set_info(**info)
  1508. return True
  1509. return False
  1510. def _calc_info_openblas(self):
  1511. info = get_info('openblas_lapack')
  1512. if info:
  1513. self.set_info(**info)
  1514. return True
  1515. info = get_info('openblas_clapack')
  1516. if info:
  1517. self.set_info(**info)
  1518. return True
  1519. return False
  1520. def _calc_info_flame(self):
  1521. info = get_info('flame')
  1522. if info:
  1523. self.set_info(**info)
  1524. return True
  1525. return False
  1526. def _calc_info_atlas(self):
  1527. info = get_info('atlas_3_10_threads')
  1528. if not info:
  1529. info = get_info('atlas_3_10')
  1530. if not info:
  1531. info = get_info('atlas_threads')
  1532. if not info:
  1533. info = get_info('atlas')
  1534. if info:
  1535. # Figure out if ATLAS has lapack...
  1536. # If not we need the lapack library, but not BLAS!
  1537. l = info.get('define_macros', [])
  1538. if ('ATLAS_WITH_LAPACK_ATLAS', None) in l \
  1539. or ('ATLAS_WITHOUT_LAPACK', None) in l:
  1540. # Get LAPACK (with possible warnings)
  1541. # If not found we don't accept anything
  1542. # since we can't use ATLAS with LAPACK!
  1543. lapack_info = self._get_info_lapack()
  1544. if not lapack_info:
  1545. return False
  1546. dict_append(info, **lapack_info)
  1547. self.set_info(**info)
  1548. return True
  1549. return False
  1550. def _calc_info_accelerate(self):
  1551. info = get_info('accelerate')
  1552. if info:
  1553. self.set_info(**info)
  1554. return True
  1555. return False
  1556. def _get_info_blas(self):
  1557. # Default to get the optimized BLAS implementation
  1558. info = get_info('blas_opt')
  1559. if not info:
  1560. warnings.warn(BlasNotFoundError.__doc__ or '', stacklevel=3)
  1561. info_src = get_info('blas_src')
  1562. if not info_src:
  1563. warnings.warn(BlasSrcNotFoundError.__doc__ or '', stacklevel=3)
  1564. return {}
  1565. dict_append(info, libraries=[('fblas_src', info_src)])
  1566. return info
  1567. def _get_info_lapack(self):
  1568. info = get_info('lapack')
  1569. if not info:
  1570. warnings.warn(LapackNotFoundError.__doc__ or '', stacklevel=3)
  1571. info_src = get_info('lapack_src')
  1572. if not info_src:
  1573. warnings.warn(LapackSrcNotFoundError.__doc__ or '', stacklevel=3)
  1574. return {}
  1575. dict_append(info, libraries=[('flapack_src', info_src)])
  1576. return info
  1577. def _calc_info_lapack(self):
  1578. info = self._get_info_lapack()
  1579. if info:
  1580. info_blas = self._get_info_blas()
  1581. dict_append(info, **info_blas)
  1582. dict_append(info, define_macros=[('NO_ATLAS_INFO', 1)])
  1583. self.set_info(**info)
  1584. return True
  1585. return False
  1586. def _calc_info_from_envvar(self):
  1587. info = {}
  1588. info['language'] = 'f77'
  1589. info['libraries'] = []
  1590. info['include_dirs'] = []
  1591. info['define_macros'] = []
  1592. info['extra_link_args'] = os.environ['NPY_LAPACK_LIBS'].split()
  1593. self.set_info(**info)
  1594. return True
  1595. def _calc_info(self, name):
  1596. return getattr(self, '_calc_info_{}'.format(name))()
  1597. def calc_info(self):
  1598. lapack_order, unknown_order = _parse_env_order(self.lapack_order, self.order_env_var_name)
  1599. if len(unknown_order) > 0:
  1600. raise ValueError("lapack_opt_info user defined "
  1601. "LAPACK order has unacceptable "
  1602. "values: {}".format(unknown_order))
  1603. if 'NPY_LAPACK_LIBS' in os.environ:
  1604. # Bypass autodetection, set language to F77 and use env var linker
  1605. # flags directly
  1606. self._calc_info_from_envvar()
  1607. return
  1608. for lapack in lapack_order:
  1609. if self._calc_info(lapack):
  1610. return
  1611. if 'lapack' not in lapack_order:
  1612. # Since the user may request *not* to use any library, we still need
  1613. # to raise warnings to signal missing packages!
  1614. warnings.warn(LapackNotFoundError.__doc__ or '', stacklevel=2)
  1615. warnings.warn(LapackSrcNotFoundError.__doc__ or '', stacklevel=2)
  1616. class _ilp64_opt_info_mixin:
  1617. symbol_suffix = None
  1618. symbol_prefix = None
  1619. def _check_info(self, info):
  1620. macros = dict(info.get('define_macros', []))
  1621. prefix = macros.get('BLAS_SYMBOL_PREFIX', '')
  1622. suffix = macros.get('BLAS_SYMBOL_SUFFIX', '')
  1623. if self.symbol_prefix not in (None, prefix):
  1624. return False
  1625. if self.symbol_suffix not in (None, suffix):
  1626. return False
  1627. return bool(info)
  1628. class lapack_ilp64_opt_info(lapack_opt_info, _ilp64_opt_info_mixin):
  1629. notfounderror = LapackILP64NotFoundError
  1630. lapack_order = ['openblas64_', 'openblas_ilp64']
  1631. order_env_var_name = 'NPY_LAPACK_ILP64_ORDER'
  1632. def _calc_info(self, name):
  1633. info = get_info(name + '_lapack')
  1634. if self._check_info(info):
  1635. self.set_info(**info)
  1636. return True
  1637. return False
  1638. class lapack_ilp64_plain_opt_info(lapack_ilp64_opt_info):
  1639. # Same as lapack_ilp64_opt_info, but fix symbol names
  1640. symbol_prefix = ''
  1641. symbol_suffix = ''
  1642. class lapack64__opt_info(lapack_ilp64_opt_info):
  1643. symbol_prefix = ''
  1644. symbol_suffix = '64_'
  1645. class blas_opt_info(system_info):
  1646. notfounderror = BlasNotFoundError
  1647. # List of all known BLAS libraries, in the default order
  1648. blas_order = ['mkl', 'blis', 'openblas',
  1649. 'accelerate', 'atlas', 'blas']
  1650. order_env_var_name = 'NPY_BLAS_ORDER'
  1651. def _calc_info_mkl(self):
  1652. info = get_info('blas_mkl')
  1653. if info:
  1654. self.set_info(**info)
  1655. return True
  1656. return False
  1657. def _calc_info_blis(self):
  1658. info = get_info('blis')
  1659. if info:
  1660. self.set_info(**info)
  1661. return True
  1662. return False
  1663. def _calc_info_openblas(self):
  1664. info = get_info('openblas')
  1665. if info:
  1666. self.set_info(**info)
  1667. return True
  1668. return False
  1669. def _calc_info_atlas(self):
  1670. info = get_info('atlas_3_10_blas_threads')
  1671. if not info:
  1672. info = get_info('atlas_3_10_blas')
  1673. if not info:
  1674. info = get_info('atlas_blas_threads')
  1675. if not info:
  1676. info = get_info('atlas_blas')
  1677. if info:
  1678. self.set_info(**info)
  1679. return True
  1680. return False
  1681. def _calc_info_accelerate(self):
  1682. info = get_info('accelerate')
  1683. if info:
  1684. self.set_info(**info)
  1685. return True
  1686. return False
  1687. def _calc_info_blas(self):
  1688. # Warn about a non-optimized BLAS library
  1689. warnings.warn(BlasOptNotFoundError.__doc__ or '', stacklevel=3)
  1690. info = {}
  1691. dict_append(info, define_macros=[('NO_ATLAS_INFO', 1)])
  1692. blas = get_info('blas')
  1693. if blas:
  1694. dict_append(info, **blas)
  1695. else:
  1696. # Not even BLAS was found!
  1697. warnings.warn(BlasNotFoundError.__doc__ or '', stacklevel=3)
  1698. blas_src = get_info('blas_src')
  1699. if not blas_src:
  1700. warnings.warn(BlasSrcNotFoundError.__doc__ or '', stacklevel=3)
  1701. return False
  1702. dict_append(info, libraries=[('fblas_src', blas_src)])
  1703. self.set_info(**info)
  1704. return True
  1705. def _calc_info_from_envvar(self):
  1706. info = {}
  1707. info['language'] = 'f77'
  1708. info['libraries'] = []
  1709. info['include_dirs'] = []
  1710. info['define_macros'] = []
  1711. info['extra_link_args'] = os.environ['NPY_BLAS_LIBS'].split()
  1712. if 'NPY_CBLAS_LIBS' in os.environ:
  1713. info['define_macros'].append(('HAVE_CBLAS', None))
  1714. info['extra_link_args'].extend(
  1715. os.environ['NPY_CBLAS_LIBS'].split())
  1716. self.set_info(**info)
  1717. return True
  1718. def _calc_info(self, name):
  1719. return getattr(self, '_calc_info_{}'.format(name))()
  1720. def calc_info(self):
  1721. blas_order, unknown_order = _parse_env_order(self.blas_order, self.order_env_var_name)
  1722. if len(unknown_order) > 0:
  1723. raise ValueError("blas_opt_info user defined BLAS order has unacceptable values: {}".format(unknown_order))
  1724. if 'NPY_BLAS_LIBS' in os.environ:
  1725. # Bypass autodetection, set language to F77 and use env var linker
  1726. # flags directly
  1727. self._calc_info_from_envvar()
  1728. return
  1729. for blas in blas_order:
  1730. if self._calc_info(blas):
  1731. return
  1732. if 'blas' not in blas_order:
  1733. # Since the user may request *not* to use any library, we still need
  1734. # to raise warnings to signal missing packages!
  1735. warnings.warn(BlasNotFoundError.__doc__ or '', stacklevel=2)
  1736. warnings.warn(BlasSrcNotFoundError.__doc__ or '', stacklevel=2)
  1737. class blas_ilp64_opt_info(blas_opt_info, _ilp64_opt_info_mixin):
  1738. notfounderror = BlasILP64NotFoundError
  1739. blas_order = ['openblas64_', 'openblas_ilp64']
  1740. order_env_var_name = 'NPY_BLAS_ILP64_ORDER'
  1741. def _calc_info(self, name):
  1742. info = get_info(name)
  1743. if self._check_info(info):
  1744. self.set_info(**info)
  1745. return True
  1746. return False
  1747. class blas_ilp64_plain_opt_info(blas_ilp64_opt_info):
  1748. symbol_prefix = ''
  1749. symbol_suffix = ''
  1750. class blas64__opt_info(blas_ilp64_opt_info):
  1751. symbol_prefix = ''
  1752. symbol_suffix = '64_'
  1753. class cblas_info(system_info):
  1754. section = 'cblas'
  1755. dir_env_var = 'CBLAS'
  1756. # No default as it's used only in blas_info
  1757. _lib_names = []
  1758. notfounderror = BlasNotFoundError
  1759. class blas_info(system_info):
  1760. section = 'blas'
  1761. dir_env_var = 'BLAS'
  1762. _lib_names = ['blas']
  1763. notfounderror = BlasNotFoundError
  1764. def calc_info(self):
  1765. lib_dirs = self.get_lib_dirs()
  1766. opt = self.get_option_single('blas_libs', 'libraries')
  1767. blas_libs = self.get_libs(opt, self._lib_names)
  1768. info = self.check_libs(lib_dirs, blas_libs, [])
  1769. if info is None:
  1770. return
  1771. else:
  1772. info['include_dirs'] = self.get_include_dirs()
  1773. if platform.system() == 'Windows':
  1774. # The check for windows is needed because get_cblas_libs uses the
  1775. # same compiler that was used to compile Python and msvc is
  1776. # often not installed when mingw is being used. This rough
  1777. # treatment is not desirable, but windows is tricky.
  1778. info['language'] = 'f77' # XXX: is it generally true?
  1779. # If cblas is given as an option, use those
  1780. cblas_info_obj = cblas_info()
  1781. cblas_opt = cblas_info_obj.get_option_single('cblas_libs', 'libraries')
  1782. cblas_libs = cblas_info_obj.get_libs(cblas_opt, None)
  1783. if cblas_libs:
  1784. info['libraries'] = cblas_libs + blas_libs
  1785. info['define_macros'] = [('HAVE_CBLAS', None)]
  1786. else:
  1787. lib = self.get_cblas_libs(info)
  1788. if lib is not None:
  1789. info['language'] = 'c'
  1790. info['libraries'] = lib
  1791. info['define_macros'] = [('HAVE_CBLAS', None)]
  1792. self.set_info(**info)
  1793. def get_cblas_libs(self, info):
  1794. """ Check whether we can link with CBLAS interface
  1795. This method will search through several combinations of libraries
  1796. to check whether CBLAS is present:
  1797. 1. Libraries in ``info['libraries']``, as is
  1798. 2. As 1. but also explicitly adding ``'cblas'`` as a library
  1799. 3. As 1. but also explicitly adding ``'blas'`` as a library
  1800. 4. Check only library ``'cblas'``
  1801. 5. Check only library ``'blas'``
  1802. Parameters
  1803. ----------
  1804. info : dict
  1805. system information dictionary for compilation and linking
  1806. Returns
  1807. -------
  1808. libraries : list of str or None
  1809. a list of libraries that enables the use of CBLAS interface.
  1810. Returns None if not found or a compilation error occurs.
  1811. Since 1.17 returns a list.
  1812. """
  1813. # primitive cblas check by looking for the header and trying to link
  1814. # cblas or blas
  1815. c = customized_ccompiler()
  1816. tmpdir = tempfile.mkdtemp()
  1817. s = textwrap.dedent("""\
  1818. #include <cblas.h>
  1819. int main(int argc, const char *argv[])
  1820. {
  1821. double a[4] = {1,2,3,4};
  1822. double b[4] = {5,6,7,8};
  1823. return cblas_ddot(4, a, 1, b, 1) > 10;
  1824. }""")
  1825. src = os.path.join(tmpdir, 'source.c')
  1826. try:
  1827. with open(src, 'wt') as f:
  1828. f.write(s)
  1829. try:
  1830. # check we can compile (find headers)
  1831. obj = c.compile([src], output_dir=tmpdir,
  1832. include_dirs=self.get_include_dirs())
  1833. except (distutils.ccompiler.CompileError, distutils.ccompiler.LinkError):
  1834. return None
  1835. # check we can link (find library)
  1836. # some systems have separate cblas and blas libs.
  1837. for libs in [info['libraries'], ['cblas'] + info['libraries'],
  1838. ['blas'] + info['libraries'], ['cblas'], ['blas']]:
  1839. try:
  1840. c.link_executable(obj, os.path.join(tmpdir, "a.out"),
  1841. libraries=libs,
  1842. library_dirs=info['library_dirs'],
  1843. extra_postargs=info.get('extra_link_args', []))
  1844. return libs
  1845. except distutils.ccompiler.LinkError:
  1846. pass
  1847. finally:
  1848. shutil.rmtree(tmpdir)
  1849. return None
  1850. class openblas_info(blas_info):
  1851. section = 'openblas'
  1852. dir_env_var = 'OPENBLAS'
  1853. _lib_names = ['openblas']
  1854. _require_symbols = []
  1855. notfounderror = BlasNotFoundError
  1856. @property
  1857. def symbol_prefix(self):
  1858. try:
  1859. return self.cp.get(self.section, 'symbol_prefix')
  1860. except NoOptionError:
  1861. return ''
  1862. @property
  1863. def symbol_suffix(self):
  1864. try:
  1865. return self.cp.get(self.section, 'symbol_suffix')
  1866. except NoOptionError:
  1867. return ''
  1868. def _calc_info(self):
  1869. c = customized_ccompiler()
  1870. lib_dirs = self.get_lib_dirs()
  1871. # Prefer to use libraries over openblas_libs
  1872. opt = self.get_option_single('openblas_libs', 'libraries')
  1873. openblas_libs = self.get_libs(opt, self._lib_names)
  1874. info = self.check_libs(lib_dirs, openblas_libs, [])
  1875. if c.compiler_type == "msvc" and info is None:
  1876. from numpy.distutils.fcompiler import new_fcompiler
  1877. f = new_fcompiler(c_compiler=c)
  1878. if f and f.compiler_type == 'gnu95':
  1879. # Try gfortran-compatible library files
  1880. info = self.check_msvc_gfortran_libs(lib_dirs, openblas_libs)
  1881. # Skip lapack check, we'd need build_ext to do it
  1882. skip_symbol_check = True
  1883. elif info:
  1884. skip_symbol_check = False
  1885. info['language'] = 'c'
  1886. if info is None:
  1887. return None
  1888. # Add extra info for OpenBLAS
  1889. extra_info = self.calc_extra_info()
  1890. dict_append(info, **extra_info)
  1891. if not (skip_symbol_check or self.check_symbols(info)):
  1892. return None
  1893. info['define_macros'] = [('HAVE_CBLAS', None)]
  1894. if self.symbol_prefix:
  1895. info['define_macros'] += [('BLAS_SYMBOL_PREFIX', self.symbol_prefix)]
  1896. if self.symbol_suffix:
  1897. info['define_macros'] += [('BLAS_SYMBOL_SUFFIX', self.symbol_suffix)]
  1898. return info
  1899. def calc_info(self):
  1900. info = self._calc_info()
  1901. if info is not None:
  1902. self.set_info(**info)
  1903. def check_msvc_gfortran_libs(self, library_dirs, libraries):
  1904. # First, find the full path to each library directory
  1905. library_paths = []
  1906. for library in libraries:
  1907. for library_dir in library_dirs:
  1908. # MinGW static ext will be .a
  1909. fullpath = os.path.join(library_dir, library + '.a')
  1910. if os.path.isfile(fullpath):
  1911. library_paths.append(fullpath)
  1912. break
  1913. else:
  1914. return None
  1915. # Generate numpy.distutils virtual static library file
  1916. basename = self.__class__.__name__
  1917. tmpdir = os.path.join(os.getcwd(), 'build', basename)
  1918. if not os.path.isdir(tmpdir):
  1919. os.makedirs(tmpdir)
  1920. info = {'library_dirs': [tmpdir],
  1921. 'libraries': [basename],
  1922. 'language': 'f77'}
  1923. fake_lib_file = os.path.join(tmpdir, basename + '.fobjects')
  1924. fake_clib_file = os.path.join(tmpdir, basename + '.cobjects')
  1925. with open(fake_lib_file, 'w') as f:
  1926. f.write("\n".join(library_paths))
  1927. with open(fake_clib_file, 'w') as f:
  1928. pass
  1929. return info
  1930. def check_symbols(self, info):
  1931. res = False
  1932. c = customized_ccompiler()
  1933. tmpdir = tempfile.mkdtemp()
  1934. prototypes = "\n".join("void %s%s%s();" % (self.symbol_prefix,
  1935. symbol_name,
  1936. self.symbol_suffix)
  1937. for symbol_name in self._require_symbols)
  1938. calls = "\n".join("%s%s%s();" % (self.symbol_prefix,
  1939. symbol_name,
  1940. self.symbol_suffix)
  1941. for symbol_name in self._require_symbols)
  1942. s = textwrap.dedent("""\
  1943. %(prototypes)s
  1944. int main(int argc, const char *argv[])
  1945. {
  1946. %(calls)s
  1947. return 0;
  1948. }""") % dict(prototypes=prototypes, calls=calls)
  1949. src = os.path.join(tmpdir, 'source.c')
  1950. out = os.path.join(tmpdir, 'a.out')
  1951. # Add the additional "extra" arguments
  1952. try:
  1953. extra_args = info['extra_link_args']
  1954. except Exception:
  1955. extra_args = []
  1956. try:
  1957. with open(src, 'wt') as f:
  1958. f.write(s)
  1959. obj = c.compile([src], output_dir=tmpdir)
  1960. try:
  1961. c.link_executable(obj, out, libraries=info['libraries'],
  1962. library_dirs=info['library_dirs'],
  1963. extra_postargs=extra_args)
  1964. res = True
  1965. except distutils.ccompiler.LinkError:
  1966. res = False
  1967. finally:
  1968. shutil.rmtree(tmpdir)
  1969. return res
  1970. class openblas_lapack_info(openblas_info):
  1971. section = 'openblas'
  1972. dir_env_var = 'OPENBLAS'
  1973. _lib_names = ['openblas']
  1974. _require_symbols = ['zungqr_']
  1975. notfounderror = BlasNotFoundError
  1976. class openblas_clapack_info(openblas_lapack_info):
  1977. _lib_names = ['openblas', 'lapack']
  1978. class openblas_ilp64_info(openblas_info):
  1979. section = 'openblas_ilp64'
  1980. dir_env_var = 'OPENBLAS_ILP64'
  1981. _lib_names = ['openblas64']
  1982. _require_symbols = ['dgemm_', 'cblas_dgemm']
  1983. notfounderror = BlasILP64NotFoundError
  1984. def _calc_info(self):
  1985. info = super()._calc_info()
  1986. if info is not None:
  1987. info['define_macros'] += [('HAVE_BLAS_ILP64', None)]
  1988. return info
  1989. class openblas_ilp64_lapack_info(openblas_ilp64_info):
  1990. _require_symbols = ['dgemm_', 'cblas_dgemm', 'zungqr_', 'LAPACKE_zungqr']
  1991. def _calc_info(self):
  1992. info = super()._calc_info()
  1993. if info:
  1994. info['define_macros'] += [('HAVE_LAPACKE', None)]
  1995. return info
  1996. class openblas64__info(openblas_ilp64_info):
  1997. # ILP64 Openblas, with default symbol suffix
  1998. section = 'openblas64_'
  1999. dir_env_var = 'OPENBLAS64_'
  2000. _lib_names = ['openblas64_']
  2001. symbol_suffix = '64_'
  2002. symbol_prefix = ''
  2003. class openblas64__lapack_info(openblas_ilp64_lapack_info, openblas64__info):
  2004. pass
  2005. class blis_info(blas_info):
  2006. section = 'blis'
  2007. dir_env_var = 'BLIS'
  2008. _lib_names = ['blis']
  2009. notfounderror = BlasNotFoundError
  2010. def calc_info(self):
  2011. lib_dirs = self.get_lib_dirs()
  2012. opt = self.get_option_single('blis_libs', 'libraries')
  2013. blis_libs = self.get_libs(opt, self._lib_names)
  2014. info = self.check_libs2(lib_dirs, blis_libs, [])
  2015. if info is None:
  2016. return
  2017. # Add include dirs
  2018. incl_dirs = self.get_include_dirs()
  2019. dict_append(info,
  2020. language='c',
  2021. define_macros=[('HAVE_CBLAS', None)],
  2022. include_dirs=incl_dirs)
  2023. self.set_info(**info)
  2024. class flame_info(system_info):
  2025. """ Usage of libflame for LAPACK operations
  2026. This requires libflame to be compiled with lapack wrappers:
  2027. ./configure --enable-lapack2flame ...
  2028. Be aware that libflame 5.1.0 has some missing names in the shared library, so
  2029. if you have problems, try the static flame library.
  2030. """
  2031. section = 'flame'
  2032. _lib_names = ['flame']
  2033. notfounderror = FlameNotFoundError
  2034. def check_embedded_lapack(self, info):
  2035. """ libflame does not necessarily have a wrapper for fortran LAPACK, we need to check """
  2036. c = customized_ccompiler()
  2037. tmpdir = tempfile.mkdtemp()
  2038. s = textwrap.dedent("""\
  2039. void zungqr_();
  2040. int main(int argc, const char *argv[])
  2041. {
  2042. zungqr_();
  2043. return 0;
  2044. }""")
  2045. src = os.path.join(tmpdir, 'source.c')
  2046. out = os.path.join(tmpdir, 'a.out')
  2047. # Add the additional "extra" arguments
  2048. extra_args = info.get('extra_link_args', [])
  2049. try:
  2050. with open(src, 'wt') as f:
  2051. f.write(s)
  2052. obj = c.compile([src], output_dir=tmpdir)
  2053. try:
  2054. c.link_executable(obj, out, libraries=info['libraries'],
  2055. library_dirs=info['library_dirs'],
  2056. extra_postargs=extra_args)
  2057. return True
  2058. except distutils.ccompiler.LinkError:
  2059. return False
  2060. finally:
  2061. shutil.rmtree(tmpdir)
  2062. def calc_info(self):
  2063. lib_dirs = self.get_lib_dirs()
  2064. flame_libs = self.get_libs('libraries', self._lib_names)
  2065. info = self.check_libs2(lib_dirs, flame_libs, [])
  2066. if info is None:
  2067. return
  2068. if self.check_embedded_lapack(info):
  2069. # check if the user has supplied all information required
  2070. self.set_info(**info)
  2071. else:
  2072. # Try and get the BLAS lib to see if we can get it to work
  2073. blas_info = get_info('blas_opt')
  2074. if not blas_info:
  2075. # since we already failed once, this ain't going to work either
  2076. return
  2077. # Now we need to merge the two dictionaries
  2078. for key in blas_info:
  2079. if isinstance(blas_info[key], list):
  2080. info[key] = info.get(key, []) + blas_info[key]
  2081. elif isinstance(blas_info[key], tuple):
  2082. info[key] = info.get(key, ()) + blas_info[key]
  2083. else:
  2084. info[key] = info.get(key, '') + blas_info[key]
  2085. # Now check again
  2086. if self.check_embedded_lapack(info):
  2087. self.set_info(**info)
  2088. class accelerate_info(system_info):
  2089. section = 'accelerate'
  2090. _lib_names = ['accelerate', 'veclib']
  2091. notfounderror = BlasNotFoundError
  2092. def calc_info(self):
  2093. # Make possible to enable/disable from config file/env var
  2094. libraries = os.environ.get('ACCELERATE')
  2095. if libraries:
  2096. libraries = [libraries]
  2097. else:
  2098. libraries = self.get_libs('libraries', self._lib_names)
  2099. libraries = [lib.strip().lower() for lib in libraries]
  2100. if (sys.platform == 'darwin' and
  2101. not os.getenv('_PYTHON_HOST_PLATFORM', None)):
  2102. # Use the system BLAS from Accelerate or vecLib under OSX
  2103. args = []
  2104. link_args = []
  2105. if get_platform()[-4:] == 'i386' or 'intel' in get_platform() or \
  2106. 'x86_64' in get_platform() or \
  2107. 'i386' in platform.platform():
  2108. intel = 1
  2109. else:
  2110. intel = 0
  2111. if (os.path.exists('/System/Library/Frameworks'
  2112. '/Accelerate.framework/') and
  2113. 'accelerate' in libraries):
  2114. if intel:
  2115. args.extend(['-msse3'])
  2116. args.extend([
  2117. '-I/System/Library/Frameworks/vecLib.framework/Headers'])
  2118. link_args.extend(['-Wl,-framework', '-Wl,Accelerate'])
  2119. elif (os.path.exists('/System/Library/Frameworks'
  2120. '/vecLib.framework/') and
  2121. 'veclib' in libraries):
  2122. if intel:
  2123. args.extend(['-msse3'])
  2124. args.extend([
  2125. '-I/System/Library/Frameworks/vecLib.framework/Headers'])
  2126. link_args.extend(['-Wl,-framework', '-Wl,vecLib'])
  2127. if args:
  2128. self.set_info(extra_compile_args=args,
  2129. extra_link_args=link_args,
  2130. define_macros=[('NO_ATLAS_INFO', 3),
  2131. ('HAVE_CBLAS', None)])
  2132. return
  2133. class blas_src_info(system_info):
  2134. # BLAS_SRC is deprecated, please do not use this!
  2135. # Build or install a BLAS library via your package manager or from
  2136. # source separately.
  2137. section = 'blas_src'
  2138. dir_env_var = 'BLAS_SRC'
  2139. notfounderror = BlasSrcNotFoundError
  2140. def get_paths(self, section, key):
  2141. pre_dirs = system_info.get_paths(self, section, key)
  2142. dirs = []
  2143. for d in pre_dirs:
  2144. dirs.extend([d] + self.combine_paths(d, ['blas']))
  2145. return [d for d in dirs if os.path.isdir(d)]
  2146. def calc_info(self):
  2147. src_dirs = self.get_src_dirs()
  2148. src_dir = ''
  2149. for d in src_dirs:
  2150. if os.path.isfile(os.path.join(d, 'daxpy.f')):
  2151. src_dir = d
  2152. break
  2153. if not src_dir:
  2154. #XXX: Get sources from netlib. May be ask first.
  2155. return
  2156. blas1 = '''
  2157. caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot
  2158. dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2
  2159. srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg
  2160. dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax
  2161. snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap
  2162. scabs1
  2163. '''
  2164. blas2 = '''
  2165. cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv
  2166. chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv
  2167. dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv
  2168. sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger
  2169. stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc
  2170. zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2
  2171. ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv
  2172. '''
  2173. blas3 = '''
  2174. cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k
  2175. dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm
  2176. ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm
  2177. '''
  2178. sources = [os.path.join(src_dir, f + '.f') \
  2179. for f in (blas1 + blas2 + blas3).split()]
  2180. #XXX: should we check here actual existence of source files?
  2181. sources = [f for f in sources if os.path.isfile(f)]
  2182. info = {'sources': sources, 'language': 'f77'}
  2183. self.set_info(**info)
  2184. class x11_info(system_info):
  2185. section = 'x11'
  2186. notfounderror = X11NotFoundError
  2187. _lib_names = ['X11']
  2188. def __init__(self):
  2189. system_info.__init__(self,
  2190. default_lib_dirs=default_x11_lib_dirs,
  2191. default_include_dirs=default_x11_include_dirs)
  2192. def calc_info(self):
  2193. if sys.platform in ['win32']:
  2194. return
  2195. lib_dirs = self.get_lib_dirs()
  2196. include_dirs = self.get_include_dirs()
  2197. opt = self.get_option_single('x11_libs', 'libraries')
  2198. x11_libs = self.get_libs(opt, self._lib_names)
  2199. info = self.check_libs(lib_dirs, x11_libs, [])
  2200. if info is None:
  2201. return
  2202. inc_dir = None
  2203. for d in include_dirs:
  2204. if self.combine_paths(d, 'X11/X.h'):
  2205. inc_dir = d
  2206. break
  2207. if inc_dir is not None:
  2208. dict_append(info, include_dirs=[inc_dir])
  2209. self.set_info(**info)
  2210. class _numpy_info(system_info):
  2211. section = 'Numeric'
  2212. modulename = 'Numeric'
  2213. notfounderror = NumericNotFoundError
  2214. def __init__(self):
  2215. include_dirs = []
  2216. try:
  2217. module = __import__(self.modulename)
  2218. prefix = []
  2219. for name in module.__file__.split(os.sep):
  2220. if name == 'lib':
  2221. break
  2222. prefix.append(name)
  2223. # Ask numpy for its own include path before attempting
  2224. # anything else
  2225. try:
  2226. include_dirs.append(getattr(module, 'get_include')())
  2227. except AttributeError:
  2228. pass
  2229. include_dirs.append(sysconfig.get_path('include'))
  2230. except ImportError:
  2231. pass
  2232. py_incl_dir = sysconfig.get_path('include')
  2233. include_dirs.append(py_incl_dir)
  2234. py_pincl_dir = sysconfig.get_path('platinclude')
  2235. if py_pincl_dir not in include_dirs:
  2236. include_dirs.append(py_pincl_dir)
  2237. for d in default_include_dirs:
  2238. d = os.path.join(d, os.path.basename(py_incl_dir))
  2239. if d not in include_dirs:
  2240. include_dirs.append(d)
  2241. system_info.__init__(self,
  2242. default_lib_dirs=[],
  2243. default_include_dirs=include_dirs)
  2244. def calc_info(self):
  2245. try:
  2246. module = __import__(self.modulename)
  2247. except ImportError:
  2248. return
  2249. info = {}
  2250. macros = []
  2251. for v in ['__version__', 'version']:
  2252. vrs = getattr(module, v, None)
  2253. if vrs is None:
  2254. continue
  2255. macros = [(self.modulename.upper() + '_VERSION',
  2256. _c_string_literal(vrs)),
  2257. (self.modulename.upper(), None)]
  2258. break
  2259. dict_append(info, define_macros=macros)
  2260. include_dirs = self.get_include_dirs()
  2261. inc_dir = None
  2262. for d in include_dirs:
  2263. if self.combine_paths(d,
  2264. os.path.join(self.modulename,
  2265. 'arrayobject.h')):
  2266. inc_dir = d
  2267. break
  2268. if inc_dir is not None:
  2269. dict_append(info, include_dirs=[inc_dir])
  2270. if info:
  2271. self.set_info(**info)
  2272. return
  2273. class numarray_info(_numpy_info):
  2274. section = 'numarray'
  2275. modulename = 'numarray'
  2276. class Numeric_info(_numpy_info):
  2277. section = 'Numeric'
  2278. modulename = 'Numeric'
  2279. class numpy_info(_numpy_info):
  2280. section = 'numpy'
  2281. modulename = 'numpy'
  2282. class numerix_info(system_info):
  2283. section = 'numerix'
  2284. def calc_info(self):
  2285. which = None, None
  2286. if os.getenv("NUMERIX"):
  2287. which = os.getenv("NUMERIX"), "environment var"
  2288. # If all the above fail, default to numpy.
  2289. if which[0] is None:
  2290. which = "numpy", "defaulted"
  2291. try:
  2292. import numpy # noqa: F401
  2293. which = "numpy", "defaulted"
  2294. except ImportError as e:
  2295. msg1 = str(e)
  2296. try:
  2297. import Numeric # noqa: F401
  2298. which = "numeric", "defaulted"
  2299. except ImportError as e:
  2300. msg2 = str(e)
  2301. try:
  2302. import numarray # noqa: F401
  2303. which = "numarray", "defaulted"
  2304. except ImportError as e:
  2305. msg3 = str(e)
  2306. log.info(msg1)
  2307. log.info(msg2)
  2308. log.info(msg3)
  2309. which = which[0].strip().lower(), which[1]
  2310. if which[0] not in ["numeric", "numarray", "numpy"]:
  2311. raise ValueError("numerix selector must be either 'Numeric' "
  2312. "or 'numarray' or 'numpy' but the value obtained"
  2313. " from the %s was '%s'." % (which[1], which[0]))
  2314. os.environ['NUMERIX'] = which[0]
  2315. self.set_info(**get_info(which[0]))
  2316. class f2py_info(system_info):
  2317. def calc_info(self):
  2318. try:
  2319. import numpy.f2py as f2py
  2320. except ImportError:
  2321. return
  2322. f2py_dir = os.path.join(os.path.dirname(f2py.__file__), 'src')
  2323. self.set_info(sources=[os.path.join(f2py_dir, 'fortranobject.c')],
  2324. include_dirs=[f2py_dir])
  2325. return
  2326. class boost_python_info(system_info):
  2327. section = 'boost_python'
  2328. dir_env_var = 'BOOST'
  2329. def get_paths(self, section, key):
  2330. pre_dirs = system_info.get_paths(self, section, key)
  2331. dirs = []
  2332. for d in pre_dirs:
  2333. dirs.extend([d] + self.combine_paths(d, ['boost*']))
  2334. return [d for d in dirs if os.path.isdir(d)]
  2335. def calc_info(self):
  2336. src_dirs = self.get_src_dirs()
  2337. src_dir = ''
  2338. for d in src_dirs:
  2339. if os.path.isfile(os.path.join(d, 'libs', 'python', 'src',
  2340. 'module.cpp')):
  2341. src_dir = d
  2342. break
  2343. if not src_dir:
  2344. return
  2345. py_incl_dirs = [sysconfig.get_path('include')]
  2346. py_pincl_dir = sysconfig.get_path('platinclude')
  2347. if py_pincl_dir not in py_incl_dirs:
  2348. py_incl_dirs.append(py_pincl_dir)
  2349. srcs_dir = os.path.join(src_dir, 'libs', 'python', 'src')
  2350. bpl_srcs = glob(os.path.join(srcs_dir, '*.cpp'))
  2351. bpl_srcs += glob(os.path.join(srcs_dir, '*', '*.cpp'))
  2352. info = {'libraries': [('boost_python_src',
  2353. {'include_dirs': [src_dir] + py_incl_dirs,
  2354. 'sources':bpl_srcs}
  2355. )],
  2356. 'include_dirs': [src_dir],
  2357. }
  2358. if info:
  2359. self.set_info(**info)
  2360. return
  2361. class agg2_info(system_info):
  2362. section = 'agg2'
  2363. dir_env_var = 'AGG2'
  2364. def get_paths(self, section, key):
  2365. pre_dirs = system_info.get_paths(self, section, key)
  2366. dirs = []
  2367. for d in pre_dirs:
  2368. dirs.extend([d] + self.combine_paths(d, ['agg2*']))
  2369. return [d for d in dirs if os.path.isdir(d)]
  2370. def calc_info(self):
  2371. src_dirs = self.get_src_dirs()
  2372. src_dir = ''
  2373. for d in src_dirs:
  2374. if os.path.isfile(os.path.join(d, 'src', 'agg_affine_matrix.cpp')):
  2375. src_dir = d
  2376. break
  2377. if not src_dir:
  2378. return
  2379. if sys.platform == 'win32':
  2380. agg2_srcs = glob(os.path.join(src_dir, 'src', 'platform',
  2381. 'win32', 'agg_win32_bmp.cpp'))
  2382. else:
  2383. agg2_srcs = glob(os.path.join(src_dir, 'src', '*.cpp'))
  2384. agg2_srcs += [os.path.join(src_dir, 'src', 'platform',
  2385. 'X11',
  2386. 'agg_platform_support.cpp')]
  2387. info = {'libraries':
  2388. [('agg2_src',
  2389. {'sources': agg2_srcs,
  2390. 'include_dirs': [os.path.join(src_dir, 'include')],
  2391. }
  2392. )],
  2393. 'include_dirs': [os.path.join(src_dir, 'include')],
  2394. }
  2395. if info:
  2396. self.set_info(**info)
  2397. return
  2398. class _pkg_config_info(system_info):
  2399. section = None
  2400. config_env_var = 'PKG_CONFIG'
  2401. default_config_exe = 'pkg-config'
  2402. append_config_exe = ''
  2403. version_macro_name = None
  2404. release_macro_name = None
  2405. version_flag = '--modversion'
  2406. cflags_flag = '--cflags'
  2407. def get_config_exe(self):
  2408. if self.config_env_var in os.environ:
  2409. return os.environ[self.config_env_var]
  2410. return self.default_config_exe
  2411. def get_config_output(self, config_exe, option):
  2412. cmd = config_exe + ' ' + self.append_config_exe + ' ' + option
  2413. try:
  2414. o = subprocess.check_output(cmd)
  2415. except (OSError, subprocess.CalledProcessError):
  2416. pass
  2417. else:
  2418. o = filepath_from_subprocess_output(o)
  2419. return o
  2420. def calc_info(self):
  2421. config_exe = find_executable(self.get_config_exe())
  2422. if not config_exe:
  2423. log.warn('File not found: %s. Cannot determine %s info.' \
  2424. % (config_exe, self.section))
  2425. return
  2426. info = {}
  2427. macros = []
  2428. libraries = []
  2429. library_dirs = []
  2430. include_dirs = []
  2431. extra_link_args = []
  2432. extra_compile_args = []
  2433. version = self.get_config_output(config_exe, self.version_flag)
  2434. if version:
  2435. macros.append((self.__class__.__name__.split('.')[-1].upper(),
  2436. _c_string_literal(version)))
  2437. if self.version_macro_name:
  2438. macros.append((self.version_macro_name + '_%s'
  2439. % (version.replace('.', '_')), None))
  2440. if self.release_macro_name:
  2441. release = self.get_config_output(config_exe, '--release')
  2442. if release:
  2443. macros.append((self.release_macro_name + '_%s'
  2444. % (release.replace('.', '_')), None))
  2445. opts = self.get_config_output(config_exe, '--libs')
  2446. if opts:
  2447. for opt in opts.split():
  2448. if opt[:2] == '-l':
  2449. libraries.append(opt[2:])
  2450. elif opt[:2] == '-L':
  2451. library_dirs.append(opt[2:])
  2452. else:
  2453. extra_link_args.append(opt)
  2454. opts = self.get_config_output(config_exe, self.cflags_flag)
  2455. if opts:
  2456. for opt in opts.split():
  2457. if opt[:2] == '-I':
  2458. include_dirs.append(opt[2:])
  2459. elif opt[:2] == '-D':
  2460. if '=' in opt:
  2461. n, v = opt[2:].split('=')
  2462. macros.append((n, v))
  2463. else:
  2464. macros.append((opt[2:], None))
  2465. else:
  2466. extra_compile_args.append(opt)
  2467. if macros:
  2468. dict_append(info, define_macros=macros)
  2469. if libraries:
  2470. dict_append(info, libraries=libraries)
  2471. if library_dirs:
  2472. dict_append(info, library_dirs=library_dirs)
  2473. if include_dirs:
  2474. dict_append(info, include_dirs=include_dirs)
  2475. if extra_link_args:
  2476. dict_append(info, extra_link_args=extra_link_args)
  2477. if extra_compile_args:
  2478. dict_append(info, extra_compile_args=extra_compile_args)
  2479. if info:
  2480. self.set_info(**info)
  2481. return
  2482. class wx_info(_pkg_config_info):
  2483. section = 'wx'
  2484. config_env_var = 'WX_CONFIG'
  2485. default_config_exe = 'wx-config'
  2486. append_config_exe = ''
  2487. version_macro_name = 'WX_VERSION'
  2488. release_macro_name = 'WX_RELEASE'
  2489. version_flag = '--version'
  2490. cflags_flag = '--cxxflags'
  2491. class gdk_pixbuf_xlib_2_info(_pkg_config_info):
  2492. section = 'gdk_pixbuf_xlib_2'
  2493. append_config_exe = 'gdk-pixbuf-xlib-2.0'
  2494. version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'
  2495. class gdk_pixbuf_2_info(_pkg_config_info):
  2496. section = 'gdk_pixbuf_2'
  2497. append_config_exe = 'gdk-pixbuf-2.0'
  2498. version_macro_name = 'GDK_PIXBUF_VERSION'
  2499. class gdk_x11_2_info(_pkg_config_info):
  2500. section = 'gdk_x11_2'
  2501. append_config_exe = 'gdk-x11-2.0'
  2502. version_macro_name = 'GDK_X11_VERSION'
  2503. class gdk_2_info(_pkg_config_info):
  2504. section = 'gdk_2'
  2505. append_config_exe = 'gdk-2.0'
  2506. version_macro_name = 'GDK_VERSION'
  2507. class gdk_info(_pkg_config_info):
  2508. section = 'gdk'
  2509. append_config_exe = 'gdk'
  2510. version_macro_name = 'GDK_VERSION'
  2511. class gtkp_x11_2_info(_pkg_config_info):
  2512. section = 'gtkp_x11_2'
  2513. append_config_exe = 'gtk+-x11-2.0'
  2514. version_macro_name = 'GTK_X11_VERSION'
  2515. class gtkp_2_info(_pkg_config_info):
  2516. section = 'gtkp_2'
  2517. append_config_exe = 'gtk+-2.0'
  2518. version_macro_name = 'GTK_VERSION'
  2519. class xft_info(_pkg_config_info):
  2520. section = 'xft'
  2521. append_config_exe = 'xft'
  2522. version_macro_name = 'XFT_VERSION'
  2523. class freetype2_info(_pkg_config_info):
  2524. section = 'freetype2'
  2525. append_config_exe = 'freetype2'
  2526. version_macro_name = 'FREETYPE2_VERSION'
  2527. class amd_info(system_info):
  2528. section = 'amd'
  2529. dir_env_var = 'AMD'
  2530. _lib_names = ['amd']
  2531. def calc_info(self):
  2532. lib_dirs = self.get_lib_dirs()
  2533. opt = self.get_option_single('amd_libs', 'libraries')
  2534. amd_libs = self.get_libs(opt, self._lib_names)
  2535. info = self.check_libs(lib_dirs, amd_libs, [])
  2536. if info is None:
  2537. return
  2538. include_dirs = self.get_include_dirs()
  2539. inc_dir = None
  2540. for d in include_dirs:
  2541. p = self.combine_paths(d, 'amd.h')
  2542. if p:
  2543. inc_dir = os.path.dirname(p[0])
  2544. break
  2545. if inc_dir is not None:
  2546. dict_append(info, include_dirs=[inc_dir],
  2547. define_macros=[('SCIPY_AMD_H', None)],
  2548. swig_opts=['-I' + inc_dir])
  2549. self.set_info(**info)
  2550. return
  2551. class umfpack_info(system_info):
  2552. section = 'umfpack'
  2553. dir_env_var = 'UMFPACK'
  2554. notfounderror = UmfpackNotFoundError
  2555. _lib_names = ['umfpack']
  2556. def calc_info(self):
  2557. lib_dirs = self.get_lib_dirs()
  2558. opt = self.get_option_single('umfpack_libs', 'libraries')
  2559. umfpack_libs = self.get_libs(opt, self._lib_names)
  2560. info = self.check_libs(lib_dirs, umfpack_libs, [])
  2561. if info is None:
  2562. return
  2563. include_dirs = self.get_include_dirs()
  2564. inc_dir = None
  2565. for d in include_dirs:
  2566. p = self.combine_paths(d, ['', 'umfpack'], 'umfpack.h')
  2567. if p:
  2568. inc_dir = os.path.dirname(p[0])
  2569. break
  2570. if inc_dir is not None:
  2571. dict_append(info, include_dirs=[inc_dir],
  2572. define_macros=[('SCIPY_UMFPACK_H', None)],
  2573. swig_opts=['-I' + inc_dir])
  2574. dict_append(info, **get_info('amd'))
  2575. self.set_info(**info)
  2576. return
  2577. def combine_paths(*args, **kws):
  2578. """ Return a list of existing paths composed by all combinations of
  2579. items from arguments.
  2580. """
  2581. r = []
  2582. for a in args:
  2583. if not a:
  2584. continue
  2585. if is_string(a):
  2586. a = [a]
  2587. r.append(a)
  2588. args = r
  2589. if not args:
  2590. return []
  2591. if len(args) == 1:
  2592. result = reduce(lambda a, b: a + b, map(glob, args[0]), [])
  2593. elif len(args) == 2:
  2594. result = []
  2595. for a0 in args[0]:
  2596. for a1 in args[1]:
  2597. result.extend(glob(os.path.join(a0, a1)))
  2598. else:
  2599. result = combine_paths(*(combine_paths(args[0], args[1]) + args[2:]))
  2600. log.debug('(paths: %s)', ','.join(result))
  2601. return result
  2602. language_map = {'c': 0, 'c++': 1, 'f77': 2, 'f90': 3}
  2603. inv_language_map = {0: 'c', 1: 'c++', 2: 'f77', 3: 'f90'}
  2604. def dict_append(d, **kws):
  2605. languages = []
  2606. for k, v in kws.items():
  2607. if k == 'language':
  2608. languages.append(v)
  2609. continue
  2610. if k in d:
  2611. if k in ['library_dirs', 'include_dirs',
  2612. 'extra_compile_args', 'extra_link_args',
  2613. 'runtime_library_dirs', 'define_macros']:
  2614. [d[k].append(vv) for vv in v if vv not in d[k]]
  2615. else:
  2616. d[k].extend(v)
  2617. else:
  2618. d[k] = v
  2619. if languages:
  2620. l = inv_language_map[max([language_map.get(l, 0) for l in languages])]
  2621. d['language'] = l
  2622. return
  2623. def parseCmdLine(argv=(None,)):
  2624. import optparse
  2625. parser = optparse.OptionParser("usage: %prog [-v] [info objs]")
  2626. parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
  2627. default=False,
  2628. help='be verbose and print more messages')
  2629. opts, args = parser.parse_args(args=argv[1:])
  2630. return opts, args
  2631. def show_all(argv=None):
  2632. import inspect
  2633. if argv is None:
  2634. argv = sys.argv
  2635. opts, args = parseCmdLine(argv)
  2636. if opts.verbose:
  2637. log.set_threshold(log.DEBUG)
  2638. else:
  2639. log.set_threshold(log.INFO)
  2640. show_only = []
  2641. for n in args:
  2642. if n[-5:] != '_info':
  2643. n = n + '_info'
  2644. show_only.append(n)
  2645. show_all = not show_only
  2646. _gdict_ = globals().copy()
  2647. for name, c in _gdict_.items():
  2648. if not inspect.isclass(c):
  2649. continue
  2650. if not issubclass(c, system_info) or c is system_info:
  2651. continue
  2652. if not show_all:
  2653. if name not in show_only:
  2654. continue
  2655. del show_only[show_only.index(name)]
  2656. conf = c()
  2657. conf.verbosity = 2
  2658. # FIXME: r not used
  2659. r = conf.get_info()
  2660. if show_only:
  2661. log.info('Info classes not defined: %s', ','.join(show_only))
  2662. if __name__ == "__main__":
  2663. show_all()