From e30f209e3b19310c2f1bb41f5d9a6c40a43fb7e4 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Fri, 7 Apr 2017 22:19:50 +0200 Subject: [PATCH 01/23] Dockerfile for ubuntu/Python2 --- Dockerfile.ubuntu | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Dockerfile.ubuntu diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu new file mode 100644 index 0000000..369bece --- /dev/null +++ b/Dockerfile.ubuntu @@ -0,0 +1,11 @@ +FROM ubuntu:16.04 +RUN apt-get update && apt-get install -y libboost-all-dev python-dev git cmake g++ gdb python-dbg libboost-dbg +RUN mkdir /work +VOLUME /work/src +WORKDIR /work +RUN git clone https://github.com/TNG/boost-python-examples.git src && ./build.sh || true +# +# alternatively to the last RUN, one can share the source with the host system: +# docker build -t bp:latest . +# docker run -t -i -v $PWD:/work/src bp:latest +# mkdir build && cd build && cmake ../src && make && make test From bd07fbbf690f984b7521e250ab2a74639c31b86c Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Thu, 4 May 2017 16:08:09 +0200 Subject: [PATCH 02/23] Find boost.python3 on linux/win too --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aafc6ea..e005f06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.8.3) FIND_PACKAGE(PythonInterp) FIND_PACKAGE(PythonLibs) -if(APPLE AND ${PYTHON_VERSION_MAJOR} EQUAL 3) +if (${PYTHON_VERSION_MAJOR} EQUAL 3) FIND_PACKAGE(Boost COMPONENTS python3) else() FIND_PACKAGE(Boost COMPONENTS python) From dfd2f5d2f94cd5ae274cf89dc7482d61ebe2b618 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Thu, 4 May 2017 16:37:00 +0200 Subject: [PATCH 03/23] CTest to run detected interpreter --- 01-HelloWorld/CMakeLists.txt | 2 +- 02-ExposingClasses/CMakeLists.txt | 2 +- 03-Constructors/CMakeLists.txt | 2 +- 04-ClassMembers/CMakeLists.txt | 2 +- 05-Inheritance/CMakeLists.txt | 2 +- 06-VirtualFunctionsInPython/CMakeLists.txt | 2 +- 07-Operators/CMakeLists.txt | 2 +- 08-CallPolicies/CMakeLists.txt | 2 +- 09-Overloading/CMakeLists.txt | 2 +- 10-Embedding/CMakeLists.txt | 2 +- 11-Iterators/CMakeLists.txt | 2 +- 12-Exceptions/CMakeLists.txt | 2 +- 13-AutoInstantiation/CMakeLists.txt | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/01-HelloWorld/CMakeLists.txt b/01-HelloWorld/CMakeLists.txt index 1f4d2f8..66af19c 100644 --- a/01-HelloWorld/CMakeLists.txt +++ b/01-HelloWorld/CMakeLists.txt @@ -1,4 +1,4 @@ PYTHON_ADD_MODULE(hello hello.cpp) FILE(COPY hello.py DESTINATION .) -ADD_TEST(01-HelloWorld hello.py) +ADD_TEST(NAME 01-HelloWorld COMMAND ${PYTHON_EXECUTABLE} hello.py) diff --git a/02-ExposingClasses/CMakeLists.txt b/02-ExposingClasses/CMakeLists.txt index 9b7b59e..5e7f969 100644 --- a/02-ExposingClasses/CMakeLists.txt +++ b/02-ExposingClasses/CMakeLists.txt @@ -1,4 +1,4 @@ PYTHON_ADD_MODULE(classes classes.cpp) FILE(COPY classes.py DESTINATION .) -ADD_TEST(02-ExposingClasses classes.py) +ADD_TEST(NAME 02-ExposingClasses COMMAND ${PYTHON_EXECUTABLE} classes.py) diff --git a/03-Constructors/CMakeLists.txt b/03-Constructors/CMakeLists.txt index f33b5db..9e145bf 100644 --- a/03-Constructors/CMakeLists.txt +++ b/03-Constructors/CMakeLists.txt @@ -1,4 +1,4 @@ PYTHON_ADD_MODULE(ctor ctor.cpp) FILE(COPY ctor.py DESTINATION .) -ADD_TEST(03-Constructors ctor.py) +ADD_TEST(NAME 03-Constructors COMMAND ${PYTHON_EXECUTABLE} ctor.py) diff --git a/04-ClassMembers/CMakeLists.txt b/04-ClassMembers/CMakeLists.txt index 50f3f0b..d0912ff 100644 --- a/04-ClassMembers/CMakeLists.txt +++ b/04-ClassMembers/CMakeLists.txt @@ -1,5 +1,5 @@ PYTHON_ADD_MODULE(member member.cpp) FILE(COPY member.py DESTINATION .) -ADD_TEST(04-ClassMembers member.py) +ADD_TEST(NAME 04-ClassMembers COMMAND ${PYTHON_EXECUTABLE} member.py) diff --git a/05-Inheritance/CMakeLists.txt b/05-Inheritance/CMakeLists.txt index 41fb1f1..02748ee 100644 --- a/05-Inheritance/CMakeLists.txt +++ b/05-Inheritance/CMakeLists.txt @@ -1,5 +1,5 @@ PYTHON_ADD_MODULE(inheritance inheritance.cpp) FILE(COPY inheritance.py DESTINATION .) -ADD_TEST(05-Inheritance inheritance.py) +ADD_TEST(NAME 05-Inheritance COMMAND ${PYTHON_EXECUTABLE} inheritance.py) diff --git a/06-VirtualFunctionsInPython/CMakeLists.txt b/06-VirtualFunctionsInPython/CMakeLists.txt index b3548da..fe21fb9 100644 --- a/06-VirtualFunctionsInPython/CMakeLists.txt +++ b/06-VirtualFunctionsInPython/CMakeLists.txt @@ -1,5 +1,5 @@ PYTHON_ADD_MODULE(virtual virtual.cpp) FILE(COPY virtual.py DESTINATION .) -ADD_TEST(06-VirtualFunctionsInPython virtual.py) +ADD_TEST(NAME 06-VirtualFunctionsInPython COMMAND ${PYTHON_EXECUTABLE} virtual.py) diff --git a/07-Operators/CMakeLists.txt b/07-Operators/CMakeLists.txt index 5a6b207..41226c4 100644 --- a/07-Operators/CMakeLists.txt +++ b/07-Operators/CMakeLists.txt @@ -1,5 +1,5 @@ PYTHON_ADD_MODULE(operators operators.cpp) FILE(COPY operators.py DESTINATION .) -ADD_TEST(07-Operators operators.py) +ADD_TEST(NAME 07-Operators COMMAND ${PYTHON_EXECUTABLE} operators.py) diff --git a/08-CallPolicies/CMakeLists.txt b/08-CallPolicies/CMakeLists.txt index 0799ed9..fddcbf1 100644 --- a/08-CallPolicies/CMakeLists.txt +++ b/08-CallPolicies/CMakeLists.txt @@ -1,5 +1,5 @@ PYTHON_ADD_MODULE(policies policies.cpp) FILE(COPY policies.py DESTINATION .) -ADD_TEST(08-CallPolicies policies.py) +ADD_TEST(NAME 08-CallPolicies COMMAND ${PYTHON_EXECUTABLE} policies.py) diff --git a/09-Overloading/CMakeLists.txt b/09-Overloading/CMakeLists.txt index bf82d4a..988e823 100644 --- a/09-Overloading/CMakeLists.txt +++ b/09-Overloading/CMakeLists.txt @@ -1,5 +1,5 @@ PYTHON_ADD_MODULE(overload overload.cpp) FILE(COPY overload.py DESTINATION .) -ADD_TEST(09-Overloading overload.py) +ADD_TEST(NAME 09-Overloading COMMAND ${PYTHON_EXECUTABLE} overload.py) diff --git a/10-Embedding/CMakeLists.txt b/10-Embedding/CMakeLists.txt index 0aeda1f..3fac1d9 100644 --- a/10-Embedding/CMakeLists.txt +++ b/10-Embedding/CMakeLists.txt @@ -3,5 +3,5 @@ PYTHON_ADD_MODULE(mymodule mymodule.cpp) ADD_EXECUTABLE(embedding mymodule.cpp embedding.cpp) TARGET_LINK_LIBRARIES(embedding ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) FILE(COPY embedding.py DESTINATION .) -ADD_TEST(10-Embedding embedding) +ADD_TEST(NAME 10-Embedding COMMAND embedding) diff --git a/11-Iterators/CMakeLists.txt b/11-Iterators/CMakeLists.txt index c8f4aaf..5a828c4 100644 --- a/11-Iterators/CMakeLists.txt +++ b/11-Iterators/CMakeLists.txt @@ -1,5 +1,5 @@ PYTHON_ADD_MODULE(iterators iterators.cpp) FILE(COPY iterators.py DESTINATION .) -ADD_TEST(11-Iterators iterators.py) +ADD_TEST(NAME 11-Iterators COMMAND ${PYTHON_EXECUTABLE} iterators.py) diff --git a/12-Exceptions/CMakeLists.txt b/12-Exceptions/CMakeLists.txt index 277ae3a..c97a750 100644 --- a/12-Exceptions/CMakeLists.txt +++ b/12-Exceptions/CMakeLists.txt @@ -1,5 +1,5 @@ PYTHON_ADD_MODULE(myexceptions myexceptions.cpp) FILE(COPY myexceptions.py DESTINATION .) -ADD_TEST(12-Exceptions myexceptions.py) +ADD_TEST(NAME 12-Exceptions COMMAND ${PYTHON_EXECUTABLE} myexceptions.py) diff --git a/13-AutoInstantiation/CMakeLists.txt b/13-AutoInstantiation/CMakeLists.txt index 2e39c99..d601eb1 100644 --- a/13-AutoInstantiation/CMakeLists.txt +++ b/13-AutoInstantiation/CMakeLists.txt @@ -3,5 +3,5 @@ ADD_EXECUTABLE(auto_instance myextension.cpp auto_instance.cpp) TARGET_LINK_LIBRARIES(auto_instance ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) FILE(COPY auto_instance.py DESTINATION .) SET( ENV{PYTHONPATH} . ) -ADD_TEST(13-AutoInstantiation auto_instance) +ADD_TEST(NAME 13-AutoInstantiation COMMAND auto_instance) From fb73f5806b76c6f5b737e04ee28d056b394c5c9c Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Fri, 7 Apr 2017 22:19:50 +0200 Subject: [PATCH 04/23] Dockerfile for ubuntu/Python2 --- Dockerfile.ubuntu | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Dockerfile.ubuntu diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu new file mode 100644 index 0000000..369bece --- /dev/null +++ b/Dockerfile.ubuntu @@ -0,0 +1,11 @@ +FROM ubuntu:16.04 +RUN apt-get update && apt-get install -y libboost-all-dev python-dev git cmake g++ gdb python-dbg libboost-dbg +RUN mkdir /work +VOLUME /work/src +WORKDIR /work +RUN git clone https://github.com/TNG/boost-python-examples.git src && ./build.sh || true +# +# alternatively to the last RUN, one can share the source with the host system: +# docker build -t bp:latest . +# docker run -t -i -v $PWD:/work/src bp:latest +# mkdir build && cd build && cmake ../src && make && make test From cdeaa43118671ea8212084b93ea41a766b720273 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Fri, 8 Sep 2017 17:03:56 +0200 Subject: [PATCH 05/23] Allow Linux distributions less outspoken about GNU. --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 2bda7f6..1359445 100755 --- a/build.sh +++ b/build.sh @@ -6,7 +6,7 @@ cd ${0%%$(basename $0)} mkdir build cd build -if [[ "$OSTYPE" == "linux-gnu" ]]; then +if [[ "$OSTYPE" == "linux-gnu" || "$OSTYPE" == "linux" ]]; then cmake -DCMAKE_BUILD_TYPE=DEBUG .. && make && make test elif [[ "$OSTYPE" == "darwin"* ]]; then PYTHON_VERSION=`python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";` From 8faa1e912dd113f8fa443524c115dc4e4defa7b6 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Fri, 8 Sep 2017 22:13:14 +0200 Subject: [PATCH 06/23] Accept list argument. Fixes #16 --- 02-ExposingClasses/classes.cpp | 15 +++++++++++++++ 02-ExposingClasses/classes.py | 3 +++ 2 files changed, 18 insertions(+) diff --git a/02-ExposingClasses/classes.cpp b/02-ExposingClasses/classes.cpp index 88a75a9..dfcdcc6 100644 --- a/02-ExposingClasses/classes.cpp +++ b/02-ExposingClasses/classes.cpp @@ -1,10 +1,24 @@ #include +#include +#include #include +#include +#include struct World { void set(std::string msg) { mMsg = msg; } + void many(boost::python::list msgs) { + long l = len(msgs); + std::stringstream ss; + for (long i = 0; i0) ss << ", "; + std::string s = boost::python::extract(msgs[i]); + ss << s; + } + mMsg = ss.str(); + } std::string greet() { return mMsg; } std::string mMsg; }; @@ -16,5 +30,6 @@ BOOST_PYTHON_MODULE(classes) class_("World") .def("greet", &World::greet) .def("set", &World::set) + .def("many", &World::many) ; }; diff --git a/02-ExposingClasses/classes.py b/02-ExposingClasses/classes.py index cdbc2a8..0032809 100755 --- a/02-ExposingClasses/classes.py +++ b/02-ExposingClasses/classes.py @@ -6,4 +6,7 @@ t.set("bom dia!") print (t.greet()) +t.many(['Good Morning', 'Buon giorno', 'Kali mera']) +print (t.greet()) + From 21c9b41dc1dc57f46cfd46e4f0fccf22ea6301ae Mon Sep 17 00:00:00 2001 From: reissgrvs Date: Thu, 15 Mar 2018 15:27:51 +0000 Subject: [PATCH 07/23] Fixed function reference in 12-Exceptions --- 12-Exceptions/myexceptions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12-Exceptions/myexceptions.cpp b/12-Exceptions/myexceptions.cpp index 4dc272f..fb79ad8 100644 --- a/12-Exceptions/myexceptions.cpp +++ b/12-Exceptions/myexceptions.cpp @@ -17,5 +17,5 @@ BOOST_PYTHON_MODULE(myexceptions) { register_exception_translator(translateException); - def("someFunction", someFunction); + def("someFunction", &someFunction); } From 870d7fbabd3bc98754489c6fd4e72eb8ed6738ed Mon Sep 17 00:00:00 2001 From: Dendi Suhubdy Date: Mon, 11 Jun 2018 00:22:15 -0400 Subject: [PATCH 08/23] Related to #19: adjusting CMakeLists.txt to adjust for newest Boost 1.67 and Boost.Python 1.67 separately --- CMakeLists.txt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e005f06..8b7ba8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,13 @@ cmake_minimum_required(VERSION 2.8.3) -FIND_PACKAGE(PythonInterp) -FIND_PACKAGE(PythonLibs) -if (${PYTHON_VERSION_MAJOR} EQUAL 3) - FIND_PACKAGE(Boost COMPONENTS python3) -else() - FIND_PACKAGE(Boost COMPONENTS python) -endif() + +FIND_PACKAGE(Boost COMPONENTS python3) +FIND_PACKAGE(PythonInterp 3) +FIND_PACKAGE(PythonLibs 3 REQUIRED) + +message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}") +message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}") +message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}") +message(STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}") ENABLE_TESTING() INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) From 7892cd9d8d90d220e66feb51801932d3ea9a903c Mon Sep 17 00:00:00 2001 From: Dendi Suhubdy Date: Tue, 12 Jun 2018 19:04:13 -0400 Subject: [PATCH 09/23] adding different python version detections --- CMakeLists.txt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b7ba8a..020b69e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,20 @@ cmake_minimum_required(VERSION 2.8.3) -FIND_PACKAGE(Boost COMPONENTS python3) -FIND_PACKAGE(PythonInterp 3) -FIND_PACKAGE(PythonLibs 3 REQUIRED) +FIND_PACKAGE(PythonInterp) + +if (PYTHONINTERP_FOUND) + if (PYTHON_VERSION_MAJOR EQUAL 3) + FIND_PACKAGE(Boost COMPONENTS python3) + FIND_PACKAGE(PythonInterp 3) + FIND_PACKAGE(PythonLibs 3 REQUIRED) + else() + FIND_PACKAGE(Boost COMPONENTS python) + FIND_PACKAGE(PythonInterp) + FIND_PACKAGE(PythonLibs REQUIRED) + endif() +else() + message("Python not found") +endif() message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}") message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}") From b8345a39ce59ce4d899c6d4c0e6ceccc421fd07e Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Sun, 17 Jun 2018 21:04:12 +0200 Subject: [PATCH 10/23] Proper version numbering (at least for OSX/brew) --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 020b69e..2c98701 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,11 @@ FIND_PACKAGE(PythonInterp) if (PYTHONINTERP_FOUND) if (PYTHON_VERSION_MAJOR EQUAL 3) - FIND_PACKAGE(Boost COMPONENTS python3) + FIND_PACKAGE(Boost COMPONENTS python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}) FIND_PACKAGE(PythonInterp 3) FIND_PACKAGE(PythonLibs 3 REQUIRED) else() - FIND_PACKAGE(Boost COMPONENTS python) + FIND_PACKAGE(Boost COMPONENTS python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}) FIND_PACKAGE(PythonInterp) FIND_PACKAGE(PythonLibs REQUIRED) endif() From 38d824fe7cbc526b1de3cc73db80f0f7e7214622 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Mon, 18 Jun 2018 22:02:11 +0200 Subject: [PATCH 11/23] Make cmake work for Linux and OSX both with Python 2.7 and 3.x at the same time. --- .gitignore | Bin 2100 -> 2123 bytes CMakeLists.txt | 12 ++++++++++++ Dockerfile.ubuntu | 4 ++-- README.md | 14 +++++++------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9132d95750dd9ed931b52def8a852c8e7b6bd092..e1fa31f647bae5db5f2b4bfd5a0d80b2ebf4b567 100644 GIT binary patch delta 32 ncmdlYa9Uu4F^7b*LP2F}UKy8OL1jrsex7bwYEf}!ejXP9wOI=< delta 9 QcmX>tuti{lF$W_T01;RMmH+?% diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c98701..95c9813 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,17 @@ cmake_minimum_required(VERSION 2.8.3) FIND_PACKAGE(PythonInterp) if (PYTHONINTERP_FOUND) + if (UNIX AND NOT APPLE) + if (PYTHON_VERSION_MAJOR EQUAL 3) + FIND_PACKAGE(Boost COMPONENTS python${PYTHON_VERSION_SUFFIX}) + FIND_PACKAGE(PythonInterp 3) + FIND_PACKAGE(PythonLibs 3 REQUIRED) + else() + FIND_PACKAGE(Boost COMPONENTS python) + FIND_PACKAGE(PythonInterp) + FIND_PACKAGE(PythonLibs REQUIRED) + endif() + else() if (PYTHON_VERSION_MAJOR EQUAL 3) FIND_PACKAGE(Boost COMPONENTS python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}) FIND_PACKAGE(PythonInterp 3) @@ -12,6 +23,7 @@ if (PYTHONINTERP_FOUND) FIND_PACKAGE(PythonInterp) FIND_PACKAGE(PythonLibs REQUIRED) endif() + endif() else() message("Python not found") endif() diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index 369bece..47dad3f 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -1,5 +1,5 @@ -FROM ubuntu:16.04 -RUN apt-get update && apt-get install -y libboost-all-dev python-dev git cmake g++ gdb python-dbg libboost-dbg +FROM ubuntu:bionic +RUN apt-get update && apt-get install -y libboost-all-dev python-dev git cmake g++ gdb python-dbg RUN mkdir /work VOLUME /work/src WORKDIR /work diff --git a/README.md b/README.md index 171c97b..2702f87 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ Others are independent. ### general + [CMake](http://www.cmake.org "CMake project page") (>= 2.8.3) -+ [Boost](http://www.boost.org/ "Boost project page") (tested with 1.4.2, but should work with >= 1.3.2) -+ [Python](http://www.python.org "Python home page") (tested with 2.7, but should work with >= 2.2) ++ [Boost](http://www.boost.org/ "Boost project page") (tested with 1.67, but should work with >= 1.3.2) ++ [Python](http://www.python.org "Python home page") (tested with 2.7 and 3.6, but should work with >= 2.2) + a C++ compiler for your platform, e.g. [GCC](http://gcc.gnu.org "GCC home") or [MinGW](http://www.mingw.org "Minimalist GNU for Windows") -The examples should work on Linux, Windows and Mac, but currently have not been tested under Windows. +The examples should work on Linux, Windows and OSX, but currently [have not been tested much under Windows](https://github.com/TNG/boost-python-examples/issues/10#issuecomment-326828479). ### Mac OS X with [homebrew](http://brew.sh) @@ -45,16 +45,16 @@ The code works with Python 3 both on Linux and on OS X. However, there are sever + Build Boost::Python against Python 3 (needs at least version 1.56.0) + make sure `python` resolves to python3 (e.g., by using a python3 VE) -+ run `cmake -DBOOST_ROOT=xxx ..` ++ run `./build.sh` ### OS X (again with homebrew) Some effort has been made to make Python 3 compilation automatic, by making modifications to `build.sh` and `CMakeLists.txt` that account for quirks on the Apple platform regarding cmake, paths, and naming conventions for python/python3. Having said that, if you use `build.sh`, then you will still need to do the following: -+ Build Boost::Python against Python 3 (needs at least version 1.56.0) ++ Build Boost::Python against Python 3 (needs at least version 1.56.0) or `brew install boost-python3` + make sure `python` resolves to python3 (e.g., by using virtualenv) ++ check that `cmake` uses matching python interpreter and libraries (down to the last digit). Otherwise you run into [#17](https://github.com/TNG/boost-python-examples/issues/17). If you are building without `build.sh`, then you will additionally need to: -+ run `cmake -DBOOST_ROOT=xxx -DPYTHON_LIBRARY=xxx -DPYTHON_INCLUDE_DIR=xxx ..` -+ As of the time of this writing, the naming convention is that python2 is called "python" and python3 is called "python3" on the Apple platform. Therefore, in `CMakeLists.txt` verify that the line `FIND_PACKAGE(Boost COMPONENTS python)` is changed to `FIND_PACKAGE(Boost COMPONENTS python3)`. ++ run `cmake -DBOOST_LIBRARYDIR=xxx -DPYTHON_LIBRARY=xxx -DPYTHON_INCLUDE_DIR=xxx ..` From 9bd984f4abca6bff3a0d40ae75677f5f3c4a09fd Mon Sep 17 00:00:00 2001 From: reissgrvs Date: Thu, 15 Mar 2018 15:27:51 +0000 Subject: [PATCH 12/23] Fixed function reference in 12-Exceptions --- 12-Exceptions/myexceptions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/12-Exceptions/myexceptions.cpp b/12-Exceptions/myexceptions.cpp index 4dc272f..fb79ad8 100644 --- a/12-Exceptions/myexceptions.cpp +++ b/12-Exceptions/myexceptions.cpp @@ -17,5 +17,5 @@ BOOST_PYTHON_MODULE(myexceptions) { register_exception_translator(translateException); - def("someFunction", someFunction); + def("someFunction", &someFunction); } From 7cc1a69421b3c1e23fdbe3dd83f89b4e89d6ec58 Mon Sep 17 00:00:00 2001 From: Dendi Suhubdy Date: Mon, 11 Jun 2018 00:22:15 -0400 Subject: [PATCH 13/23] Related to #19: adjusting CMakeLists.txt to adjust for newest Boost 1.67 and Boost.Python 1.67 separately --- CMakeLists.txt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e005f06..8b7ba8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,13 @@ cmake_minimum_required(VERSION 2.8.3) -FIND_PACKAGE(PythonInterp) -FIND_PACKAGE(PythonLibs) -if (${PYTHON_VERSION_MAJOR} EQUAL 3) - FIND_PACKAGE(Boost COMPONENTS python3) -else() - FIND_PACKAGE(Boost COMPONENTS python) -endif() + +FIND_PACKAGE(Boost COMPONENTS python3) +FIND_PACKAGE(PythonInterp 3) +FIND_PACKAGE(PythonLibs 3 REQUIRED) + +message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}") +message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}") +message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}") +message(STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}") ENABLE_TESTING() INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) From c03c90e177d7ab9d08ac80231fc25024a9ffe4c5 Mon Sep 17 00:00:00 2001 From: Dendi Suhubdy Date: Tue, 12 Jun 2018 19:04:13 -0400 Subject: [PATCH 14/23] adding different python version detections --- CMakeLists.txt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b7ba8a..020b69e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,20 @@ cmake_minimum_required(VERSION 2.8.3) -FIND_PACKAGE(Boost COMPONENTS python3) -FIND_PACKAGE(PythonInterp 3) -FIND_PACKAGE(PythonLibs 3 REQUIRED) +FIND_PACKAGE(PythonInterp) + +if (PYTHONINTERP_FOUND) + if (PYTHON_VERSION_MAJOR EQUAL 3) + FIND_PACKAGE(Boost COMPONENTS python3) + FIND_PACKAGE(PythonInterp 3) + FIND_PACKAGE(PythonLibs 3 REQUIRED) + else() + FIND_PACKAGE(Boost COMPONENTS python) + FIND_PACKAGE(PythonInterp) + FIND_PACKAGE(PythonLibs REQUIRED) + endif() +else() + message("Python not found") +endif() message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}") message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}") From f285428ab3129896ce82d3de53a62660a6c8ca28 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Sun, 17 Jun 2018 21:04:12 +0200 Subject: [PATCH 15/23] Proper version numbering (at least for OSX/brew) --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 020b69e..2c98701 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,11 @@ FIND_PACKAGE(PythonInterp) if (PYTHONINTERP_FOUND) if (PYTHON_VERSION_MAJOR EQUAL 3) - FIND_PACKAGE(Boost COMPONENTS python3) + FIND_PACKAGE(Boost COMPONENTS python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}) FIND_PACKAGE(PythonInterp 3) FIND_PACKAGE(PythonLibs 3 REQUIRED) else() - FIND_PACKAGE(Boost COMPONENTS python) + FIND_PACKAGE(Boost COMPONENTS python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}) FIND_PACKAGE(PythonInterp) FIND_PACKAGE(PythonLibs REQUIRED) endif() From db54a0e9b0563ee39285a5fa7e9998caa2580041 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Mon, 18 Jun 2018 22:02:11 +0200 Subject: [PATCH 16/23] Make cmake work for Linux and OSX both with Python 2.7 and 3.x at the same time. --- .gitignore | Bin 2100 -> 2123 bytes CMakeLists.txt | 12 ++++++++++++ Dockerfile.ubuntu | 4 ++-- README.md | 14 +++++++------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9132d95750dd9ed931b52def8a852c8e7b6bd092..e1fa31f647bae5db5f2b4bfd5a0d80b2ebf4b567 100644 GIT binary patch delta 32 ncmdlYa9Uu4F^7b*LP2F}UKy8OL1jrsex7bwYEf}!ejXP9wOI=< delta 9 QcmX>tuti{lF$W_T01;RMmH+?% diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c98701..95c9813 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,17 @@ cmake_minimum_required(VERSION 2.8.3) FIND_PACKAGE(PythonInterp) if (PYTHONINTERP_FOUND) + if (UNIX AND NOT APPLE) + if (PYTHON_VERSION_MAJOR EQUAL 3) + FIND_PACKAGE(Boost COMPONENTS python${PYTHON_VERSION_SUFFIX}) + FIND_PACKAGE(PythonInterp 3) + FIND_PACKAGE(PythonLibs 3 REQUIRED) + else() + FIND_PACKAGE(Boost COMPONENTS python) + FIND_PACKAGE(PythonInterp) + FIND_PACKAGE(PythonLibs REQUIRED) + endif() + else() if (PYTHON_VERSION_MAJOR EQUAL 3) FIND_PACKAGE(Boost COMPONENTS python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}) FIND_PACKAGE(PythonInterp 3) @@ -12,6 +23,7 @@ if (PYTHONINTERP_FOUND) FIND_PACKAGE(PythonInterp) FIND_PACKAGE(PythonLibs REQUIRED) endif() + endif() else() message("Python not found") endif() diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index 369bece..47dad3f 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -1,5 +1,5 @@ -FROM ubuntu:16.04 -RUN apt-get update && apt-get install -y libboost-all-dev python-dev git cmake g++ gdb python-dbg libboost-dbg +FROM ubuntu:bionic +RUN apt-get update && apt-get install -y libboost-all-dev python-dev git cmake g++ gdb python-dbg RUN mkdir /work VOLUME /work/src WORKDIR /work diff --git a/README.md b/README.md index 171c97b..2702f87 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ Others are independent. ### general + [CMake](http://www.cmake.org "CMake project page") (>= 2.8.3) -+ [Boost](http://www.boost.org/ "Boost project page") (tested with 1.4.2, but should work with >= 1.3.2) -+ [Python](http://www.python.org "Python home page") (tested with 2.7, but should work with >= 2.2) ++ [Boost](http://www.boost.org/ "Boost project page") (tested with 1.67, but should work with >= 1.3.2) ++ [Python](http://www.python.org "Python home page") (tested with 2.7 and 3.6, but should work with >= 2.2) + a C++ compiler for your platform, e.g. [GCC](http://gcc.gnu.org "GCC home") or [MinGW](http://www.mingw.org "Minimalist GNU for Windows") -The examples should work on Linux, Windows and Mac, but currently have not been tested under Windows. +The examples should work on Linux, Windows and OSX, but currently [have not been tested much under Windows](https://github.com/TNG/boost-python-examples/issues/10#issuecomment-326828479). ### Mac OS X with [homebrew](http://brew.sh) @@ -45,16 +45,16 @@ The code works with Python 3 both on Linux and on OS X. However, there are sever + Build Boost::Python against Python 3 (needs at least version 1.56.0) + make sure `python` resolves to python3 (e.g., by using a python3 VE) -+ run `cmake -DBOOST_ROOT=xxx ..` ++ run `./build.sh` ### OS X (again with homebrew) Some effort has been made to make Python 3 compilation automatic, by making modifications to `build.sh` and `CMakeLists.txt` that account for quirks on the Apple platform regarding cmake, paths, and naming conventions for python/python3. Having said that, if you use `build.sh`, then you will still need to do the following: -+ Build Boost::Python against Python 3 (needs at least version 1.56.0) ++ Build Boost::Python against Python 3 (needs at least version 1.56.0) or `brew install boost-python3` + make sure `python` resolves to python3 (e.g., by using virtualenv) ++ check that `cmake` uses matching python interpreter and libraries (down to the last digit). Otherwise you run into [#17](https://github.com/TNG/boost-python-examples/issues/17). If you are building without `build.sh`, then you will additionally need to: -+ run `cmake -DBOOST_ROOT=xxx -DPYTHON_LIBRARY=xxx -DPYTHON_INCLUDE_DIR=xxx ..` -+ As of the time of this writing, the naming convention is that python2 is called "python" and python3 is called "python3" on the Apple platform. Therefore, in `CMakeLists.txt` verify that the line `FIND_PACKAGE(Boost COMPONENTS python)` is changed to `FIND_PACKAGE(Boost COMPONENTS python3)`. ++ run `cmake -DBOOST_LIBRARYDIR=xxx -DPYTHON_LIBRARY=xxx -DPYTHON_INCLUDE_DIR=xxx ..` From 46a1b32e7568a645f4ff372d4729f2f4a9e74508 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Tue, 19 Jun 2018 21:04:44 +0200 Subject: [PATCH 17/23] Set up -py3 suffix for linux. --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 1359445..802f3c8 100755 --- a/build.sh +++ b/build.sh @@ -7,7 +7,7 @@ mkdir build cd build if [[ "$OSTYPE" == "linux-gnu" || "$OSTYPE" == "linux" ]]; then - cmake -DCMAKE_BUILD_TYPE=DEBUG .. && make && make test + cmake -DPYTHON_VERSION_SUFFIX=-py3 -DCMAKE_BUILD_TYPE=DEBUG .. && make && make test elif [[ "$OSTYPE" == "darwin"* ]]; then PYTHON_VERSION=`python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";` PYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Versions/$PYTHON_VERSION/lib/libpython$PYTHON_VERSION.dylib From 83dee52df9a263a32bda726f03e93f4cb77f82e3 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Tue, 19 Jun 2018 21:11:07 +0200 Subject: [PATCH 18/23] Enable Travis --- .travis.yml | 20 ++++++++++++++++++++ Brewfile | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 .travis.yml create mode 100644 Brewfile diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1dc9750 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +language: cpp +script: ./build.sh + +matrix: + include: + - os: linux + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - libboost-all-dev + + - os: osx + osx_image: xcode9.2 + env: + - PYTHON_EXECUTABLE: /usr/local/bin/python + before_install: + - brew update && brew bundle + - brew unlink python && brew install python@2 diff --git a/Brewfile b/Brewfile new file mode 100644 index 0000000..625a1df --- /dev/null +++ b/Brewfile @@ -0,0 +1,3 @@ +brew 'boost-python' + + From 53be768535593ea1b17f502321d5444d3770fabb Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Fri, 22 Jun 2018 10:16:26 +0200 Subject: [PATCH 19/23] Add travis status badge. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2702f87..7ac2773 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # boost::python examples +[![Build Status](https://travis-ci.org/TNG/boost-python-examples.svg?branch=master)](https://travis-ci.org/TNG/boost-python-examples) + These are a few examples on how to use the boost::python library to extend Python with C++ libraries. Some of the are based on the [existing tutorial for boost::python from Joel de Guzman](http://www.boost.org/doc/libs/1_46_1/libs/python/doc/tutorial/doc/html/index.html "Boost.Python tutorial"). Others are independent. From d88618d1001d8c65bf3c287517f1cc71a63951b0 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Fri, 22 Jun 2018 12:46:51 +0200 Subject: [PATCH 20/23] Add DCO config: members do not need one. --- .github/dco.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/dco.yml diff --git a/.github/dco.yml b/.github/dco.yml new file mode 100644 index 0000000..4ac50ad --- /dev/null +++ b/.github/dco.yml @@ -0,0 +1,3 @@ +require: + members: false + From f7cd9af15557f3214fd885b7530c0dbc0e927d34 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Fri, 22 Jun 2018 13:21:48 +0200 Subject: [PATCH 21/23] Add and document DCO. Signed-off-by: Achim Herwig --- DCO.md | 43 +++++++++++++++++++++++++++++++++++++++++++ README.md | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 DCO.md diff --git a/DCO.md b/DCO.md new file mode 100644 index 0000000..f34d70b --- /dev/null +++ b/DCO.md @@ -0,0 +1,43 @@ +## Sign your work - the Developer's Certificate of Origin +The sign-off is a simple line at the end of the explanation for the patch, which certifies that you wrote it or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify the below (from [developercertificate.org](https://www.developercertificate.org)): + +> Developer's Certificate of Origin 1.1 +> +> By making a contribution to this project, I certify that: +> +> (a) The contribution was created in whole or in part by me and I +> have the right to submit it under the open source license +> indicated in the file; or +> +> (b) The contribution is based upon previous work that, to the best +> of my knowledge, is covered under an appropriate open source +> license and I have the right under that license to submit that +> work with modifications, whether created in whole or in part +> by me, under the same open source license (unless I am +> permitted to submit under a different license), as indicated +> in the file; or +> +> (c) The contribution was provided directly to me by some other +> person who certified (a), (b) or (c) and I have not modified +> it. +> +> (d) I understand and agree that this project and the contribution +> are public and that a record of the contribution (including all +> personal information I submit with it, including my sign-off) is +> maintained indefinitely and may be redistributed consistent with +> this project or the open source license(s) involved. + +#### DCO Sign-Off Methods + +The DCO requires a sign-off message in the following format appear on each commit in the pull request: + +> Signed-off-by: Random J Developer + +using your real name (sorry, no pseudonyms or anonymous contributions.) + +The DCO text can either be manually added to your commit body, or you can add either **`-s`** or **`--signoff`** to your usual git commit commands. If you forget to add the sign-off you can also amend a previous commit with the sign-off by running **`git commit --amend -s`**. If you've pushed your changes to Github already you'll need to force push your branch after this with ***`git push -f`**. + + +#### Alternative Sign-Off Methods in rare cases + +If it is really no option for you to disclose your real name and email address, there might be a chance that you can get your contribution accepted. In this case please contact the maintainers directly and verify the adherence to the DCO of the contribution manually. This might include quite some legal overhead for both parties. diff --git a/README.md b/README.md index 7ac2773..63e1f2b 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,36 @@ Some effort has been made to make Python 3 compilation automatic, by making modi If you are building without `build.sh`, then you will additionally need to: + run `cmake -DBOOST_LIBRARYDIR=xxx -DPYTHON_LIBRARY=xxx -DPYTHON_INCLUDE_DIR=xxx ..` + +## Contributing + +Contributions are very welcome. The following will provide some helpful guidelines. + +### How to contribute + +If you want to submit a contribution, please follow the following workflow: + +* Fork the project +* Create a feature branch +* Add your contribution +* When you're completely done, build the project and run all tests +* Create a Pull Request + +### Commits + +Commit messages should be clear and fully elaborate the context and the reason of a change. +If your commit refers to an issue, please post-fix it with the issue number, e.g. + +``` +Issue: #123 +``` + +Furthermore, commits should be signed (`git commit -s`) according to the [DCO](DCO.md). + +### Pull Requests + +If your Pull Request resolves an issue, please add a respective line to the end, like + +``` +Resolves #123 +``` From 1b9aca72dcd553b5f7910556bc28eabb5a3a7164 Mon Sep 17 00:00:00 2001 From: fossabot Date: Tue, 19 Mar 2019 12:42:32 -0700 Subject: [PATCH 22/23] Add license scan report and status Signed-off-by: fossabot --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63e1f2b..e3ac2f3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ - # boost::python examples [![Build Status](https://travis-ci.org/TNG/boost-python-examples.svg?branch=master)](https://travis-ci.org/TNG/boost-python-examples) +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FTNG%2Fboost-python-examples.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FTNG%2Fboost-python-examples?ref=badge_shield) These are a few examples on how to use the boost::python library to extend Python with C++ libraries. Some of the are based on the [existing tutorial for boost::python from Joel de Guzman](http://www.boost.org/doc/libs/1_46_1/libs/python/doc/tutorial/doc/html/index.html "Boost.Python tutorial"). @@ -93,3 +93,7 @@ If your Pull Request resolves an issue, please add a respective line to the end, ``` Resolves #123 ``` + + +## License +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FTNG%2Fboost-python-examples.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FTNG%2Fboost-python-examples?ref=badge_large) \ No newline at end of file From 72ea66d3e6200f8bcbaac707069ba708d88d8ee8 Mon Sep 17 00:00:00 2001 From: Achim Herwig Date: Sat, 23 May 2020 16:38:51 +0200 Subject: [PATCH 23/23] Add problem report template --- .github/ISSUE_TEMPLATE/problem-report.md | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/problem-report.md diff --git a/.github/ISSUE_TEMPLATE/problem-report.md b/.github/ISSUE_TEMPLATE/problem-report.md new file mode 100644 index 0000000..c2b8e7e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/problem-report.md @@ -0,0 +1,29 @@ +--- +name: Problem report +about: Create a problem report to help us help you +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**Error message(s)** + +**Environment:** + - OS: [e.g. Ubuntu Linux, openSUSE Linux, OSX, Windows] + - Version [e.g. 22] + - Python Version + - Source of Python [e.g., self-compiled, OS version, ...] + - Boost Version + - Source of Boost [e.g., self-compiled, OS version, ...] + - Compiler Version + +**Log of compilation** + + + +**Additional context** +Add any other context about the problem here.