Fix for running 'python -m' when using swig -builtin

Same as e05b5ea for -builtin.

Also added runtime tests to check 'python -m'.
This commit is contained in:
William S Fulton 2018-12-04 19:12:13 +00:00
commit 604ae7186b
17 changed files with 155 additions and 9 deletions

View file

@ -734,7 +734,7 @@ public:
*
*/
Printf(default_import_code, "\n# Pull in all the attributes from %s\n", module);
Printv(default_import_code, "if __name__.rpartition('.')[0] != '':\n", NULL);
Printv(default_import_code, "if __package__ or __name__.rpartition('.')[0]:\n", NULL);
Printv(default_import_code, tab4, "try:\n", NULL);
Printf(default_import_code, tab4 tab4 "from .%s import *\n", module);
Printv(default_import_code, tab4 "except ImportError:\n", NULL);