I am trying to create a few AOT compiled python code for a project using numba.
I would like to have all my source code in a particular directory and then use these to build the compiled code through the conventional setup.py in a different directory. For example, let's assume my project is structured as follows
- numba_project/
- numba_project/
- __init__.py
- src/
- numba_source.py
- lib/
- setup.py
The numba_source.py looks something like
from numba.pycc import CC
cc = CC('my_module')
@cc.export('mul_f', 'f8(f8, f8)')
def mul(a, b):
return a*b
cc.compile()
and the setup.py looks something like this
import setuptools
from numpy.distutils.core import setup
from numba_project.src.numba_source import cc
setup(
name = 'my_numba_examples',
# other setup arguments,
ext_modules = [cc.distutils_extension()]
)
Now, when i build extension modules through the build_ext command, my extension module is built into the src/ folder. i.e.,
- numba_project/
- numba_project/
- __init__.py
- src/
- numba_source.py
- my_module.so
- lib/
- setup.py
But, I would like to build the extension into the lib/ folder. According to the reference manual, the numba AOT compiler provides the option to specify the output directory name and file name where the extension would be built, through the CC instance attributes output_dir and output_file respectively. But this works only if I compile the code myself by calling the CC function compile(). When the code is compiled by the setup.py, the output_dir and output_file attributes are to be ignored.
So, I currently am not able to specify the target directory for my extension. I tried the Python dotted name (which is the standard while creating a C or a Fortran extension as explained here) while naming the module, i.e., something like
cc = CC('numba_project.lib.my_module')
but I get the following error
ValueError: basename should be a simple module name, not qualified name
Any suggestions on how to build the module under a target directory when building the sources from setup.py would be appreciated. Thanks!