system_info.py 103 KB

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