mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
Fix import_ failure.
[SVN r37141]
This commit is contained in:
@@ -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
|
||||
<define>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)
|
||||
# {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user