system_info.py 105 KB

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