Commit 370c52d1 authored by Patrick Storz's avatar Patrick Storz 🦄

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)
parent 812f50f7
Pipeline #66315345 passed with stages
in 106 minutes and 58 seconds
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment