I wrote a python library with two parts:
- A Python C extension
- A Python wrapper for the Python C extension
I would like to be able to package it in such a way that the Python wrapper is the top level module foo
and the Python C extension is a submodule located at foo._foo
. However I have so far only been able to create two top level modules, foo
and _foo
.
What do I need to do in setup.py
and in the init_foo
C function in order to accomplish this?
(My question is subtlety different from this)
Current directory structure:
foo/
foo/
__init__.py
foo.c
setup.py
tests.py
setup.py
looks something like:
from distutils.core import setup, Extension
module = Extension('_foo',
sources=['foo.c'])
setup(name='foo', packages=['foo'], ext_modules=[module])
foo.c
looks something like:
PyMODINIT_FUNC init_foo(void) {
PyObject *m;
m = Py_InitModule("_foo", FooMethods);
// ..
}
int main(int argc, char *argv[]) {
Py_SetProgramName(argv[0])
Py_Initialize();
init_pychbase();
}
foo/__init__.py
looks something like:
from _foo import _Foo, _Bar, _Baz
class Foo(object):
def __init__(self):
self._foo = _Foo()
tests.py
file was located in the same directory as the foo module so the imports were off when I ran it. Creating atests/tests.py
setup solved this. – Suspiration