use importlib to load C extension modules for python 2.7 and newer
This commit is contained in:
parent
4890a70c37
commit
23d2eb555f
1 changed files with 10 additions and 1 deletions
|
|
@ -827,7 +827,16 @@ public:
|
|||
* isn't available in python 2.4 or earlier, so we have to write some
|
||||
* code conditional on the python version.
|
||||
*/
|
||||
Printv(f_shadow, "if version_info >= (2, 6, 0):\n", NULL);
|
||||
Printv(f_shadow, "if version_info >= (2, 7, 0):\n", NULL);
|
||||
Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
|
||||
Printv(f_shadow, tab8, "import importlib\n", NULL);
|
||||
Printv(f_shadow, tab8, "pkg = __name__.rpartition('.')[0]\n", NULL);
|
||||
Printf(f_shadow, tab8 "mname = '.'.join((pkg, '%s')).lstrip('.')\n",
|
||||
module);
|
||||
Printv(f_shadow, tab8, "return importlib.import_module(mname)\n", NULL);
|
||||
Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
|
||||
Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
|
||||
Printv(f_shadow, "elif version_info >= (2, 6, 0):\n", NULL);
|
||||
Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
|
||||
Printv(f_shadow, tab8, "from os.path import dirname\n", NULL);
|
||||
Printv(f_shadow, tab8, "import imp\n", NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue