Alternate locations for BOOST_PYTHON_MODULE
Hello, I am attempting to make a large pre-existing code base accessible to python, so that I can run quick scripts to automate the behavior of certain classes for testing purposes. We are using C++ and python 3.3 with the boost.python library. I have a script to automatically generate the BOOST_PYTHON_MODULE( ... ) wrapper definitions for the C++ source code. But, because this is a pre-existing code base with other people already working on it, I would prefer to not have to modify the source code files of all of the classes by inserting the python wrappers at the bottom. All the examples I've seen show the BOOST_PYTHON_MODULE at the bottom of the C++ source file. Is it possible to put the BOOST_PYTHON_MODULE in a separate file, and #include the class it is wrapping? If so, how would I do this? And how would I configure the Jamroot file to compile these properly? Also, I'm targeting windows systems and using Visual Studio 2010, if that matters Thanks very much, Trevor
Trevor, that is certainly possible, all my python exports look like this: #include "pfemPy.inl" BOOST_PYTHON_MODULE(pfemPy) { PfemInst::call(); } // boost module Then e.g. in "pfemPy.inl" I wrap and export the C++ classes. The file "pfemPy.inl" in turn includes the header of the required source which are "untoched". I can not help you about the Jamroot, as I am not using bjam. -Holger On Wed, Jun 12, 2013 at 11:05 AM, Trevor Haba <Trevor.Haba@logmein.com> wrote:
Hello,
I am attempting to make a large pre-existing code base accessible to python, so that I can run quick scripts to automate the behavior of certain classes for testing purposes. We are using C++ and python 3.3 with the boost.python library. I have a script to automatically generate the BOOST_PYTHON_MODULE( … ) wrapper definitions for the C++ source code. But, because this is a pre-existing code base with other people already working on it, I would prefer to not have to modify the source code files of all of the classes by inserting the python wrappers at the bottom. All the examples I’ve seen show the BOOST_PYTHON_MODULE at the bottom of the C++ source file. Is it possible to put the BOOST_PYTHON_MODULE in a separate file, and #include the class it is wrapping? If so, how would I do this? And how would I configure the Jamroot file to compile these properly?
Also, I’m targeting windows systems and using Visual Studio 2010, if that matters
Thanks very much,
Trevor
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Holger, Thanks for the reply. I'm a little bit confused about the .inl file. Sorry if these are obvious questions, I'm still somewhat new at this. So this "pfemPy.inl" is what actually contains the python bindings? So the commands like class_<foo>("foo").def(...) are in the .inl file? Are these wrapped in their own BOOST_PYTHON_MODULE(...) {} block, or are they in some other format? Then PfemInst::call(), what does that do? I'm a little bit confused, if you are still writing the wrapper calls, why not just put them in the BOOST_PYTHON_MODULE you have here? Why keep them in a seperate file, #include them and then use the ::call() function? Also, I am not tied to usnig bjam, that is just what the boost.python tutorial recommended. How are you compiling your python extension modules? Can you point me to some information about it? Thanks for your help, Trevor -----Original Message----- From: Cplusplus-sig [mailto:cplusplus-sig-bounces+trevor.haba=logmein.com@python.org] On Behalf Of Holger Brandsmeier Sent: Wednesday, June 12, 2013 11:27 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Alternate locations for BOOST_PYTHON_MODULE Trevor, that is certainly possible, all my python exports look like this: #include "pfemPy.inl" BOOST_PYTHON_MODULE(pfemPy) { PfemInst::call(); } // boost module Then e.g. in "pfemPy.inl" I wrap and export the C++ classes. The file "pfemPy.inl" in turn includes the header of the required source which are "untoched". I can not help you about the Jamroot, as I am not using bjam. -Holger On Wed, Jun 12, 2013 at 11:05 AM, Trevor Haba <Trevor.Haba@logmein.com> wrote:
Hello,
I am attempting to make a large pre-existing code base accessible to python, so that I can run quick scripts to automate the behavior of certain classes for testing purposes. We are using C++ and python 3.3 with the boost.python library. I have a script to automatically generate the BOOST_PYTHON_MODULE( … ) wrapper definitions for the C++ source code. But, because this is a pre-existing code base with other people already working on it, I would prefer to not have to modify the source code files of all of the classes by inserting the python wrappers at the bottom. All the examples I’ve seen show the BOOST_PYTHON_MODULE at the bottom of the C++ source file. Is it possible to put the BOOST_PYTHON_MODULE in a separate file, and #include the class it is wrapping? If so, how would I do this? And how would I configure the Jamroot file to compile these properly?
Also, I’m targeting windows systems and using Visual Studio 2010, if that matters
Thanks very much,
Trevor
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Trevor, ok, so I misunderstood your question. If what you want to do is this: ---- myclass.h class MyClass { [...] }; ---- pythonFile.cpp #include "myclass.h" [...] BOOST_PYTHON_MODULE(...) { [...] } That is certainly possible, I think almost everyone (including me) does it like this.
Also, I am not tied to usnig bjam, that is just what the boost.python tutorial recommended. How are you compiling your python extension modules? Can you point me to some information about it?
I recommend you to use bjam, I simply can not help you about it. -Holger On Wed, Jun 12, 2013 at 12:10 PM, Trevor Haba <Trevor.Haba@logmein.com> wrote:
Holger,
Thanks for the reply. I'm a little bit confused about the .inl file. Sorry if these are obvious questions, I'm still somewhat new at this.
So this "pfemPy.inl" is what actually contains the python bindings? So the commands like class_<foo>("foo").def(...) are in the .inl file? Are these wrapped in their own BOOST_PYTHON_MODULE(...) {} block, or are they in some other format? Then PfemInst::call(), what does that do? I'm a little bit confused, if you are still writing the wrapper calls, why not just put them in the BOOST_PYTHON_MODULE you have here? Why keep them in a seperate file, #include them and then use the ::call() function?
Also, I am not tied to usnig bjam, that is just what the boost.python tutorial recommended. How are you compiling your python extension modules? Can you point me to some information about it?
Thanks for your help, Trevor
-----Original Message----- From: Cplusplus-sig [mailto:cplusplus-sig-bounces+trevor.haba=logmein.com@python.org] On Behalf Of Holger Brandsmeier Sent: Wednesday, June 12, 2013 11:27 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Alternate locations for BOOST_PYTHON_MODULE
Trevor,
that is certainly possible, all my python exports look like this:
#include "pfemPy.inl"
BOOST_PYTHON_MODULE(pfemPy) { PfemInst::call(); } // boost module
Then e.g. in "pfemPy.inl" I wrap and export the C++ classes. The file "pfemPy.inl" in turn includes the header of the required source which are "untoched".
I can not help you about the Jamroot, as I am not using bjam.
-Holger
On Wed, Jun 12, 2013 at 11:05 AM, Trevor Haba <Trevor.Haba@logmein.com> wrote:
Hello,
I am attempting to make a large pre-existing code base accessible to python, so that I can run quick scripts to automate the behavior of certain classes for testing purposes. We are using C++ and python 3.3 with the boost.python library. I have a script to automatically generate the BOOST_PYTHON_MODULE( … ) wrapper definitions for the C++ source code. But, because this is a pre-existing code base with other people already working on it, I would prefer to not have to modify the source code files of all of the classes by inserting the python wrappers at the bottom. All the examples I’ve seen show the BOOST_PYTHON_MODULE at the bottom of the C++ source file. Is it possible to put the BOOST_PYTHON_MODULE in a separate file, and #include the class it is wrapping? If so, how would I do this? And how would I configure the Jamroot file to compile these properly?
Also, I’m targeting windows systems and using Visual Studio 2010, if that matters
Thanks very much,
Trevor
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
On Wed, 12 Jun 2013 11:34:24 +0100, Holger Brandsmeier <brandsmeier@gmx.de> wrote:
Trevor,
ok, so I misunderstood your question. If what you want to do is this:
---- myclass.h class MyClass { [...] };
---- pythonFile.cpp #include "myclass.h" [...]
BOOST_PYTHON_MODULE(...) { [...] }
That is certainly possible, I think almost everyone (including me) does it like this.
Yea, this is kind of how I do it, but I don't include the class headers into the file containing BOOST_PYTHON_MODULE; I just forward declare a load of RegisterFooClass functions, and then call them within the BOOST_PYTHON_MODULE. Doing it this way I find, makes the file containing the BOOST_PYTHON_MODULE a lot smaller and it compiles a lot faster. All it needs to include is <boost/python/module.hpp>.
Also, I am not tied to usnig bjam, that is just what the boost.python tutorial recommended. How are you compiling your python extension modules? Can you point me to some information about it?
I recommend you to use bjam, I simply can not help you about it.
Yea, I don't use bjam either... I'm using Python's distutils, which is not all that recommendable. I'd probably recommend using Makefile's. I'm sure you can find some relevant tutorials online... Cheers, Alex
participants (3)
-
Alex Leach -
Holger Brandsmeier -
Trevor Haba