From 14f3454afd92e1ae37950eb9d8bbb1bf750a1ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Wed, 27 Mar 2013 09:09:34 -0300 Subject: Calculate workdir in the launcher, set PythonHome to that It will look for dependencies in PYTHONHOME/lib --- CMakeLists.txt | 2 +- src/main.cpp | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87185c7..1e43cc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.8.3) FIND_PACKAGE(PythonInterp) FIND_PACKAGE(PythonLibs) -FIND_PACKAGE(Boost COMPONENTS python) +FIND_PACKAGE(Boost COMPONENTS python filesystem system) INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) diff --git a/src/main.cpp b/src/main.cpp index 237b282..9db7a2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,34 +3,44 @@ #include #include +#include +#include #include -using namespace boost::python; +namespace py = boost::python; +namespace fs = boost::filesystem; int main(int argc, char** argv) { try { + fs::path full_path(fs::current_path()); + Py_Initialize(); - object main_module = import("__main__"); - object global = (main_module.attr("__dict__")); + + Py_SetPythonHome(const_cast(full_path.string().c_str())); + + py::object main_module = py::import("__main__"); + py::object global = (main_module.attr("__dict__")); PySys_SetArgv(argc, argv); - exec( - "import os\n" + global["_pwd"] = full_path.string(); + + py::exec( "import sys\n" + "sys.path = [_pwd + '/lib',\n" + " _pwd + '/apps',\n" + " _pwd + '/apps/eip',\n" + " _pwd]\n" + "import os\n" "import encodings.idna\n" // we need to make sure this is imported - "sys.path = [os.path.join(os.getcwd(), 'deps'),\n" - " os.path.join(os.getcwd(), 'apps'),\n" - " os.path.join(os.getcwd(), 'apps', 'eip'),\n" - " os.getcwd()]\n" "sys.argv.append('--standalone')\n", global, global); - exec_file("apps/leap/app.py", - global, - global); - } catch (error_already_set&) { + py::exec_file("apps/leap/app.py", + global, + global); + } catch (py::error_already_set&) { PyErr_PrintEx(0); return 1; } -- cgit v1.2.3