diff options
author | John Wiegley <johnw@newartisans.com> | 2012-02-29 22:12:07 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-02-29 22:12:07 -0600 |
commit | 6989b0748bb8afae80f7f3271ec014dbb4ad07d3 (patch) | |
tree | fe3d7fd7d26d40f0e46d3274bb535086919fb1a1 /src/pyinterp.cc | |
parent | 8013e091292628b3e631fea07342c31f1c36966b (diff) | |
download | fork-ledger-6989b0748bb8afae80f7f3271ec014dbb4ad07d3.tar.gz fork-ledger-6989b0748bb8afae80f7f3271ec014dbb4ad07d3.tar.bz2 fork-ledger-6989b0748bb8afae80f7f3271ec014dbb4ad07d3.zip |
Fixed Python initialization problem with --import
Diffstat (limited to 'src/pyinterp.cc')
-rw-r--r-- | src/pyinterp.cc | 22 |
1 files changed, 12 insertions, 10 deletions
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())); } |