mabuchilab / NiceLib

A Python package for rapidly developing "nice" bindings for C libraries, using cffi
GNU General Public License v3.0
24 stars 8 forks source link

Figure out `load_lib()` package-related behavior #4

Open natezb opened 7 years ago

natezb commented 7 years ago

Currently load_lib() relies on being passed a pkg argument, typically the __package__ attribute of the file from which it's being called. However, this is the empty string for standalone modules. Currently, this results in a confusing error message coming from importlib.import_module():

TypeError: the 'package' argument is required to perform a relative import for '._mylib'.

Maybe it doesn't make sense to allow use of load_lib() by non-packages, because there's the generated _mylib.py file and maybe a _build_mylib.py too. However, if this is the case, we should provide an error message that makes this clear, and probably a note about this in the docs somewhere.

We may also want to provide a way for the user to modify where load_lib() looks for the generated files.