Commits

Greg Ward committed 0b2cbc1

plugins: automatically import fubsy module into Python's __main__

  • Participants
  • Parent commits 33df062

Comments (0)

Files changed (2)

File src/fubsy/plugins/empython.c

 
 int
 installBuiltins() {
-    PyObject *module = Py_InitModule("fubsy", methods);
-    if (!module) {
+    PyObject *fubsy, *main;
+
+    fubsy = Py_InitModule("fubsy", methods);
+    if (!fubsy) {
         return -1;
     }
+
+    /* "import fubsy" in __main__, so it's visible to inline plugins for free */
+    main = PyImport_ImportModule("__main__");
+    if (!main) {
+        return -1;
+    }
+    Py_INCREF(fubsy);                         /* AddObject() steals a ref */
+    if (PyModule_AddObject(main, "fubsy", fubsy) < 0) {
+        return -1;
+    }
+
+    Py_DECREF(main);
     return 0;
 }

File src/fubsy/plugins/python_test.go

 	assert.Nil(t, err)
 
 	values, err := pp.Run(`
-import fubsy     # XXX this should be automatic!
 fubsy.mkdir("ding")
 fubsy.mkdir("dong")
 `)