]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/config/numpy.py
2 # Copyright (c) 2016 Stefan Seefeld
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE_1_0.txt or copy at
7 # http://www.boost.org/LICENSE_1_0.txt)
10 from contextlib
import contextmanager
14 save_cpppath
= context
.env
.get('CPPPATH', [])
15 save_libs
= context
.env
.get('LIBS', [])
17 context
.env
.Replace(LIBS
=save_libs
)
18 context
.env
.Replace(CPPPATH
=save_cpppath
)
21 def add_options(vars):
28 numpy_source_file
= r
"""
29 // If defined, enforces linking againg PythonXXd.lib, which
30 // is usually not included in Python environments.
33 #include "numpy/arrayobject.h"
35 #if PY_VERSION_HEX >= 0x03000000
36 void *initialize() { import_array();}
38 void initialize() { import_array();}
53 PyObject * a = PyArray_SimpleNew(1, &dims, NPY_INT);
66 def check_python(cmd
):
68 return True, subprocess
.check_output([python
, '-c', cmd
]).strip()
69 except subprocess
.CalledProcessError
as e
:
72 context
.Message('Checking for NumPy...')
74 python
= context
.env
['PYTHON']
75 result
, numpy_incpath
= check_python('import numpy; print(numpy.get_include())')
77 context
.env
.AppendUnique(CPPPATH
=numpy_incpath
)
78 context
.env
.AppendUnique(LIBS
=context
.env
['PYTHONLIBS'])
79 result
, output
= context
.TryRun(numpy_source_file
,'.cpp')
83 context
.env
['NUMPY'] = True
84 context
.env
['NUMPY_CPPPATH'] = numpy_incpath