From e61401d27e0ea57248b8321dce58d4f56ad57fa4 Mon Sep 17 00:00:00 2001 From: Stefan Seefeld Date: Mon, 5 Mar 2007 18:44:45 +0000 Subject: [PATCH] Fix import_ failure. [SVN r37141] --- test/Jamfile.v2 | 6 +++--- test/import_.cpp | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 743ca4d3..51f59b63 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -5,11 +5,11 @@ use-project /boost/python : ../build ; project /boost/python/test ; -rule py-run ( sources * ) +rule py-run ( sources * : input-file ? ) { return [ run $(sources) /boost/python//boost_python /python//python : # args - : # input files + : $(input-file) : #requirements BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION @@ -150,7 +150,7 @@ bpl-test crossmod_opaque /boost/python//boost_python ] [ bpl-test map_indexing_suite : map_indexing_suite.py map_indexing_suite_ext ] -[ py-run import_.cpp ] +[ py-run import_.cpp : import_.py ] # if $(TEST_BIENSTMAN_NON_BUGS) # { diff --git a/test/import_.cpp b/test/import_.cpp index 86ca2d70..f50a0089 100644 --- a/test/import_.cpp +++ b/test/import_.cpp @@ -7,7 +7,7 @@ #include #include - +#include namespace bpl = boost::python; @@ -22,9 +22,23 @@ void import_test() int main(int argc, char **argv) { + BOOST_TEST(argc == 2); + // Initialize the interpreter Py_Initialize(); + + // Retrieve the main module + bpl::object main = bpl::import("__main__"); + + // Retrieve the main module's namespace + bpl::object global(main.attr("__dict__")); + // Inject search path for import_ module + std::ostringstream script; + script << "import sys, os.path\n" + << "path = os.path.dirname('" << argv[1] << "')\n" + << "sys.path.insert(0, path)\n"; + bpl::object result = bpl::exec(bpl::str(script.str()), global, global); if (bpl::handle_exception(import_test)) { if (PyErr_Occurred())