feat(python-plugin): prepend instead of append ModulePath to sys.path
authorPatrick Browne <patrick.browne@amadeus.com>
Tue, 30 Sep 2014 08:31:05 +0000 (10:31 +0200)
committerPatrick Browne <patrick.browne@amadeus.com>
Tue, 30 Sep 2014 08:32:07 +0000 (10:32 +0200)
When importing a module, you expect the plugin repertory to have higher priority
than your site-packages. It will prevent hard to debug clashing module names problems.
At least, if there is a problem, it will fail more loudly than "module did not register
any config callback"

src/python.c

index 10ac8f0..81724c0 100644 (file)
@@ -1103,8 +1103,8 @@ static int cpy_config(oconfig_item_t *ci) {
                                cpy_log_exception("python initialization");
                                continue;
                        }
-                       if (PyList_Append(sys_path, dir_object) != 0) {
-                               ERROR("python plugin: Unable to append \"%s\" to "
+                       if (PyList_Insert(sys_path, 0, dir_object) != 0) {
+                               ERROR("python plugin: Unable to prepend \"%s\" to "
                                      "python module path.", dir);
                                cpy_log_exception("python initialization");
                        }