From 370c52d1310a0d86e4d0c4ad125209f320918d54 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Thu, 13 Jun 2019 23:20:33 +0200 Subject: Add extensions directory in user folder to PYTHONPATH This allows users to install modules there and use them easily within other modules (for example required for extension manager) --- src/inkscape-main.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/inkscape-main.cpp') diff --git a/src/inkscape-main.cpp b/src/inkscape-main.cpp index 8473795c1..17f044edb 100644 --- a/src/inkscape-main.cpp +++ b/src/inkscape-main.cpp @@ -17,6 +17,8 @@ #include "inkscape-application.h" #include "path-prefix.h" +#include "io/resource.h" + static void set_extensions_env() { // add inkscape to PATH, so the correct version is always available to extensions by simply calling "inkscape" @@ -29,27 +31,23 @@ static void set_extensions_env() } g_free(program_dir); - // add share/inkscape/extensions to PYTHONPATH so the inkex module is found by extensions in user folder - auto new_pythonpath = std::string(INKSCAPE_EXTENSIONDIR); + // add various locations to PYTHONPATH so extensions find their modules + auto extensiondir_user = get_path_ustring(Inkscape::IO::Resource::USER, Inkscape::IO::Resource::EXTENSIONS); + auto extensiondir_system = get_path_ustring(Inkscape::IO::Resource::SYSTEM, Inkscape::IO::Resource::EXTENSIONS); + + auto pythonpath = extensiondir_user + G_SEARCHPATH_SEPARATOR + extensiondir_system; - // add old PYTHONPATH - gchar const *pythonpath = g_getenv("PYTHONPATH"); - if (pythonpath) { - new_pythonpath.append(G_SEARCHPATH_SEPARATOR_S).append(pythonpath); + auto pythonpath_old = Glib::getenv("PYTHONPATH"); + if (!pythonpath_old.empty()) { + pythonpath += G_SEARCHPATH_SEPARATOR + pythonpath_old; } - // add share/inkscape/extensions/inkex/deprecated-simple - new_pythonpath.append(G_SEARCHPATH_SEPARATOR_S) - .append(INKSCAPE_EXTENSIONDIR) - .append(G_DIR_SEPARATOR_S) - .append("inkex") - .append(G_DIR_SEPARATOR_S) - .append("deprecated-simple"); + pythonpath += G_SEARCHPATH_SEPARATOR + Glib::build_filename(extensiondir_system, "inkex", "deprecated-simple"); - g_setenv("PYTHONPATH", new_pythonpath.c_str(), true); + Glib::setenv("PYTHONPATH", pythonpath); // Python 2.x attempts to encode output as ASCII by default when sent to a pipe. - g_setenv("PYTHONIOENCODING", "UTF-8", true); + Glib::setenv("PYTHONIOENCODING", "UTF-8"); #ifdef _WIN32 // add inkscape directory to DLL search path so dynamically linked extension modules find their libraries -- cgit v1.2.3