Commit a5854d2b authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

builtinimport: Add basic support for namespace packages.

That was easy - just avoid erroring out on seeing candidate dir for namespace
package. That's far from being complete though - namespace packages should
support importing portions of package from different sys.path entries, here
we require first matching entry to contain all namespace package's portions.

And yet, that's a way to put parts of the same Python package into multiple
installable package - something we really need for *Micro*Python.
parent 75ffcaea
......@@ -292,11 +292,10 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
vstr_add_str(&path, "");
if (mp_import_stat(vstr_str(&path)) != MP_IMPORT_STAT_FILE) {
vstr_cut_tail_bytes(&path, sizeof("/") - 1); // cut off /
"Per PEP-420 a dir without (%s) is a namespace package; "
"namespace packages are not supported", vstr_str(&path)));
printf("Notice: %s is imported as namespace package\n", vstr_str(&path));
} else {
do_load(module_obj, &path);
do_load(module_obj, &path);
vstr_cut_tail_bytes(&path, sizeof("/") - 1); // cut off /
// "Specifically, any module that contains a __path__ attribute is considered a package."
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment