From 6989b0748bb8afae80f7f3271ec014dbb4ad07d3 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 29 Feb 2012 22:12:07 -0600 Subject: Fixed Python initialization problem with --import --- src/pyinterp.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/pyinterp.cc') diff --git a/src/pyinterp.cc b/src/pyinterp.cc index e0fd2d59..e48f16c6 100644 --- a/src/pyinterp.cc +++ b/src/pyinterp.cc @@ -191,32 +191,34 @@ object python_interpreter_t::import_into_main(const string& str) object python_interpreter_t::import_option(const string& str) { + if (! is_initialized) + initialize(); + path file(str); + string name(str); python::object sys_module = python::import("sys"); python::object sys_dict = sys_module.attr("__dict__"); python::list paths(sys_dict["path"]); + if (contains(str, ".py")) { #if BOOST_VERSION >= 103700 - paths.insert(0, file.parent_path().string()); - sys_dict["path"] = paths; + path& cwd(get_parsing_context().current_directory); + paths.insert(0, filesystem::absolute(file, cwd).parent_path().string()); + sys_dict["path"] = paths; #if BOOST_VERSION >= 104600 - string name = file.filename().string(); - if (contains(name, ".py")) name = file.stem().string(); #else - string name = file.filename(); - if (contains(name, ".py")) name = file.stem(); #endif #else // BOOST_VERSION >= 103700 - paths.insert(0, file.branch_path().string()); - sys_dict["path"] = paths; - - string name = file.leaf(); + paths.insert(0, file.branch_path().string()); + sys_dict["path"] = paths; + name = file.leaf(); #endif // BOOST_VERSION >= 103700 + } return python::import(python::str(name.c_str())); } -- cgit v1.2.3