diff --git a/src/gsi/gsi/gsiInterpreter.h b/src/gsi/gsi/gsiInterpreter.h index a88f00814..9cd074dc2 100644 --- a/src/gsi/gsi/gsiInterpreter.h +++ b/src/gsi/gsi/gsiInterpreter.h @@ -187,7 +187,7 @@ public: /** * @brief Add the given path to the search path ($: in ruby) */ - virtual void add_path (const std::string &path) = 0; + virtual void add_path (const std::string &path, bool prepend = false) = 0; /** * @brief Requires the given module (ruby "require") diff --git a/src/pya/pya/pya.cc b/src/pya/pya/pya.cc index fb7f16fd3..41a421b62 100644 --- a/src/pya/pya/pya.cc +++ b/src/pya/pya/pya.cc @@ -321,7 +321,9 @@ PythonInterpreter::PythonInterpreter (bool embedded) // We can put build-in modules there. std::string module_path = tl::get_module_path ((void *) &reset_interpreter); if (! module_path.empty ()) { - add_path (tl::combine_path (tl::absolute_path (module_path), "pymod")); + add_path (tl::combine_path (tl::absolute_path (module_path), "pymod"), true /*prepend*/); + } else { + tl::warn << tl::to_string (tr ("Unable to find built-in Python module library path")); } PyObject *pya_module = PyImport_ImportModule (pya_module_name); @@ -368,11 +370,15 @@ PythonInterpreter::make_string (const std::string &s) } void -PythonInterpreter::add_path (const std::string &p) +PythonInterpreter::add_path (const std::string &p, bool prepend) { PyObject *path = PySys_GetObject ((char *) "path"); if (path != NULL && PyList_Check (path)) { - PyList_Append (path, c2python (p)); + if (prepend) { + PyList_Insert (path, 0, c2python (p)); + } else { + PyList_Append (path, c2python (p)); + } } } diff --git a/src/pya/pya/pya.h b/src/pya/pya/pya.h index cd5ebbf83..65fa77cb9 100644 --- a/src/pya/pya/pya.h +++ b/src/pya/pya/pya.h @@ -108,7 +108,7 @@ public: /** * @brief Add the given path to the search path */ - void add_path (const std::string &path); + void add_path (const std::string &path, bool prepend = false); /** * @brief Adds a package location to this interpreter diff --git a/src/pyastub/pya.cc b/src/pyastub/pya.cc index 1ab239f6e..e752bd85b 100644 --- a/src/pyastub/pya.cc +++ b/src/pyastub/pya.cc @@ -53,7 +53,7 @@ PythonInterpreter *PythonInterpreter::instance () } void -PythonInterpreter::add_path (const std::string &) +PythonInterpreter::add_path (const std::string &, bool prepend) { // .. nothing .. } diff --git a/src/pyastub/pya.h b/src/pyastub/pya.h index 64f8400b1..c1bf931d8 100644 --- a/src/pyastub/pya.h +++ b/src/pyastub/pya.h @@ -48,7 +48,7 @@ public: /** * @brief Add the given path to the search path */ - void add_path (const std::string &path); + void add_path (const std::string &path, bool prepend); /** * @brief Adds a package location to this interpreter diff --git a/src/rba/rba/rba.cc b/src/rba/rba/rba.cc index d11eca094..aba50449c 100644 --- a/src/rba/rba/rba.cc +++ b/src/rba/rba/rba.cc @@ -1552,11 +1552,15 @@ struct RubyConstDescriptor extern "C" void ruby_prog_init(); static void -rba_add_path (const std::string &path) +rba_add_path (const std::string &path, bool prepend) { VALUE pv = rb_gv_get ("$:"); if (pv != Qnil && TYPE (pv) == T_ARRAY) { - rb_ary_push (pv, rb_str_new (path.c_str (), long (path.size ()))); + if (prepend) { + rb_ary_unshift (pv, rb_str_new (path.c_str (), long (path.size ()))); + } else { + rb_ary_push (pv, rb_str_new (path.c_str (), long (path.size ()))); + } } } @@ -2036,7 +2040,7 @@ RubyInterpreter::initialize (int &main_argc, char **main_argv, int (*main_func) if (v.is_list ()) { for (tl::Variant::iterator i = v.begin (); i != v.end (); ++i) { - rba_add_path (i->to_string ()); + rba_add_path (i->to_string (), false); } } @@ -2133,9 +2137,9 @@ RubyInterpreter::remove_package_location (const std::string & /*package_path*/) } void -RubyInterpreter::add_path (const std::string &path) +RubyInterpreter::add_path (const std::string &path, bool prepend) { - rba_add_path (path); + rba_add_path (path, prepend); } void diff --git a/src/rba/rba/rba.h b/src/rba/rba/rba.h index f2a1bda43..21535e986 100644 --- a/src/rba/rba/rba.h +++ b/src/rba/rba/rba.h @@ -56,7 +56,7 @@ public: /** * @brief Add the given path to the search path ($: in ruby) */ - void add_path (const std::string &path); + void add_path (const std::string &path, bool prepend = false); /** * @brief Adds a package location to this interpreter diff --git a/src/rbastub/rba.cc b/src/rbastub/rba.cc index 3ad1e9ddd..e42c34a34 100644 --- a/src/rbastub/rba.cc +++ b/src/rbastub/rba.cc @@ -63,7 +63,7 @@ RubyInterpreter::remove_package_location (const std::string &) } void -RubyInterpreter::add_path (const std::string &) +RubyInterpreter::add_path (const std::string &, bool) { // .. nothing .. } diff --git a/src/rbastub/rba.h b/src/rbastub/rba.h index 393dbae0c..b178e1cf0 100644 --- a/src/rbastub/rba.h +++ b/src/rbastub/rba.h @@ -45,7 +45,7 @@ public: /** * @brief Add the given path to the search path ($: in ruby) */ - void add_path (const std::string &path); + void add_path (const std::string &path, bool prepend); /** * @brief Adds a package location to this interpreter