Skip to content

Commit 462a31b

Browse files
committed
Python 2 testing
1 parent c873776 commit 462a31b

File tree

7 files changed

+31
-14
lines changed

7 files changed

+31
-14
lines changed

.appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ install:
2424
- conda info -a
2525
- conda install gtest cmake -c conda-forge
2626
- conda install xtensor==0.8.3 pytest numpy pybind11==2.1.1 -c conda-forge
27-
- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -DBUILD_TESTS=ON .
27+
- "set PYTHONHOME=%MINICONDA%"
28+
- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D BUILD_TESTS=ON -D PYTHON_EXECUTABLE=%MINICONDA%\\python.exe .
2829
- nmake test_xtensor_python
2930
- nmake install
3031

.travis.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@ matrix:
88
- ubuntu-toolchain-r-test
99
packages:
1010
- g++-4.9
11-
env: COMPILER=gcc GCC=4.9
11+
env: COMPILER=gcc GCC=4.9 PY=3
1212
- os: linux
1313
addons:
1414
apt:
1515
sources:
1616
- ubuntu-toolchain-r-test
1717
packages:
1818
- g++-5
19-
env: COMPILER=gcc GCC=5
19+
env: COMPILER=gcc GCC=5 PY=3
20+
- os: linux
21+
addons:
22+
apt:
23+
sources:
24+
- ubuntu-toolchain-r-test
25+
packages:
26+
- g++-5
27+
env: COMPILER=gcc GCC=5 PY=2
2028
- os: linux
2129
addons:
2230
apt:
@@ -25,7 +33,7 @@ matrix:
2533
- llvm-toolchain-precise-3.6
2634
packages:
2735
- clang-3.6
28-
env: COMPILER=clang CLANG=3.6
36+
env: COMPILER=clang CLANG=3.6 PY=3
2937
- os: linux
3038
addons:
3139
apt:
@@ -34,7 +42,7 @@ matrix:
3442
- llvm-toolchain-precise-3.7
3543
packages:
3644
- clang-3.7
37-
env: COMPILER=clang CLANG=3.7
45+
env: COMPILER=clang CLANG=3.7 PY=3
3846
- os: linux
3947
addons:
4048
apt:
@@ -43,10 +51,11 @@ matrix:
4351
- llvm-toolchain-precise-3.8
4452
packages:
4553
- clang-3.8
46-
env: COMPILER=clang CLANG=3.8
54+
env: COMPILER=clang CLANG=3.8 PY=3
4755
- os: osx
4856
osx_image: xcode8
4957
compiler: clang
58+
env: PY=3
5059
env:
5160
global:
5261
- MINCONDA_VERSION="latest"
@@ -73,7 +82,11 @@ install:
7382
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
7483
MINCONDA_OS=$MINCONDA_OSX;
7584
fi
76-
- wget "http://repo.continuum.io/miniconda/Miniconda3-$MINCONDA_VERSION-$MINCONDA_OS.sh" -O miniconda.sh;
85+
- if [[ "$PY" == "3" ]]; then
86+
wget "http://repo.continuum.io/miniconda/Miniconda3-$MINCONDA_VERSION-$MINCONDA_OS.sh" -O miniconda.sh;
87+
else
88+
wget "http://repo.continuum.io/miniconda/Miniconda2-$MINCONDA_VERSION-$MINCONDA_OS.sh" -O miniconda.sh;
89+
fi
7790
- bash miniconda.sh -b -p $HOME/miniconda
7891
- export PATH="$HOME/miniconda/bin:$PATH"
7992
- hash -r
@@ -86,7 +99,7 @@ install:
8699
- conda env create -f ./test-environment.yml
87100
- source activate test-xtensor-python
88101
- cd ..
89-
- cmake -DBUILD_TESTS=ON -D CMAKE_INSTALL_PREFIX=$HOME/miniconda .
102+
- cmake -D BUILD_TESTS=ON -D CMAKE_INSTALL_PREFIX=$HOME/miniconda .
90103
- make -j2 test_xtensor_python
91104
- make install
92105

docs/source/basic_usage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Example 1: Use an algorithm of the C++ library on a numpy array inplace
2929
3030
PYBIND11_PLUGIN(xtensor_python_test)
3131
{
32-
import_array() //this is actually a macro
32+
import_numpy() //this is actually a macro
3333
pybind11::module m("xtensor_python_test", "Test module for xtensor python bindings");
3434
3535
m.def("sum_of_sines", sum_of_sines,
@@ -80,7 +80,7 @@ Example 2: Create a universal function from a C++ scalar function
8080
8181
PYBIND11_PLUGIN(xtensor_python_test)
8282
{
83-
import_array()
83+
import_numpy()
8484
py::module m("xtensor_python_test", "Test module for xtensor python bindings");
8585
8686
m.def("vectorized_func", xt::pyvectorize(scalar_func), "");

docs/source/numpy_capi.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ When writing an extension module that is self-contained in a single file, its au
1717
points:
1818

1919
- ``FORCE_IMPORT_ARRAY`` must be defined before including any header of ``xtensor-python``.
20-
- ``import_array()`` must be called in the function initializing the module.
20+
- ``import_numpy()`` must be called in the function initializing the module.
2121

2222
Thus the basic skeleton of the module looks like:
2323

@@ -29,7 +29,7 @@ Thus the basic skeleton of the module looks like:
2929
3030
PYBIND11_PLUGIN(plugin_name)
3131
{
32-
import_array()
32+
import_numpy()
3333
pybind11::module m(//...
3434
//...
3535
return m.ptr();

include/xtensor-python/pycontainer.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
#define PY_ARRAY_UNIQUE_SYMBOL xtensor_python_ARRAY_API
2525
#endif
2626
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
27+
2728
#include "numpy/arrayobject.h"
2829

2930
#include "xtensor/xcontainer.hpp"
3031

32+
#define import_numpy() { if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); } }
33+
3134
namespace xt
3235
{
3336

test/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main(int argc, char* argv[])
2020
{
2121
// Initialize all the things (google-test and Python interpreter)
2222
Py_Initialize();
23-
import_array()
23+
import_numpy()
2424
::testing::InitGoogleTest(&argc, argv);
2525

2626
// Run test suite

test_python/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int add(int i, int j)
5151

5252
PYBIND11_PLUGIN(xtensor_python_test)
5353
{
54-
import_array()
54+
import_numpy()
5555
py::module m("xtensor_python_test", "Test module for xtensor python bindings");
5656

5757
m.def("example1", example1);

0 commit comments

Comments
 (0)