File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 55use-project /boost/python : ../build ;
66project /boost/python/test ;
77
8- rule py-run ( sources * )
8+ rule py-run ( sources * : input-file ? )
99{
1010 return [ run $(sources) /boost/python//boost_python /python//python
1111 : # args
12- : # input files
12+ : $( input-file)
1313 : #requirements
1414 <define>BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION
1515
@@ -150,7 +150,7 @@ bpl-test crossmod_opaque
150150 /boost/python//boost_python ]
151151[ bpl-test
152152 map_indexing_suite : map_indexing_suite.py map_indexing_suite_ext ]
153- [ py-run import_.cpp ]
153+ [ py-run import_.cpp : import_.py ]
154154
155155# if $(TEST_BIENSTMAN_NON_BUGS)
156156# {
Original file line number Diff line number Diff line change 77
88#include < boost/detail/lightweight_test.hpp>
99#include < iostream>
10-
10+ # include < sstream >
1111
1212namespace bpl = boost::python;
1313
@@ -22,9 +22,23 @@ void import_test()
2222
2323int main (int argc, char **argv)
2424{
25+ BOOST_TEST (argc == 2 );
26+
2527 // Initialize the interpreter
2628 Py_Initialize ();
29+
30+ // Retrieve the main module
31+ bpl::object main = bpl::import (" __main__" );
32+
33+ // Retrieve the main module's namespace
34+ bpl::object global (main.attr (" __dict__" ));
2735
36+ // Inject search path for import_ module
37+ std::ostringstream script;
38+ script << " import sys, os.path\n "
39+ << " path = os.path.dirname('" << argv[1 ] << " ')\n "
40+ << " sys.path.insert(0, path)\n " ;
41+ bpl::object result = bpl::exec (bpl::str (script.str ()), global, global);
2842 if (bpl::handle_exception (import_test))
2943 {
3044 if (PyErr_Occurred ())
You can’t perform that action at this time.
0 commit comments