[pypy-commit] pypy py3.5: _imp.load_dynamic => _imp.create_dynamic

arigo pypy.commits at gmail.com
Tue Aug 16 14:06:25 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r86224:e633a352e2f6
Date: 2016-08-16 12:18 +0200
http://bitbucket.org/pypy/pypy/changeset/e633a352e2f6/

Log:	_imp.load_dynamic => _imp.create_dynamic

diff --git a/pypy/module/imp/__init__.py b/pypy/module/imp/__init__.py
--- a/pypy/module/imp/__init__.py
+++ b/pypy/module/imp/__init__.py
@@ -12,7 +12,7 @@
 
         'get_magic':       'interp_imp.get_magic',
         'get_tag':         'interp_imp.get_tag',
-        'load_dynamic':    'interp_imp.load_dynamic',
+        'create_dynamic':  'interp_imp.create_dynamic',
         'create_builtin':  'interp_imp.create_builtin',
         'init_frozen':     'interp_imp.init_frozen',
         'is_builtin':      'interp_imp.is_builtin',
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -117,6 +117,13 @@
         space.sys.setmodule(w_mod)
     return w_mod
 
+def load_c_extension(space, filename, modulename):
+    from pypy.module.cpyext.api import load_extension_module
+    log_pyverbose(space, 1, "import %s # from %s\n" %
+                  (modulename, filename))
+    load_extension_module(space, filename, modulename)
+    # NB. cpyext.api.load_extension_module() can also delegate to _cffi_backend
+
 # __________________________________________________________________
 #
 # import lock, to prevent two threads from running module-level code in
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -50,17 +50,13 @@
         fd = space.int_w(space.call_method(w_iobase, 'fileno'))
         return streamio.fdopen_as_stream(fd, filemode)
 
- at unwrap_spec(filename='fsencode')
-def load_dynamic(space, w_modulename, filename, w_file=None):
+def create_dynamic(space, w_spec, w_file=None):
     if not importing.has_so_extension(space):
         raise oefmt(space.w_ImportError, "Not implemented")
-
-    # the next line is mandatory to init cpyext
-    space.getbuiltinmodule("cpyext")
-
-    from pypy.module.cpyext.api import load_extension_module
-    load_extension_module(space, filename, space.str_w(w_modulename))
-
+    w_modulename = space.getattr(w_spec, space.wrap("name"))
+    w_path = space.getattr(w_spec, space.wrap("origin"))
+    filename = space.fsencode_w(w_path)
+    importing.load_c_extension(space, filename, space.str_w(w_modulename))
     return importing.check_sys_modules(space, w_modulename)
 
 def create_builtin(space, w_spec):
diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py
--- a/pypy/module/imp/test/test_app.py
+++ b/pypy/module/imp/test/test_app.py
@@ -54,11 +54,13 @@
         finally:
             del sys.path[0]
 
-    def test_load_dynamic(self):
+    def test_create_dynamic(self):
         import imp
-        raises(ImportError, imp.load_dynamic, 'foo', 'bar')
-        raises(ImportError, imp.load_dynamic, 'foo', 'bar',
-               open(self.file_module))
+        class FakeSpec:
+            name = 'foo'
+            origin = 'this/path/does/not/exist'
+        raises(ImportError, imp.create_dynamic, FakeSpec())
+        raises(ImportError, imp.create_dynamic, FakeSpec(), "unused")
 
     def test_suffixes(self):
         import imp


More information about the pypy-commit mailing list