system_info.py 108 KB

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