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.
Currently
load_lib()relies on being passed apkgargument, 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 fromimportlib.import_module():Maybe it doesn't make sense to allow use of
load_lib()by non-packages, because there's the generated_mylib.pyfile and maybe a_build_mylib.pytoo. 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.