system_info.py 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079
  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().replace(':',',') 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. if lib[0] == '-':
  886. found_libs.append(lib)
  887. continue
  888. for lib_dir in lib_dirs:
  889. found_lib = self._find_lib(lib_dir, lib, exts)
  890. if found_lib:
  891. found_libs.append(found_lib)
  892. if lib_dir not in found_dirs:
  893. found_dirs.append(lib_dir)
  894. break
  895. return found_dirs, found_libs
  896. def _check_libs(self, lib_dirs, libs, opt_libs, exts):
  897. """Find mandatory and optional libs in expected paths.
  898. Missing optional libraries are silently forgotten.
  899. """
  900. if not is_sequence(lib_dirs):
  901. lib_dirs = [lib_dirs]
  902. # First, try to find the mandatory libraries
  903. found_dirs, found_libs = self._find_libs(lib_dirs, libs, exts)
  904. if len(found_libs) > 0 and len(found_libs) == len(libs):
  905. # Now, check for optional libraries
  906. opt_found_dirs, opt_found_libs = self._find_libs(lib_dirs, opt_libs, exts)
  907. found_libs.extend(opt_found_libs)
  908. for lib_dir in opt_found_dirs:
  909. if lib_dir not in found_dirs:
  910. found_dirs.append(lib_dir)
  911. info = {'libraries': found_libs, 'library_dirs': found_dirs}
  912. return info
  913. else:
  914. return None
  915. def combine_paths(self, *args):
  916. """Return a list of existing paths composed by all combinations
  917. of items from the arguments.
  918. """
  919. return combine_paths(*args)
  920. class fft_opt_info(system_info):
  921. def calc_info(self):
  922. info = {}
  923. fftw_info = get_info('fftw3') or get_info('fftw2') or get_info('dfftw')
  924. djbfft_info = get_info('djbfft')
  925. if fftw_info:
  926. dict_append(info, **fftw_info)
  927. if djbfft_info:
  928. dict_append(info, **djbfft_info)
  929. self.set_info(**info)
  930. return
  931. class fftw_info(system_info):
  932. #variables to override
  933. section = 'fftw'
  934. dir_env_var = 'FFTW'
  935. notfounderror = FFTWNotFoundError
  936. ver_info = [{'name':'fftw3',
  937. 'libs':['fftw3'],
  938. 'includes':['fftw3.h'],
  939. 'macros':[('SCIPY_FFTW3_H', None)]},
  940. {'name':'fftw2',
  941. 'libs':['rfftw', 'fftw'],
  942. 'includes':['fftw.h', 'rfftw.h'],
  943. 'macros':[('SCIPY_FFTW_H', None)]}]
  944. def calc_ver_info(self, ver_param):
  945. """Returns True on successful version detection, else False"""
  946. lib_dirs = self.get_lib_dirs()
  947. incl_dirs = self.get_include_dirs()
  948. opt = self.get_option_single(self.section + '_libs', 'libraries')
  949. libs = self.get_libs(opt, ver_param['libs'])
  950. info = self.check_libs(lib_dirs, libs)
  951. if info is not None:
  952. flag = 0
  953. for d in incl_dirs:
  954. if len(self.combine_paths(d, ver_param['includes'])) \
  955. == len(ver_param['includes']):
  956. dict_append(info, include_dirs=[d])
  957. flag = 1
  958. break
  959. if flag:
  960. dict_append(info, define_macros=ver_param['macros'])
  961. else:
  962. info = None
  963. if info is not None:
  964. self.set_info(**info)
  965. return True
  966. else:
  967. log.info(' %s not found' % (ver_param['name']))
  968. return False
  969. def calc_info(self):
  970. for i in self.ver_info:
  971. if self.calc_ver_info(i):
  972. break
  973. class fftw2_info(fftw_info):
  974. #variables to override
  975. section = 'fftw'
  976. dir_env_var = 'FFTW'
  977. notfounderror = FFTWNotFoundError
  978. ver_info = [{'name':'fftw2',
  979. 'libs':['rfftw', 'fftw'],
  980. 'includes':['fftw.h', 'rfftw.h'],
  981. 'macros':[('SCIPY_FFTW_H', None)]}
  982. ]
  983. class fftw3_info(fftw_info):
  984. #variables to override
  985. section = 'fftw3'
  986. dir_env_var = 'FFTW3'
  987. notfounderror = FFTWNotFoundError
  988. ver_info = [{'name':'fftw3',
  989. 'libs':['fftw3'],
  990. 'includes':['fftw3.h'],
  991. 'macros':[('SCIPY_FFTW3_H', None)]},
  992. ]
  993. class dfftw_info(fftw_info):
  994. section = 'fftw'
  995. dir_env_var = 'FFTW'
  996. ver_info = [{'name':'dfftw',
  997. 'libs':['drfftw', 'dfftw'],
  998. 'includes':['dfftw.h', 'drfftw.h'],
  999. 'macros':[('SCIPY_DFFTW_H', None)]}]
  1000. class sfftw_info(fftw_info):
  1001. section = 'fftw'
  1002. dir_env_var = 'FFTW'
  1003. ver_info = [{'name':'sfftw',
  1004. 'libs':['srfftw', 'sfftw'],
  1005. 'includes':['sfftw.h', 'srfftw.h'],
  1006. 'macros':[('SCIPY_SFFTW_H', None)]}]
  1007. class fftw_threads_info(fftw_info):
  1008. section = 'fftw'
  1009. dir_env_var = 'FFTW'
  1010. ver_info = [{'name':'fftw threads',
  1011. 'libs':['rfftw_threads', 'fftw_threads'],
  1012. 'includes':['fftw_threads.h', 'rfftw_threads.h'],
  1013. 'macros':[('SCIPY_FFTW_THREADS_H', None)]}]
  1014. class dfftw_threads_info(fftw_info):
  1015. section = 'fftw'
  1016. dir_env_var = 'FFTW'
  1017. ver_info = [{'name':'dfftw threads',
  1018. 'libs':['drfftw_threads', 'dfftw_threads'],
  1019. 'includes':['dfftw_threads.h', 'drfftw_threads.h'],
  1020. 'macros':[('SCIPY_DFFTW_THREADS_H', None)]}]
  1021. class sfftw_threads_info(fftw_info):
  1022. section = 'fftw'
  1023. dir_env_var = 'FFTW'
  1024. ver_info = [{'name':'sfftw threads',
  1025. 'libs':['srfftw_threads', 'sfftw_threads'],
  1026. 'includes':['sfftw_threads.h', 'srfftw_threads.h'],
  1027. 'macros':[('SCIPY_SFFTW_THREADS_H', None)]}]
  1028. class djbfft_info(system_info):
  1029. section = 'djbfft'
  1030. dir_env_var = 'DJBFFT'
  1031. notfounderror = DJBFFTNotFoundError
  1032. def get_paths(self, section, key):
  1033. pre_dirs = system_info.get_paths(self, section, key)
  1034. dirs = []
  1035. for d in pre_dirs:
  1036. dirs.extend(self.combine_paths(d, ['djbfft']) + [d])
  1037. return [d for d in dirs if os.path.isdir(d)]
  1038. def calc_info(self):
  1039. lib_dirs = self.get_lib_dirs()
  1040. incl_dirs = self.get_include_dirs()
  1041. info = None
  1042. for d in lib_dirs:
  1043. p = self.combine_paths(d, ['djbfft.a'])
  1044. if p:
  1045. info = {'extra_objects': p}
  1046. break
  1047. p = self.combine_paths(d, ['libdjbfft.a', 'libdjbfft' + so_ext])
  1048. if p:
  1049. info = {'libraries': ['djbfft'], 'library_dirs': [d]}
  1050. break
  1051. if info is None:
  1052. return
  1053. for d in incl_dirs:
  1054. if len(self.combine_paths(d, ['fftc8.h', 'fftfreq.h'])) == 2:
  1055. dict_append(info, include_dirs=[d],
  1056. define_macros=[('SCIPY_DJBFFT_H', None)])
  1057. self.set_info(**info)
  1058. return
  1059. return
  1060. class mkl_info(system_info):
  1061. section = 'mkl'
  1062. dir_env_var = 'MKLROOT'
  1063. _lib_mkl = ['mkl_rt']
  1064. def get_mkl_rootdir(self):
  1065. mklroot = os.environ.get('MKLROOT', None)
  1066. if mklroot is not None:
  1067. return mklroot
  1068. paths = os.environ.get('LD_LIBRARY_PATH', '').split(os.pathsep)
  1069. ld_so_conf = '/etc/ld.so.conf'
  1070. if os.path.isfile(ld_so_conf):
  1071. with open(ld_so_conf, 'r') as f:
  1072. for d in f:
  1073. d = d.strip()
  1074. if d:
  1075. paths.append(d)
  1076. intel_mkl_dirs = []
  1077. for path in paths:
  1078. path_atoms = path.split(os.sep)
  1079. for m in path_atoms:
  1080. if m.startswith('mkl'):
  1081. d = os.sep.join(path_atoms[:path_atoms.index(m) + 2])
  1082. intel_mkl_dirs.append(d)
  1083. break
  1084. for d in paths:
  1085. dirs = glob(os.path.join(d, 'mkl', '*'))
  1086. dirs += glob(os.path.join(d, 'mkl*'))
  1087. for sub_dir in dirs:
  1088. if os.path.isdir(os.path.join(sub_dir, 'lib')):
  1089. return sub_dir
  1090. return None
  1091. def __init__(self):
  1092. mklroot = self.get_mkl_rootdir()
  1093. if mklroot is None:
  1094. system_info.__init__(self)
  1095. else:
  1096. from .cpuinfo import cpu
  1097. if cpu.is_Itanium():
  1098. plt = '64'
  1099. elif cpu.is_Intel() and cpu.is_64bit():
  1100. plt = 'intel64'
  1101. else:
  1102. plt = '32'
  1103. system_info.__init__(
  1104. self,
  1105. default_lib_dirs=[os.path.join(mklroot, 'lib', plt)],
  1106. default_include_dirs=[os.path.join(mklroot, 'include')])
  1107. def calc_info(self):
  1108. lib_dirs = self.get_lib_dirs()
  1109. incl_dirs = self.get_include_dirs()
  1110. opt = self.get_option_single('mkl_libs', 'libraries')
  1111. mkl_libs = self.get_libs(opt, self._lib_mkl)
  1112. info = self.check_libs2(lib_dirs, mkl_libs)
  1113. if info is None:
  1114. return
  1115. dict_append(info,
  1116. define_macros=[('SCIPY_MKL_H', None),
  1117. ('HAVE_CBLAS', None)],
  1118. include_dirs=incl_dirs)
  1119. if sys.platform == 'win32':
  1120. pass # win32 has no pthread library
  1121. else:
  1122. dict_append(info, libraries=['pthread'])
  1123. self.set_info(**info)
  1124. class lapack_mkl_info(mkl_info):
  1125. pass
  1126. class blas_mkl_info(mkl_info):
  1127. pass
  1128. class atlas_info(system_info):
  1129. section = 'atlas'
  1130. dir_env_var = 'ATLAS'
  1131. _lib_names = ['f77blas', 'cblas']
  1132. if sys.platform[:7] == 'freebsd':
  1133. _lib_atlas = ['atlas_r']
  1134. _lib_lapack = ['alapack_r']
  1135. else:
  1136. _lib_atlas = ['atlas']
  1137. _lib_lapack = ['lapack']
  1138. notfounderror = AtlasNotFoundError
  1139. def get_paths(self, section, key):
  1140. pre_dirs = system_info.get_paths(self, section, key)
  1141. dirs = []
  1142. for d in pre_dirs:
  1143. dirs.extend(self.combine_paths(d, ['atlas*', 'ATLAS*',
  1144. 'sse', '3dnow', 'sse2']) + [d])
  1145. return [d for d in dirs if os.path.isdir(d)]
  1146. def calc_info(self):
  1147. lib_dirs = self.get_lib_dirs()
  1148. info = {}
  1149. opt = self.get_option_single('atlas_libs', 'libraries')
  1150. atlas_libs = self.get_libs(opt, self._lib_names + self._lib_atlas)
  1151. lapack_libs = self.get_libs('lapack_libs', self._lib_lapack)
  1152. atlas = None
  1153. lapack = None
  1154. atlas_1 = None
  1155. for d in lib_dirs:
  1156. # FIXME: lapack_atlas is unused
  1157. lapack_atlas = self.check_libs2(d, ['lapack_atlas'], [])
  1158. atlas = self.check_libs2(d, atlas_libs, [])
  1159. if atlas is not None:
  1160. lib_dirs2 = [d] + self.combine_paths(d, ['atlas*', 'ATLAS*'])
  1161. lapack = self.check_libs2(lib_dirs2, lapack_libs, [])
  1162. if lapack is not None:
  1163. break
  1164. if atlas:
  1165. atlas_1 = atlas
  1166. log.info(self.__class__)
  1167. if atlas is None:
  1168. atlas = atlas_1
  1169. if atlas is None:
  1170. return
  1171. include_dirs = self.get_include_dirs()
  1172. h = (self.combine_paths(lib_dirs + include_dirs, 'cblas.h') or [None])
  1173. h = h[0]
  1174. if h:
  1175. h = os.path.dirname(h)
  1176. dict_append(info, include_dirs=[h])
  1177. info['language'] = 'c'
  1178. if lapack is not None:
  1179. dict_append(info, **lapack)
  1180. dict_append(info, **atlas)
  1181. elif 'lapack_atlas' in atlas['libraries']:
  1182. dict_append(info, **atlas)
  1183. dict_append(info,
  1184. define_macros=[('ATLAS_WITH_LAPACK_ATLAS', None)])
  1185. self.set_info(**info)
  1186. return
  1187. else:
  1188. dict_append(info, **atlas)
  1189. dict_append(info, define_macros=[('ATLAS_WITHOUT_LAPACK', None)])
  1190. message = textwrap.dedent("""
  1191. *********************************************************************
  1192. Could not find lapack library within the ATLAS installation.
  1193. *********************************************************************
  1194. """)
  1195. warnings.warn(message, stacklevel=2)
  1196. self.set_info(**info)
  1197. return
  1198. # Check if lapack library is complete, only warn if it is not.
  1199. lapack_dir = lapack['library_dirs'][0]
  1200. lapack_name = lapack['libraries'][0]
  1201. lapack_lib = None
  1202. lib_prefixes = ['lib']
  1203. if sys.platform == 'win32':
  1204. lib_prefixes.append('')
  1205. for e in self.library_extensions():
  1206. for prefix in lib_prefixes:
  1207. fn = os.path.join(lapack_dir, prefix + lapack_name + e)
  1208. if os.path.exists(fn):
  1209. lapack_lib = fn
  1210. break
  1211. if lapack_lib:
  1212. break
  1213. if lapack_lib is not None:
  1214. sz = os.stat(lapack_lib)[6]
  1215. if sz <= 4000 * 1024:
  1216. message = textwrap.dedent("""
  1217. *********************************************************************
  1218. Lapack library (from ATLAS) is probably incomplete:
  1219. size of %s is %sk (expected >4000k)
  1220. Follow the instructions in the KNOWN PROBLEMS section of the file
  1221. numpy/INSTALL.txt.
  1222. *********************************************************************
  1223. """) % (lapack_lib, sz / 1024)
  1224. warnings.warn(message, stacklevel=2)
  1225. else:
  1226. info['language'] = 'f77'
  1227. atlas_version, atlas_extra_info = get_atlas_version(**atlas)
  1228. dict_append(info, **atlas_extra_info)
  1229. self.set_info(**info)
  1230. class atlas_blas_info(atlas_info):
  1231. _lib_names = ['f77blas', 'cblas']
  1232. def calc_info(self):
  1233. lib_dirs = self.get_lib_dirs()
  1234. info = {}
  1235. opt = self.get_option_single('atlas_libs', 'libraries')
  1236. atlas_libs = self.get_libs(opt, self._lib_names + self._lib_atlas)
  1237. atlas = self.check_libs2(lib_dirs, atlas_libs, [])
  1238. if atlas is None:
  1239. return
  1240. include_dirs = self.get_include_dirs()
  1241. h = (self.combine_paths(lib_dirs + include_dirs, 'cblas.h') or [None])
  1242. h = h[0]
  1243. if h:
  1244. h = os.path.dirname(h)
  1245. dict_append(info, include_dirs=[h])
  1246. info['language'] = 'c'
  1247. info['define_macros'] = [('HAVE_CBLAS', None)]
  1248. atlas_version, atlas_extra_info = get_atlas_version(**atlas)
  1249. dict_append(atlas, **atlas_extra_info)
  1250. dict_append(info, **atlas)
  1251. self.set_info(**info)
  1252. return
  1253. class atlas_threads_info(atlas_info):
  1254. dir_env_var = ['PTATLAS', 'ATLAS']
  1255. _lib_names = ['ptf77blas', 'ptcblas']
  1256. class atlas_blas_threads_info(atlas_blas_info):
  1257. dir_env_var = ['PTATLAS', 'ATLAS']
  1258. _lib_names = ['ptf77blas', 'ptcblas']
  1259. class lapack_atlas_info(atlas_info):
  1260. _lib_names = ['lapack_atlas'] + atlas_info._lib_names
  1261. class lapack_atlas_threads_info(atlas_threads_info):
  1262. _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names
  1263. class atlas_3_10_info(atlas_info):
  1264. _lib_names = ['satlas']
  1265. _lib_atlas = _lib_names
  1266. _lib_lapack = _lib_names
  1267. class atlas_3_10_blas_info(atlas_3_10_info):
  1268. _lib_names = ['satlas']
  1269. def calc_info(self):
  1270. lib_dirs = self.get_lib_dirs()
  1271. info = {}
  1272. opt = self.get_option_single('atlas_lib', 'libraries')
  1273. atlas_libs = self.get_libs(opt, self._lib_names)
  1274. atlas = self.check_libs2(lib_dirs, atlas_libs, [])
  1275. if atlas is None:
  1276. return
  1277. include_dirs = self.get_include_dirs()
  1278. h = (self.combine_paths(lib_dirs + include_dirs, 'cblas.h') or [None])
  1279. h = h[0]
  1280. if h:
  1281. h = os.path.dirname(h)
  1282. dict_append(info, include_dirs=[h])
  1283. info['language'] = 'c'
  1284. info['define_macros'] = [('HAVE_CBLAS', None)]
  1285. atlas_version, atlas_extra_info = get_atlas_version(**atlas)
  1286. dict_append(atlas, **atlas_extra_info)
  1287. dict_append(info, **atlas)
  1288. self.set_info(**info)
  1289. return
  1290. class atlas_3_10_threads_info(atlas_3_10_info):
  1291. dir_env_var = ['PTATLAS', 'ATLAS']
  1292. _lib_names = ['tatlas']
  1293. _lib_atlas = _lib_names
  1294. _lib_lapack = _lib_names
  1295. class atlas_3_10_blas_threads_info(atlas_3_10_blas_info):
  1296. dir_env_var = ['PTATLAS', 'ATLAS']
  1297. _lib_names = ['tatlas']
  1298. class lapack_atlas_3_10_info(atlas_3_10_info):
  1299. pass
  1300. class lapack_atlas_3_10_threads_info(atlas_3_10_threads_info):
  1301. pass
  1302. class lapack_info(system_info):
  1303. section = 'lapack'
  1304. dir_env_var = 'LAPACK'
  1305. _lib_names = ['lapack']
  1306. notfounderror = LapackNotFoundError
  1307. def calc_info(self):
  1308. lib_dirs = self.get_lib_dirs()
  1309. opt = self.get_option_single('lapack_libs', 'libraries')
  1310. lapack_libs = self.get_libs(opt, self._lib_names)
  1311. info = self.check_libs(lib_dirs, lapack_libs, [])
  1312. if info is None:
  1313. return
  1314. info['language'] = 'f77'
  1315. self.set_info(**info)
  1316. class lapack_src_info(system_info):
  1317. section = 'lapack_src'
  1318. dir_env_var = 'LAPACK_SRC'
  1319. notfounderror = LapackSrcNotFoundError
  1320. def get_paths(self, section, key):
  1321. pre_dirs = system_info.get_paths(self, section, key)
  1322. dirs = []
  1323. for d in pre_dirs:
  1324. dirs.extend([d] + self.combine_paths(d, ['LAPACK*/SRC', 'SRC']))
  1325. return [d for d in dirs if os.path.isdir(d)]
  1326. def calc_info(self):
  1327. src_dirs = self.get_src_dirs()
  1328. src_dir = ''
  1329. for d in src_dirs:
  1330. if os.path.isfile(os.path.join(d, 'dgesv.f')):
  1331. src_dir = d
  1332. break
  1333. if not src_dir:
  1334. #XXX: Get sources from netlib. May be ask first.
  1335. return
  1336. # The following is extracted from LAPACK-3.0/SRC/Makefile.
  1337. # Added missing names from lapack-lite-3.1.1/SRC/Makefile
  1338. # while keeping removed names for Lapack-3.0 compatibility.
  1339. allaux = '''
  1340. ilaenv ieeeck lsame lsamen xerbla
  1341. iparmq
  1342. ''' # *.f
  1343. laux = '''
  1344. bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1
  1345. laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2
  1346. lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre
  1347. larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4
  1348. lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1
  1349. lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf
  1350. stebz stedc steqr sterf
  1351. larra larrc larrd larr larrk larrj larrr laneg laisnan isnan
  1352. lazq3 lazq4
  1353. ''' # [s|d]*.f
  1354. lasrc = '''
  1355. gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak
  1356. gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv
  1357. gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2
  1358. geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd
  1359. gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal
  1360. gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd
  1361. ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein
  1362. hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0
  1363. lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb
  1364. lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp
  1365. laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv
  1366. lartv larz larzb larzt laswp lasyf latbs latdf latps latrd
  1367. latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv
  1368. pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2
  1369. potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri
  1370. pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs
  1371. spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv
  1372. sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2
  1373. tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs
  1374. trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs
  1375. tzrqf tzrzf
  1376. lacn2 lahr2 stemr laqr0 laqr1 laqr2 laqr3 laqr4 laqr5
  1377. ''' # [s|c|d|z]*.f
  1378. sd_lasrc = '''
  1379. laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l
  1380. org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr
  1381. orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3
  1382. ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx
  1383. sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd
  1384. stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd
  1385. sygvx sytd2 sytrd
  1386. ''' # [s|d]*.f
  1387. cz_lasrc = '''
  1388. bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev
  1389. heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv
  1390. hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd
  1391. hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf
  1392. hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7
  1393. laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe
  1394. laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv
  1395. spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq
  1396. ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2
  1397. unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr
  1398. ''' # [c|z]*.f
  1399. #######
  1400. sclaux = laux + ' econd ' # s*.f
  1401. dzlaux = laux + ' secnd ' # d*.f
  1402. slasrc = lasrc + sd_lasrc # s*.f
  1403. dlasrc = lasrc + sd_lasrc # d*.f
  1404. clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f
  1405. zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f
  1406. oclasrc = ' icmax1 scsum1 ' # *.f
  1407. ozlasrc = ' izmax1 dzsum1 ' # *.f
  1408. sources = ['s%s.f' % f for f in (sclaux + slasrc).split()] \
  1409. + ['d%s.f' % f for f in (dzlaux + dlasrc).split()] \
  1410. + ['c%s.f' % f for f in (clasrc).split()] \
  1411. + ['z%s.f' % f for f in (zlasrc).split()] \
  1412. + ['%s.f' % f for f in (allaux + oclasrc + ozlasrc).split()]
  1413. sources = [os.path.join(src_dir, f) for f in sources]
  1414. # Lapack 3.1:
  1415. src_dir2 = os.path.join(src_dir, '..', 'INSTALL')
  1416. sources += [os.path.join(src_dir2, p + 'lamch.f') for p in 'sdcz']
  1417. # Lapack 3.2.1:
  1418. sources += [os.path.join(src_dir, p + 'larfp.f') for p in 'sdcz']
  1419. sources += [os.path.join(src_dir, 'ila' + p + 'lr.f') for p in 'sdcz']
  1420. sources += [os.path.join(src_dir, 'ila' + p + 'lc.f') for p in 'sdcz']
  1421. # Should we check here actual existence of source files?
  1422. # Yes, the file listing is different between 3.0 and 3.1
  1423. # versions.
  1424. sources = [f for f in sources if os.path.isfile(f)]
  1425. info = {'sources': sources, 'language': 'f77'}
  1426. self.set_info(**info)
  1427. atlas_version_c_text = r'''
  1428. /* This file is generated from numpy/distutils/system_info.py */
  1429. void ATL_buildinfo(void);
  1430. int main(void) {
  1431. ATL_buildinfo();
  1432. return 0;
  1433. }
  1434. '''
  1435. _cached_atlas_version = {}
  1436. def get_atlas_version(**config):
  1437. libraries = config.get('libraries', [])
  1438. library_dirs = config.get('library_dirs', [])
  1439. key = (tuple(libraries), tuple(library_dirs))
  1440. if key in _cached_atlas_version:
  1441. return _cached_atlas_version[key]
  1442. c = cmd_config(Distribution())
  1443. atlas_version = None
  1444. info = {}
  1445. try:
  1446. s, o = c.get_output(atlas_version_c_text,
  1447. libraries=libraries, library_dirs=library_dirs,
  1448. )
  1449. if s and re.search(r'undefined reference to `_gfortran', o, re.M):
  1450. s, o = c.get_output(atlas_version_c_text,
  1451. libraries=libraries + ['gfortran'],
  1452. library_dirs=library_dirs,
  1453. )
  1454. if not s:
  1455. warnings.warn(textwrap.dedent("""
  1456. *****************************************************
  1457. Linkage with ATLAS requires gfortran. Use
  1458. python setup.py config_fc --fcompiler=gnu95 ...
  1459. when building extension libraries that use ATLAS.
  1460. Make sure that -lgfortran is used for C++ extensions.
  1461. *****************************************************
  1462. """), stacklevel=2)
  1463. dict_append(info, language='f90',
  1464. define_macros=[('ATLAS_REQUIRES_GFORTRAN', None)])
  1465. except Exception: # failed to get version from file -- maybe on Windows
  1466. # look at directory name
  1467. for o in library_dirs:
  1468. m = re.search(r'ATLAS_(?P<version>\d+[.]\d+[.]\d+)_', o)
  1469. if m:
  1470. atlas_version = m.group('version')
  1471. if atlas_version is not None:
  1472. break
  1473. # final choice --- look at ATLAS_VERSION environment
  1474. # variable
  1475. if atlas_version is None:
  1476. atlas_version = os.environ.get('ATLAS_VERSION', None)
  1477. if atlas_version:
  1478. dict_append(info, define_macros=[(
  1479. 'ATLAS_INFO', _c_string_literal(atlas_version))
  1480. ])
  1481. else:
  1482. dict_append(info, define_macros=[('NO_ATLAS_INFO', -1)])
  1483. return atlas_version or '?.?.?', info
  1484. if not s:
  1485. m = re.search(r'ATLAS version (?P<version>\d+[.]\d+[.]\d+)', o)
  1486. if m:
  1487. atlas_version = m.group('version')
  1488. if atlas_version is None:
  1489. if re.search(r'undefined symbol: ATL_buildinfo', o, re.M):
  1490. atlas_version = '3.2.1_pre3.3.6'
  1491. else:
  1492. log.info('Status: %d', s)
  1493. log.info('Output: %s', o)
  1494. elif atlas_version == '3.2.1_pre3.3.6':
  1495. dict_append(info, define_macros=[('NO_ATLAS_INFO', -2)])
  1496. else:
  1497. dict_append(info, define_macros=[(
  1498. 'ATLAS_INFO', _c_string_literal(atlas_version))
  1499. ])
  1500. result = _cached_atlas_version[key] = atlas_version, info
  1501. return result
  1502. class lapack_opt_info(system_info):
  1503. notfounderror = LapackNotFoundError
  1504. # List of all known LAPACK libraries, in the default order
  1505. lapack_order = ['mkl', 'openblas', 'flame', 'atlas', 'lapack']
  1506. order_env_var_name = 'NPY_LAPACK_ORDER'
  1507. def _calc_info_mkl(self):
  1508. info = get_info('lapack_mkl')
  1509. if info:
  1510. self.set_info(**info)
  1511. return True
  1512. return False
  1513. def _calc_info_openblas(self):
  1514. info = get_info('openblas_lapack')
  1515. if info:
  1516. self.set_info(**info)
  1517. return True
  1518. info = get_info('openblas_clapack')
  1519. if info:
  1520. self.set_info(**info)
  1521. return True
  1522. return False
  1523. def _calc_info_flame(self):
  1524. info = get_info('flame')
  1525. if info:
  1526. self.set_info(**info)
  1527. return True
  1528. return False
  1529. def _calc_info_atlas(self):
  1530. info = get_info('atlas_3_10_threads')
  1531. if not info:
  1532. info = get_info('atlas_3_10')
  1533. if not info:
  1534. info = get_info('atlas_threads')
  1535. if not info:
  1536. info = get_info('atlas')
  1537. if info:
  1538. # Figure out if ATLAS has lapack...
  1539. # If not we need the lapack library, but not BLAS!
  1540. l = info.get('define_macros', [])
  1541. if ('ATLAS_WITH_LAPACK_ATLAS', None) in l \
  1542. or ('ATLAS_WITHOUT_LAPACK', None) in l:
  1543. # Get LAPACK (with possible warnings)
  1544. # If not found we don't accept anything
  1545. # since we can't use ATLAS with LAPACK!
  1546. lapack_info = self._get_info_lapack()
  1547. if not lapack_info:
  1548. return False
  1549. dict_append(info, **lapack_info)
  1550. self.set_info(**info)
  1551. return True
  1552. return False
  1553. def _calc_info_accelerate(self):
  1554. info = get_info('accelerate')
  1555. if info:
  1556. self.set_info(**info)
  1557. return True
  1558. return False
  1559. def _get_info_blas(self):
  1560. # Default to get the optimized BLAS implementation
  1561. info = get_info('blas_opt')
  1562. if not info:
  1563. warnings.warn(BlasNotFoundError.__doc__ or '', stacklevel=3)
  1564. info_src = get_info('blas_src')
  1565. if not info_src:
  1566. warnings.warn(BlasSrcNotFoundError.__doc__ or '', stacklevel=3)
  1567. return {}
  1568. dict_append(info, libraries=[('fblas_src', info_src)])
  1569. return info
  1570. def _get_info_lapack(self):
  1571. info = get_info('lapack')
  1572. if not info:
  1573. warnings.warn(LapackNotFoundError.__doc__ or '', stacklevel=3)
  1574. info_src = get_info('lapack_src')
  1575. if not info_src:
  1576. warnings.warn(LapackSrcNotFoundError.__doc__ or '', stacklevel=3)
  1577. return {}
  1578. dict_append(info, libraries=[('flapack_src', info_src)])
  1579. return info
  1580. def _calc_info_lapack(self):
  1581. info = self._get_info_lapack()
  1582. if info:
  1583. info_blas = self._get_info_blas()
  1584. dict_append(info, **info_blas)
  1585. dict_append(info, define_macros=[('NO_ATLAS_INFO', 1)])
  1586. self.set_info(**info)
  1587. return True
  1588. return False
  1589. def _calc_info(self, name):
  1590. return getattr(self, '_calc_info_{}'.format(name))()
  1591. def calc_info(self):
  1592. lapack_order, unknown_order = _parse_env_order(self.lapack_order, self.order_env_var_name)
  1593. if len(unknown_order) > 0:
  1594. raise ValueError("lapack_opt_info user defined "
  1595. "LAPACK order has unacceptable "
  1596. "values: {}".format(unknown_order))
  1597. for lapack in lapack_order:
  1598. if self._calc_info(lapack):
  1599. return
  1600. if 'lapack' not in lapack_order:
  1601. # Since the user may request *not* to use any library, we still need
  1602. # to raise warnings to signal missing packages!
  1603. warnings.warn(LapackNotFoundError.__doc__ or '', stacklevel=2)
  1604. warnings.warn(LapackSrcNotFoundError.__doc__ or '', stacklevel=2)
  1605. class _ilp64_opt_info_mixin:
  1606. symbol_suffix = None
  1607. symbol_prefix = None
  1608. def _check_info(self, info):
  1609. macros = dict(info.get('define_macros', []))
  1610. prefix = macros.get('BLAS_SYMBOL_PREFIX', '')
  1611. suffix = macros.get('BLAS_SYMBOL_SUFFIX', '')
  1612. if self.symbol_prefix not in (None, prefix):
  1613. return False
  1614. if self.symbol_suffix not in (None, suffix):
  1615. return False
  1616. return bool(info)
  1617. class lapack_ilp64_opt_info(lapack_opt_info, _ilp64_opt_info_mixin):
  1618. notfounderror = LapackILP64NotFoundError
  1619. lapack_order = ['openblas64_', 'openblas_ilp64']
  1620. order_env_var_name = 'NPY_LAPACK_ILP64_ORDER'
  1621. def _calc_info(self, name):
  1622. info = get_info(name + '_lapack')
  1623. if self._check_info(info):
  1624. self.set_info(**info)
  1625. return True
  1626. return False
  1627. class lapack_ilp64_plain_opt_info(lapack_ilp64_opt_info):
  1628. # Same as lapack_ilp64_opt_info, but fix symbol names
  1629. symbol_prefix = ''
  1630. symbol_suffix = ''
  1631. class lapack64__opt_info(lapack_ilp64_opt_info):
  1632. symbol_prefix = ''
  1633. symbol_suffix = '64_'
  1634. class blas_opt_info(system_info):
  1635. notfounderror = BlasNotFoundError
  1636. # List of all known BLAS libraries, in the default order
  1637. blas_order = ['mkl', 'blis', 'openblas', 'atlas', 'blas']
  1638. order_env_var_name = 'NPY_BLAS_ORDER'
  1639. def _calc_info_mkl(self):
  1640. info = get_info('blas_mkl')
  1641. if info:
  1642. self.set_info(**info)
  1643. return True
  1644. return False
  1645. def _calc_info_blis(self):
  1646. info = get_info('blis')
  1647. if info:
  1648. self.set_info(**info)
  1649. return True
  1650. return False
  1651. def _calc_info_openblas(self):
  1652. info = get_info('openblas')
  1653. if info:
  1654. self.set_info(**info)
  1655. return True
  1656. return False
  1657. def _calc_info_atlas(self):
  1658. info = get_info('atlas_3_10_blas_threads')
  1659. if not info:
  1660. info = get_info('atlas_3_10_blas')
  1661. if not info:
  1662. info = get_info('atlas_blas_threads')
  1663. if not info:
  1664. info = get_info('atlas_blas')
  1665. if info:
  1666. self.set_info(**info)
  1667. return True
  1668. return False
  1669. def _calc_info_accelerate(self):
  1670. info = get_info('accelerate')
  1671. if info:
  1672. self.set_info(**info)
  1673. return True
  1674. return False
  1675. def _calc_info_blas(self):
  1676. # Warn about a non-optimized BLAS library
  1677. warnings.warn(BlasOptNotFoundError.__doc__ or '', stacklevel=3)
  1678. info = {}
  1679. dict_append(info, define_macros=[('NO_ATLAS_INFO', 1)])
  1680. blas = get_info('blas')
  1681. if blas:
  1682. dict_append(info, **blas)
  1683. else:
  1684. # Not even BLAS was found!
  1685. warnings.warn(BlasNotFoundError.__doc__ or '', stacklevel=3)
  1686. blas_src = get_info('blas_src')
  1687. if not blas_src:
  1688. warnings.warn(BlasSrcNotFoundError.__doc__ or '', stacklevel=3)
  1689. return False
  1690. dict_append(info, libraries=[('fblas_src', blas_src)])
  1691. self.set_info(**info)
  1692. return True
  1693. def _calc_info(self, name):
  1694. return getattr(self, '_calc_info_{}'.format(name))()
  1695. def calc_info(self):
  1696. blas_order, unknown_order = _parse_env_order(self.blas_order, self.order_env_var_name)
  1697. if len(unknown_order) > 0:
  1698. raise ValueError("blas_opt_info user defined BLAS order has unacceptable values: {}".format(unknown_order))
  1699. for blas in blas_order:
  1700. if self._calc_info(blas):
  1701. return
  1702. if 'blas' not in blas_order:
  1703. # Since the user may request *not* to use any library, we still need
  1704. # to raise warnings to signal missing packages!
  1705. warnings.warn(BlasNotFoundError.__doc__ or '', stacklevel=2)
  1706. warnings.warn(BlasSrcNotFoundError.__doc__ or '', stacklevel=2)
  1707. class blas_ilp64_opt_info(blas_opt_info, _ilp64_opt_info_mixin):
  1708. notfounderror = BlasILP64NotFoundError
  1709. blas_order = ['openblas64_', 'openblas_ilp64']
  1710. order_env_var_name = 'NPY_BLAS_ILP64_ORDER'
  1711. def _calc_info(self, name):
  1712. info = get_info(name)
  1713. if self._check_info(info):
  1714. self.set_info(**info)
  1715. return True
  1716. return False
  1717. class blas_ilp64_plain_opt_info(blas_ilp64_opt_info):
  1718. symbol_prefix = ''
  1719. symbol_suffix = ''
  1720. class blas64__opt_info(blas_ilp64_opt_info):
  1721. symbol_prefix = ''
  1722. symbol_suffix = '64_'
  1723. class cblas_info(system_info):
  1724. section = 'cblas'
  1725. dir_env_var = 'CBLAS'
  1726. # No default as it's used only in blas_info
  1727. _lib_names = []
  1728. notfounderror = BlasNotFoundError
  1729. class blas_info(system_info):
  1730. section = 'blas'
  1731. dir_env_var = 'BLAS'
  1732. _lib_names = ['blas']
  1733. notfounderror = BlasNotFoundError
  1734. def calc_info(self):
  1735. lib_dirs = self.get_lib_dirs()
  1736. opt = self.get_option_single('blas_libs', 'libraries')
  1737. blas_libs = self.get_libs(opt, self._lib_names)
  1738. info = self.check_libs(lib_dirs, blas_libs, [])
  1739. if info is None:
  1740. return
  1741. else:
  1742. info['include_dirs'] = self.get_include_dirs()
  1743. if platform.system() == 'Windows':
  1744. # The check for windows is needed because get_cblas_libs uses the
  1745. # same compiler that was used to compile Python and msvc is
  1746. # often not installed when mingw is being used. This rough
  1747. # treatment is not desirable, but windows is tricky.
  1748. info['language'] = 'f77' # XXX: is it generally true?
  1749. # If cblas is given as an option, use those
  1750. cblas_info_obj = cblas_info()
  1751. cblas_opt = cblas_info_obj.get_option_single('cblas_libs', 'libraries')
  1752. cblas_libs = cblas_info_obj.get_libs(cblas_opt, None)
  1753. if cblas_libs:
  1754. info['libraries'] = cblas_libs + blas_libs
  1755. info['define_macros'] = [('HAVE_CBLAS', None)]
  1756. else:
  1757. lib = self.get_cblas_libs(info)
  1758. if lib is not None:
  1759. info['language'] = 'c'
  1760. info['libraries'] = lib
  1761. info['define_macros'] = [('HAVE_CBLAS', None)]
  1762. self.set_info(**info)
  1763. def get_cblas_libs(self, info):
  1764. """ Check whether we can link with CBLAS interface
  1765. This method will search through several combinations of libraries
  1766. to check whether CBLAS is present:
  1767. 1. Libraries in ``info['libraries']``, as is
  1768. 2. As 1. but also explicitly adding ``'cblas'`` as a library
  1769. 3. As 1. but also explicitly adding ``'blas'`` as a library
  1770. 4. Check only library ``'cblas'``
  1771. 5. Check only library ``'blas'``
  1772. Parameters
  1773. ----------
  1774. info : dict
  1775. system information dictionary for compilation and linking
  1776. Returns
  1777. -------
  1778. libraries : list of str or None
  1779. a list of libraries that enables the use of CBLAS interface.
  1780. Returns None if not found or a compilation error occurs.
  1781. Since 1.17 returns a list.
  1782. """
  1783. # primitive cblas check by looking for the header and trying to link
  1784. # cblas or blas
  1785. c = customized_ccompiler()
  1786. tmpdir = tempfile.mkdtemp()
  1787. s = textwrap.dedent("""\
  1788. #include <cblas.h>
  1789. int main(int argc, const char *argv[])
  1790. {
  1791. double a[4] = {1,2,3,4};
  1792. double b[4] = {5,6,7,8};
  1793. return cblas_ddot(4, a, 1, b, 1) > 10;
  1794. }""")
  1795. src = os.path.join(tmpdir, 'source.c')
  1796. try:
  1797. with open(src, 'wt') as f:
  1798. f.write(s)
  1799. try:
  1800. # check we can compile (find headers)
  1801. obj = c.compile([src], output_dir=tmpdir,
  1802. include_dirs=self.get_include_dirs())
  1803. except (distutils.ccompiler.CompileError, distutils.ccompiler.LinkError):
  1804. return None
  1805. # check we can link (find library)
  1806. # some systems have separate cblas and blas libs.
  1807. for libs in [info['libraries'], ['cblas'] + info['libraries'],
  1808. ['blas'] + info['libraries'], ['cblas'], ['blas']]:
  1809. try:
  1810. c.link_executable(obj, os.path.join(tmpdir, "a.out"),
  1811. libraries=libs,
  1812. library_dirs=info['library_dirs'],
  1813. extra_postargs=info.get('extra_link_args', []))
  1814. return libs
  1815. except distutils.ccompiler.LinkError:
  1816. pass
  1817. finally:
  1818. shutil.rmtree(tmpdir)
  1819. return None
  1820. class openblas_info(blas_info):
  1821. section = 'openblas'
  1822. dir_env_var = 'OPENBLAS'
  1823. _lib_names = ['openblas']
  1824. _require_symbols = []
  1825. notfounderror = BlasNotFoundError
  1826. @property
  1827. def symbol_prefix(self):
  1828. try:
  1829. return self.cp.get(self.section, 'symbol_prefix')
  1830. except NoOptionError:
  1831. return ''
  1832. @property
  1833. def symbol_suffix(self):
  1834. try:
  1835. return self.cp.get(self.section, 'symbol_suffix')
  1836. except NoOptionError:
  1837. return ''
  1838. def _calc_info(self):
  1839. c = customized_ccompiler()
  1840. lib_dirs = self.get_lib_dirs()
  1841. # Prefer to use libraries over openblas_libs
  1842. opt = self.get_option_single('openblas_libs', 'libraries')
  1843. openblas_libs = self.get_libs(opt, self._lib_names)
  1844. info = self.check_libs(lib_dirs, openblas_libs, [])
  1845. if c.compiler_type == "msvc" and info is None:
  1846. from numpy.distutils.fcompiler import new_fcompiler
  1847. f = new_fcompiler(c_compiler=c)
  1848. if f and f.compiler_type == 'gnu95':
  1849. # Try gfortran-compatible library files
  1850. info = self.check_msvc_gfortran_libs(lib_dirs, openblas_libs)
  1851. # Skip lapack check, we'd need build_ext to do it
  1852. skip_symbol_check = True
  1853. elif info:
  1854. skip_symbol_check = False
  1855. info['language'] = 'c'
  1856. if info is None:
  1857. return None
  1858. # Add extra info for OpenBLAS
  1859. extra_info = self.calc_extra_info()
  1860. dict_append(info, **extra_info)
  1861. if not (skip_symbol_check or self.check_symbols(info)):
  1862. return None
  1863. info['define_macros'] = [('HAVE_CBLAS', None)]
  1864. if self.symbol_prefix:
  1865. info['define_macros'] += [('BLAS_SYMBOL_PREFIX', self.symbol_prefix)]
  1866. if self.symbol_suffix:
  1867. info['define_macros'] += [('BLAS_SYMBOL_SUFFIX', self.symbol_suffix)]
  1868. return info
  1869. def calc_info(self):
  1870. info = self._calc_info()
  1871. if info is not None:
  1872. self.set_info(**info)
  1873. def check_msvc_gfortran_libs(self, library_dirs, libraries):
  1874. # First, find the full path to each library directory
  1875. library_paths = []
  1876. for library in libraries:
  1877. for library_dir in library_dirs:
  1878. # MinGW static ext will be .a
  1879. fullpath = os.path.join(library_dir, library + '.a')
  1880. if os.path.isfile(fullpath):
  1881. library_paths.append(fullpath)
  1882. break
  1883. else:
  1884. return None
  1885. # Generate numpy.distutils virtual static library file
  1886. basename = self.__class__.__name__
  1887. tmpdir = os.path.join(os.getcwd(), 'build', basename)
  1888. if not os.path.isdir(tmpdir):
  1889. os.makedirs(tmpdir)
  1890. info = {'library_dirs': [tmpdir],
  1891. 'libraries': [basename],
  1892. 'language': 'f77'}
  1893. fake_lib_file = os.path.join(tmpdir, basename + '.fobjects')
  1894. fake_clib_file = os.path.join(tmpdir, basename + '.cobjects')
  1895. with open(fake_lib_file, 'w') as f:
  1896. f.write("\n".join(library_paths))
  1897. with open(fake_clib_file, 'w') as f:
  1898. pass
  1899. return info
  1900. def check_symbols(self, info):
  1901. res = False
  1902. c = customized_ccompiler()
  1903. tmpdir = tempfile.mkdtemp()
  1904. prototypes = "\n".join("void %s%s%s();" % (self.symbol_prefix,
  1905. symbol_name,
  1906. self.symbol_suffix)
  1907. for symbol_name in self._require_symbols)
  1908. calls = "\n".join("%s%s%s();" % (self.symbol_prefix,
  1909. symbol_name,
  1910. self.symbol_suffix)
  1911. for symbol_name in self._require_symbols)
  1912. s = textwrap.dedent("""\
  1913. %(prototypes)s
  1914. int main(int argc, const char *argv[])
  1915. {
  1916. %(calls)s
  1917. return 0;
  1918. }""") % dict(prototypes=prototypes, calls=calls)
  1919. src = os.path.join(tmpdir, 'source.c')
  1920. out = os.path.join(tmpdir, 'a.out')
  1921. # Add the additional "extra" arguments
  1922. try:
  1923. extra_args = info['extra_link_args']
  1924. except Exception:
  1925. extra_args = []
  1926. try:
  1927. with open(src, 'wt') as f:
  1928. f.write(s)
  1929. obj = c.compile([src], output_dir=tmpdir)
  1930. try:
  1931. c.link_executable(obj, out, libraries=info['libraries'],
  1932. library_dirs=info['library_dirs'],
  1933. extra_postargs=extra_args)
  1934. res = True
  1935. except distutils.ccompiler.LinkError:
  1936. res = False
  1937. finally:
  1938. shutil.rmtree(tmpdir)
  1939. return res
  1940. class openblas_lapack_info(openblas_info):
  1941. section = 'openblas'
  1942. dir_env_var = 'OPENBLAS'
  1943. _lib_names = ['openblas']
  1944. _require_symbols = ['zungqr_']
  1945. notfounderror = BlasNotFoundError
  1946. class openblas_clapack_info(openblas_lapack_info):
  1947. _lib_names = ['openblas', 'lapack']
  1948. class openblas_ilp64_info(openblas_info):
  1949. section = 'openblas_ilp64'
  1950. dir_env_var = 'OPENBLAS_ILP64'
  1951. _lib_names = ['openblas64']
  1952. _require_symbols = ['dgemm_', 'cblas_dgemm']
  1953. notfounderror = BlasILP64NotFoundError
  1954. def _calc_info(self):
  1955. info = super()._calc_info()
  1956. if info is not None:
  1957. info['define_macros'] += [('HAVE_BLAS_ILP64', None)]
  1958. return info
  1959. class openblas_ilp64_lapack_info(openblas_ilp64_info):
  1960. _require_symbols = ['dgemm_', 'cblas_dgemm', 'zungqr_', 'LAPACKE_zungqr']
  1961. def _calc_info(self):
  1962. info = super()._calc_info()
  1963. if info:
  1964. info['define_macros'] += [('HAVE_LAPACKE', None)]
  1965. return info
  1966. class openblas64__info(openblas_ilp64_info):
  1967. # ILP64 Openblas, with default symbol suffix
  1968. section = 'openblas64_'
  1969. dir_env_var = 'OPENBLAS64_'
  1970. _lib_names = ['openblas64_']
  1971. symbol_suffix = '64_'
  1972. symbol_prefix = ''
  1973. class openblas64__lapack_info(openblas_ilp64_lapack_info, openblas64__info):
  1974. pass
  1975. class blis_info(blas_info):
  1976. section = 'blis'
  1977. dir_env_var = 'BLIS'
  1978. _lib_names = ['blis']
  1979. notfounderror = BlasNotFoundError
  1980. def calc_info(self):
  1981. lib_dirs = self.get_lib_dirs()
  1982. opt = self.get_option_single('blis_libs', 'libraries')
  1983. blis_libs = self.get_libs(opt, self._lib_names)
  1984. info = self.check_libs2(lib_dirs, blis_libs, [])
  1985. if info is None:
  1986. return
  1987. # Add include dirs
  1988. incl_dirs = self.get_include_dirs()
  1989. dict_append(info,
  1990. language='c',
  1991. define_macros=[('HAVE_CBLAS', None)],
  1992. include_dirs=incl_dirs)
  1993. self.set_info(**info)
  1994. class flame_info(system_info):
  1995. """ Usage of libflame for LAPACK operations
  1996. This requires libflame to be compiled with lapack wrappers:
  1997. ./configure --enable-lapack2flame ...
  1998. Be aware that libflame 5.1.0 has some missing names in the shared library, so
  1999. if you have problems, try the static flame library.
  2000. """
  2001. section = 'flame'
  2002. _lib_names = ['flame']
  2003. notfounderror = FlameNotFoundError
  2004. def check_embedded_lapack(self, info):
  2005. """ libflame does not necessarily have a wrapper for fortran LAPACK, we need to check """
  2006. c = customized_ccompiler()
  2007. tmpdir = tempfile.mkdtemp()
  2008. s = textwrap.dedent("""\
  2009. void zungqr_();
  2010. int main(int argc, const char *argv[])
  2011. {
  2012. zungqr_();
  2013. return 0;
  2014. }""")
  2015. src = os.path.join(tmpdir, 'source.c')
  2016. out = os.path.join(tmpdir, 'a.out')
  2017. # Add the additional "extra" arguments
  2018. extra_args = info.get('extra_link_args', [])
  2019. try:
  2020. with open(src, 'wt') as f:
  2021. f.write(s)
  2022. obj = c.compile([src], output_dir=tmpdir)
  2023. try:
  2024. c.link_executable(obj, out, libraries=info['libraries'],
  2025. library_dirs=info['library_dirs'],
  2026. extra_postargs=extra_args)
  2027. return True
  2028. except distutils.ccompiler.LinkError:
  2029. return False
  2030. finally:
  2031. shutil.rmtree(tmpdir)
  2032. def calc_info(self):
  2033. lib_dirs = self.get_lib_dirs()
  2034. flame_libs = self.get_libs('libraries', self._lib_names)
  2035. info = self.check_libs2(lib_dirs, flame_libs, [])
  2036. if info is None:
  2037. return
  2038. if self.check_embedded_lapack(info):
  2039. # check if the user has supplied all information required
  2040. self.set_info(**info)
  2041. else:
  2042. # Try and get the BLAS lib to see if we can get it to work
  2043. blas_info = get_info('blas_opt')
  2044. if not blas_info:
  2045. # since we already failed once, this ain't going to work either
  2046. return
  2047. # Now we need to merge the two dictionaries
  2048. for key in blas_info:
  2049. if isinstance(blas_info[key], list):
  2050. info[key] = info.get(key, []) + blas_info[key]
  2051. elif isinstance(blas_info[key], tuple):
  2052. info[key] = info.get(key, ()) + blas_info[key]
  2053. else:
  2054. info[key] = info.get(key, '') + blas_info[key]
  2055. # Now check again
  2056. if self.check_embedded_lapack(info):
  2057. self.set_info(**info)
  2058. class accelerate_info(system_info):
  2059. section = 'accelerate'
  2060. _lib_names = ['accelerate', 'veclib']
  2061. notfounderror = BlasNotFoundError
  2062. def calc_info(self):
  2063. # Make possible to enable/disable from config file/env var
  2064. libraries = os.environ.get('ACCELERATE')
  2065. if libraries:
  2066. libraries = [libraries]
  2067. else:
  2068. libraries = self.get_libs('libraries', self._lib_names)
  2069. libraries = [lib.strip().lower() for lib in libraries]
  2070. if (sys.platform == 'darwin' and
  2071. not os.getenv('_PYTHON_HOST_PLATFORM', None)):
  2072. # Use the system BLAS from Accelerate or vecLib under OSX
  2073. args = []
  2074. link_args = []
  2075. if get_platform()[-4:] == 'i386' or 'intel' in get_platform() or \
  2076. 'x86_64' in get_platform() or \
  2077. 'i386' in platform.platform():
  2078. intel = 1
  2079. else:
  2080. intel = 0
  2081. if (os.path.exists('/System/Library/Frameworks'
  2082. '/Accelerate.framework/') and
  2083. 'accelerate' in libraries):
  2084. if intel:
  2085. args.extend(['-msse3'])
  2086. args.extend([
  2087. '-I/System/Library/Frameworks/vecLib.framework/Headers'])
  2088. link_args.extend(['-Wl,-framework', '-Wl,Accelerate'])
  2089. elif (os.path.exists('/System/Library/Frameworks'
  2090. '/vecLib.framework/') and
  2091. 'veclib' in libraries):
  2092. if intel:
  2093. args.extend(['-msse3'])
  2094. args.extend([
  2095. '-I/System/Library/Frameworks/vecLib.framework/Headers'])
  2096. link_args.extend(['-Wl,-framework', '-Wl,vecLib'])
  2097. if args:
  2098. self.set_info(extra_compile_args=args,
  2099. extra_link_args=link_args,
  2100. define_macros=[('NO_ATLAS_INFO', 3),
  2101. ('HAVE_CBLAS', None)])
  2102. return
  2103. class blas_src_info(system_info):
  2104. section = 'blas_src'
  2105. dir_env_var = 'BLAS_SRC'
  2106. notfounderror = BlasSrcNotFoundError
  2107. def get_paths(self, section, key):
  2108. pre_dirs = system_info.get_paths(self, section, key)
  2109. dirs = []
  2110. for d in pre_dirs:
  2111. dirs.extend([d] + self.combine_paths(d, ['blas']))
  2112. return [d for d in dirs if os.path.isdir(d)]
  2113. def calc_info(self):
  2114. src_dirs = self.get_src_dirs()
  2115. src_dir = ''
  2116. for d in src_dirs:
  2117. if os.path.isfile(os.path.join(d, 'daxpy.f')):
  2118. src_dir = d
  2119. break
  2120. if not src_dir:
  2121. #XXX: Get sources from netlib. May be ask first.
  2122. return
  2123. blas1 = '''
  2124. caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot
  2125. dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2
  2126. srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg
  2127. dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax
  2128. snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap
  2129. scabs1
  2130. '''
  2131. blas2 = '''
  2132. cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv
  2133. chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv
  2134. dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv
  2135. sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger
  2136. stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc
  2137. zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2
  2138. ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv
  2139. '''
  2140. blas3 = '''
  2141. cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k
  2142. dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm
  2143. ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm
  2144. '''
  2145. sources = [os.path.join(src_dir, f + '.f') \
  2146. for f in (blas1 + blas2 + blas3).split()]
  2147. #XXX: should we check here actual existence of source files?
  2148. sources = [f for f in sources if os.path.isfile(f)]
  2149. info = {'sources': sources, 'language': 'f77'}
  2150. self.set_info(**info)
  2151. class x11_info(system_info):
  2152. section = 'x11'
  2153. notfounderror = X11NotFoundError
  2154. _lib_names = ['X11']
  2155. def __init__(self):
  2156. system_info.__init__(self,
  2157. default_lib_dirs=default_x11_lib_dirs,
  2158. default_include_dirs=default_x11_include_dirs)
  2159. def calc_info(self):
  2160. if sys.platform in ['win32']:
  2161. return
  2162. lib_dirs = self.get_lib_dirs()
  2163. include_dirs = self.get_include_dirs()
  2164. opt = self.get_option_single('x11_libs', 'libraries')
  2165. x11_libs = self.get_libs(opt, self._lib_names)
  2166. info = self.check_libs(lib_dirs, x11_libs, [])
  2167. if info is None:
  2168. return
  2169. inc_dir = None
  2170. for d in include_dirs:
  2171. if self.combine_paths(d, 'X11/X.h'):
  2172. inc_dir = d
  2173. break
  2174. if inc_dir is not None:
  2175. dict_append(info, include_dirs=[inc_dir])
  2176. self.set_info(**info)
  2177. class _numpy_info(system_info):
  2178. section = 'Numeric'
  2179. modulename = 'Numeric'
  2180. notfounderror = NumericNotFoundError
  2181. def __init__(self):
  2182. include_dirs = []
  2183. try:
  2184. module = __import__(self.modulename)
  2185. prefix = []
  2186. for name in module.__file__.split(os.sep):
  2187. if name == 'lib':
  2188. break
  2189. prefix.append(name)
  2190. # Ask numpy for its own include path before attempting
  2191. # anything else
  2192. try:
  2193. include_dirs.append(getattr(module, 'get_include')())
  2194. except AttributeError:
  2195. pass
  2196. include_dirs.append(sysconfig.get_path('include'))
  2197. except ImportError:
  2198. pass
  2199. py_incl_dir = sysconfig.get_path('include')
  2200. include_dirs.append(py_incl_dir)
  2201. py_pincl_dir = sysconfig.get_path('platinclude')
  2202. if py_pincl_dir not in include_dirs:
  2203. include_dirs.append(py_pincl_dir)
  2204. for d in default_include_dirs:
  2205. d = os.path.join(d, os.path.basename(py_incl_dir))
  2206. if d not in include_dirs:
  2207. include_dirs.append(d)
  2208. system_info.__init__(self,
  2209. default_lib_dirs=[],
  2210. default_include_dirs=include_dirs)
  2211. def calc_info(self):
  2212. try:
  2213. module = __import__(self.modulename)
  2214. except ImportError:
  2215. return
  2216. info = {}
  2217. macros = []
  2218. for v in ['__version__', 'version']:
  2219. vrs = getattr(module, v, None)
  2220. if vrs is None:
  2221. continue
  2222. macros = [(self.modulename.upper() + '_VERSION',
  2223. _c_string_literal(vrs)),
  2224. (self.modulename.upper(), None)]
  2225. break
  2226. dict_append(info, define_macros=macros)
  2227. include_dirs = self.get_include_dirs()
  2228. inc_dir = None
  2229. for d in include_dirs:
  2230. if self.combine_paths(d,
  2231. os.path.join(self.modulename,
  2232. 'arrayobject.h')):
  2233. inc_dir = d
  2234. break
  2235. if inc_dir is not None:
  2236. dict_append(info, include_dirs=[inc_dir])
  2237. if info:
  2238. self.set_info(**info)
  2239. return
  2240. class numarray_info(_numpy_info):
  2241. section = 'numarray'
  2242. modulename = 'numarray'
  2243. class Numeric_info(_numpy_info):
  2244. section = 'Numeric'
  2245. modulename = 'Numeric'
  2246. class numpy_info(_numpy_info):
  2247. section = 'numpy'
  2248. modulename = 'numpy'
  2249. class numerix_info(system_info):
  2250. section = 'numerix'
  2251. def calc_info(self):
  2252. which = None, None
  2253. if os.getenv("NUMERIX"):
  2254. which = os.getenv("NUMERIX"), "environment var"
  2255. # If all the above fail, default to numpy.
  2256. if which[0] is None:
  2257. which = "numpy", "defaulted"
  2258. try:
  2259. import numpy # noqa: F401
  2260. which = "numpy", "defaulted"
  2261. except ImportError as e:
  2262. msg1 = str(e)
  2263. try:
  2264. import Numeric # noqa: F401
  2265. which = "numeric", "defaulted"
  2266. except ImportError as e:
  2267. msg2 = str(e)
  2268. try:
  2269. import numarray # noqa: F401
  2270. which = "numarray", "defaulted"
  2271. except ImportError as e:
  2272. msg3 = str(e)
  2273. log.info(msg1)
  2274. log.info(msg2)
  2275. log.info(msg3)
  2276. which = which[0].strip().lower(), which[1]
  2277. if which[0] not in ["numeric", "numarray", "numpy"]:
  2278. raise ValueError("numerix selector must be either 'Numeric' "
  2279. "or 'numarray' or 'numpy' but the value obtained"
  2280. " from the %s was '%s'." % (which[1], which[0]))
  2281. os.environ['NUMERIX'] = which[0]
  2282. self.set_info(**get_info(which[0]))
  2283. class f2py_info(system_info):
  2284. def calc_info(self):
  2285. try:
  2286. import numpy.f2py as f2py
  2287. except ImportError:
  2288. return
  2289. f2py_dir = os.path.join(os.path.dirname(f2py.__file__), 'src')
  2290. self.set_info(sources=[os.path.join(f2py_dir, 'fortranobject.c')],
  2291. include_dirs=[f2py_dir])
  2292. return
  2293. class boost_python_info(system_info):
  2294. section = 'boost_python'
  2295. dir_env_var = 'BOOST'
  2296. def get_paths(self, section, key):
  2297. pre_dirs = system_info.get_paths(self, section, key)
  2298. dirs = []
  2299. for d in pre_dirs:
  2300. dirs.extend([d] + self.combine_paths(d, ['boost*']))
  2301. return [d for d in dirs if os.path.isdir(d)]
  2302. def calc_info(self):
  2303. src_dirs = self.get_src_dirs()
  2304. src_dir = ''
  2305. for d in src_dirs:
  2306. if os.path.isfile(os.path.join(d, 'libs', 'python', 'src',
  2307. 'module.cpp')):
  2308. src_dir = d
  2309. break
  2310. if not src_dir:
  2311. return
  2312. py_incl_dirs = [sysconfig.get_path('include')]
  2313. py_pincl_dir = sysconfig.get_path('platinclude')
  2314. if py_pincl_dir not in py_incl_dirs:
  2315. py_incl_dirs.append(py_pincl_dir)
  2316. srcs_dir = os.path.join(src_dir, 'libs', 'python', 'src')
  2317. bpl_srcs = glob(os.path.join(srcs_dir, '*.cpp'))
  2318. bpl_srcs += glob(os.path.join(srcs_dir, '*', '*.cpp'))
  2319. info = {'libraries': [('boost_python_src',
  2320. {'include_dirs': [src_dir] + py_incl_dirs,
  2321. 'sources':bpl_srcs}
  2322. )],
  2323. 'include_dirs': [src_dir],
  2324. }
  2325. if info:
  2326. self.set_info(**info)
  2327. return
  2328. class agg2_info(system_info):
  2329. section = 'agg2'
  2330. dir_env_var = 'AGG2'
  2331. def get_paths(self, section, key):
  2332. pre_dirs = system_info.get_paths(self, section, key)
  2333. dirs = []
  2334. for d in pre_dirs:
  2335. dirs.extend([d] + self.combine_paths(d, ['agg2*']))
  2336. return [d for d in dirs if os.path.isdir(d)]
  2337. def calc_info(self):
  2338. src_dirs = self.get_src_dirs()
  2339. src_dir = ''
  2340. for d in src_dirs:
  2341. if os.path.isfile(os.path.join(d, 'src', 'agg_affine_matrix.cpp')):
  2342. src_dir = d
  2343. break
  2344. if not src_dir:
  2345. return
  2346. if sys.platform == 'win32':
  2347. agg2_srcs = glob(os.path.join(src_dir, 'src', 'platform',
  2348. 'win32', 'agg_win32_bmp.cpp'))
  2349. else:
  2350. agg2_srcs = glob(os.path.join(src_dir, 'src', '*.cpp'))
  2351. agg2_srcs += [os.path.join(src_dir, 'src', 'platform',
  2352. 'X11',
  2353. 'agg_platform_support.cpp')]
  2354. info = {'libraries':
  2355. [('agg2_src',
  2356. {'sources': agg2_srcs,
  2357. 'include_dirs': [os.path.join(src_dir, 'include')],
  2358. }
  2359. )],
  2360. 'include_dirs': [os.path.join(src_dir, 'include')],
  2361. }
  2362. if info:
  2363. self.set_info(**info)
  2364. return
  2365. class _pkg_config_info(system_info):
  2366. section = None
  2367. config_env_var = 'PKG_CONFIG'
  2368. default_config_exe = 'pkg-config'
  2369. append_config_exe = ''
  2370. version_macro_name = None
  2371. release_macro_name = None
  2372. version_flag = '--modversion'
  2373. cflags_flag = '--cflags'
  2374. def get_config_exe(self):
  2375. if self.config_env_var in os.environ:
  2376. return os.environ[self.config_env_var]
  2377. return self.default_config_exe
  2378. def get_config_output(self, config_exe, option):
  2379. cmd = config_exe + ' ' + self.append_config_exe + ' ' + option
  2380. try:
  2381. o = subprocess.check_output(cmd)
  2382. except (OSError, subprocess.CalledProcessError):
  2383. pass
  2384. else:
  2385. o = filepath_from_subprocess_output(o)
  2386. return o
  2387. def calc_info(self):
  2388. config_exe = find_executable(self.get_config_exe())
  2389. if not config_exe:
  2390. log.warn('File not found: %s. Cannot determine %s info.' \
  2391. % (config_exe, self.section))
  2392. return
  2393. info = {}
  2394. macros = []
  2395. libraries = []
  2396. library_dirs = []
  2397. include_dirs = []
  2398. extra_link_args = []
  2399. extra_compile_args = []
  2400. version = self.get_config_output(config_exe, self.version_flag)
  2401. if version:
  2402. macros.append((self.__class__.__name__.split('.')[-1].upper(),
  2403. _c_string_literal(version)))
  2404. if self.version_macro_name:
  2405. macros.append((self.version_macro_name + '_%s'
  2406. % (version.replace('.', '_')), None))
  2407. if self.release_macro_name:
  2408. release = self.get_config_output(config_exe, '--release')
  2409. if release:
  2410. macros.append((self.release_macro_name + '_%s'
  2411. % (release.replace('.', '_')), None))
  2412. opts = self.get_config_output(config_exe, '--libs')
  2413. if opts:
  2414. for opt in opts.split():
  2415. if opt[:2] == '-l':
  2416. libraries.append(opt[2:])
  2417. elif opt[:2] == '-L':
  2418. library_dirs.append(opt[2:])
  2419. else:
  2420. extra_link_args.append(opt)
  2421. opts = self.get_config_output(config_exe, self.cflags_flag)
  2422. if opts:
  2423. for opt in opts.split():
  2424. if opt[:2] == '-I':
  2425. include_dirs.append(opt[2:])
  2426. elif opt[:2] == '-D':
  2427. if '=' in opt:
  2428. n, v = opt[2:].split('=')
  2429. macros.append((n, v))
  2430. else:
  2431. macros.append((opt[2:], None))
  2432. else:
  2433. extra_compile_args.append(opt)
  2434. if macros:
  2435. dict_append(info, define_macros=macros)
  2436. if libraries:
  2437. dict_append(info, libraries=libraries)
  2438. if library_dirs:
  2439. dict_append(info, library_dirs=library_dirs)
  2440. if include_dirs:
  2441. dict_append(info, include_dirs=include_dirs)
  2442. if extra_link_args:
  2443. dict_append(info, extra_link_args=extra_link_args)
  2444. if extra_compile_args:
  2445. dict_append(info, extra_compile_args=extra_compile_args)
  2446. if info:
  2447. self.set_info(**info)
  2448. return
  2449. class wx_info(_pkg_config_info):
  2450. section = 'wx'
  2451. config_env_var = 'WX_CONFIG'
  2452. default_config_exe = 'wx-config'
  2453. append_config_exe = ''
  2454. version_macro_name = 'WX_VERSION'
  2455. release_macro_name = 'WX_RELEASE'
  2456. version_flag = '--version'
  2457. cflags_flag = '--cxxflags'
  2458. class gdk_pixbuf_xlib_2_info(_pkg_config_info):
  2459. section = 'gdk_pixbuf_xlib_2'
  2460. append_config_exe = 'gdk-pixbuf-xlib-2.0'
  2461. version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'
  2462. class gdk_pixbuf_2_info(_pkg_config_info):
  2463. section = 'gdk_pixbuf_2'
  2464. append_config_exe = 'gdk-pixbuf-2.0'
  2465. version_macro_name = 'GDK_PIXBUF_VERSION'
  2466. class gdk_x11_2_info(_pkg_config_info):
  2467. section = 'gdk_x11_2'
  2468. append_config_exe = 'gdk-x11-2.0'
  2469. version_macro_name = 'GDK_X11_VERSION'
  2470. class gdk_2_info(_pkg_config_info):
  2471. section = 'gdk_2'
  2472. append_config_exe = 'gdk-2.0'
  2473. version_macro_name = 'GDK_VERSION'
  2474. class gdk_info(_pkg_config_info):
  2475. section = 'gdk'
  2476. append_config_exe = 'gdk'
  2477. version_macro_name = 'GDK_VERSION'
  2478. class gtkp_x11_2_info(_pkg_config_info):
  2479. section = 'gtkp_x11_2'
  2480. append_config_exe = 'gtk+-x11-2.0'
  2481. version_macro_name = 'GTK_X11_VERSION'
  2482. class gtkp_2_info(_pkg_config_info):
  2483. section = 'gtkp_2'
  2484. append_config_exe = 'gtk+-2.0'
  2485. version_macro_name = 'GTK_VERSION'
  2486. class xft_info(_pkg_config_info):
  2487. section = 'xft'
  2488. append_config_exe = 'xft'
  2489. version_macro_name = 'XFT_VERSION'
  2490. class freetype2_info(_pkg_config_info):
  2491. section = 'freetype2'
  2492. append_config_exe = 'freetype2'
  2493. version_macro_name = 'FREETYPE2_VERSION'
  2494. class amd_info(system_info):
  2495. section = 'amd'
  2496. dir_env_var = 'AMD'
  2497. _lib_names = ['amd']
  2498. def calc_info(self):
  2499. lib_dirs = self.get_lib_dirs()
  2500. opt = self.get_option_single('amd_libs', 'libraries')
  2501. amd_libs = self.get_libs(opt, self._lib_names)
  2502. info = self.check_libs(lib_dirs, amd_libs, [])
  2503. if info is None:
  2504. return
  2505. include_dirs = self.get_include_dirs()
  2506. inc_dir = None
  2507. for d in include_dirs:
  2508. p = self.combine_paths(d, 'amd.h')
  2509. if p:
  2510. inc_dir = os.path.dirname(p[0])
  2511. break
  2512. if inc_dir is not None:
  2513. dict_append(info, include_dirs=[inc_dir],
  2514. define_macros=[('SCIPY_AMD_H', None)],
  2515. swig_opts=['-I' + inc_dir])
  2516. self.set_info(**info)
  2517. return
  2518. class umfpack_info(system_info):
  2519. section = 'umfpack'
  2520. dir_env_var = 'UMFPACK'
  2521. notfounderror = UmfpackNotFoundError
  2522. _lib_names = ['umfpack']
  2523. def calc_info(self):
  2524. lib_dirs = self.get_lib_dirs()
  2525. opt = self.get_option_single('umfpack_libs', 'libraries')
  2526. umfpack_libs = self.get_libs(opt, self._lib_names)
  2527. info = self.check_libs(lib_dirs, umfpack_libs, [])
  2528. if info is None:
  2529. return
  2530. include_dirs = self.get_include_dirs()
  2531. inc_dir = None
  2532. for d in include_dirs:
  2533. p = self.combine_paths(d, ['', 'umfpack'], 'umfpack.h')
  2534. if p:
  2535. inc_dir = os.path.dirname(p[0])
  2536. break
  2537. if inc_dir is not None:
  2538. dict_append(info, include_dirs=[inc_dir],
  2539. define_macros=[('SCIPY_UMFPACK_H', None)],
  2540. swig_opts=['-I' + inc_dir])
  2541. dict_append(info, **get_info('amd'))
  2542. self.set_info(**info)
  2543. return
  2544. def combine_paths(*args, **kws):
  2545. """ Return a list of existing paths composed by all combinations of
  2546. items from arguments.
  2547. """
  2548. r = []
  2549. for a in args:
  2550. if not a:
  2551. continue
  2552. if is_string(a):
  2553. a = [a]
  2554. r.append(a)
  2555. args = r
  2556. if not args:
  2557. return []
  2558. if len(args) == 1:
  2559. result = reduce(lambda a, b: a + b, map(glob, args[0]), [])
  2560. elif len(args) == 2:
  2561. result = []
  2562. for a0 in args[0]:
  2563. for a1 in args[1]:
  2564. result.extend(glob(os.path.join(a0, a1)))
  2565. else:
  2566. result = combine_paths(*(combine_paths(args[0], args[1]) + args[2:]))
  2567. log.debug('(paths: %s)', ','.join(result))
  2568. return result
  2569. language_map = {'c': 0, 'c++': 1, 'f77': 2, 'f90': 3}
  2570. inv_language_map = {0: 'c', 1: 'c++', 2: 'f77', 3: 'f90'}
  2571. def dict_append(d, **kws):
  2572. languages = []
  2573. for k, v in kws.items():
  2574. if k == 'language':
  2575. languages.append(v)
  2576. continue
  2577. if k in d:
  2578. if k in ['library_dirs', 'include_dirs',
  2579. 'extra_compile_args', 'extra_link_args',
  2580. 'runtime_library_dirs', 'define_macros']:
  2581. [d[k].append(vv) for vv in v if vv not in d[k]]
  2582. else:
  2583. d[k].extend(v)
  2584. else:
  2585. d[k] = v
  2586. if languages:
  2587. l = inv_language_map[max([language_map.get(l, 0) for l in languages])]
  2588. d['language'] = l
  2589. return
  2590. def parseCmdLine(argv=(None,)):
  2591. import optparse
  2592. parser = optparse.OptionParser("usage: %prog [-v] [info objs]")
  2593. parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
  2594. default=False,
  2595. help='be verbose and print more messages')
  2596. opts, args = parser.parse_args(args=argv[1:])
  2597. return opts, args
  2598. def show_all(argv=None):
  2599. import inspect
  2600. if argv is None:
  2601. argv = sys.argv
  2602. opts, args = parseCmdLine(argv)
  2603. if opts.verbose:
  2604. log.set_threshold(log.DEBUG)
  2605. else:
  2606. log.set_threshold(log.INFO)
  2607. show_only = []
  2608. for n in args:
  2609. if n[-5:] != '_info':
  2610. n = n + '_info'
  2611. show_only.append(n)
  2612. show_all = not show_only
  2613. _gdict_ = globals().copy()
  2614. for name, c in _gdict_.items():
  2615. if not inspect.isclass(c):
  2616. continue
  2617. if not issubclass(c, system_info) or c is system_info:
  2618. continue
  2619. if not show_all:
  2620. if name not in show_only:
  2621. continue
  2622. del show_only[show_only.index(name)]
  2623. conf = c()
  2624. conf.verbosity = 2
  2625. # FIXME: r not used
  2626. r = conf.get_info()
  2627. if show_only:
  2628. log.info('Info classes not defined: %s', ','.join(show_only))
  2629. if __name__ == "__main__":
  2630. show_all()