Author: Antonio Cuni <[email protected]>
Branch: dummy-importlib2
Changeset: r98337:ad9feca07a5b
Date: 2019-12-18 17:44 +0100
http://bitbucket.org/pypy/pypy/changeset/ad9feca07a5b/
Log: start a branch in which to introduce a _dummy_importlib module:
currently, all applevel tests use _frozen_importlib for importing,
but since it is written at applevel it's utterly slow. The goal is
to write a minimal replacement which works for 90% of the cases and
it's much faster, to speed up tests. For the remaining 10% of the
cases, individual tests can specify to use _frozen_importlib
explicitly
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -14,9 +14,12 @@
and p.join('__init__.py').check()
and not p.basename.startswith('test')]
+# _dummy_importlib is automatically removed when you specify
+# --importlib=_frozen_importlib, which is the default when translating
essential_modules = set([
"exceptions", "_io", "sys", "builtins", "posix", "_warnings",
- "itertools", "_frozen_importlib", "operator", "_locale", "struct",
+ "itertools", "operator", "_locale", "struct",
+ "_dummy_importlib",
])
if sys.platform == "win32":
essential_modules.add("_winreg")
@@ -103,6 +106,8 @@
'cpyext': [('objspace.usemodules.array', True)],
'_cppyy': [('objspace.usemodules.cpyext', True)],
'faulthandler': [('objspace.usemodules._vmprof', True)],
+ '_dummy_importlib': [('objspace.usemodules._frozen_importlib', False)],
+ '_frozen_importlib': [('objspace.usemodules._dummy_importlib', False)],
}
module_suggests = {
# the reason you want _rawffi is for ctypes, which
diff --git a/pypy/goal/targetpypystandalone.py
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -268,6 +268,10 @@
# expose the following variables to ease debugging
global space, entry_point
+ # the default is _dummy_importlib for tests, but we really want
+ # _frozen_importlib when translating
+ config.objspace.usemodules._frozen_importlib = True
+
if config.objspace.allworkingmodules:
from pypy.config.pypyoption import enable_allworkingmodules
enable_allworkingmodules(config)
@@ -413,4 +417,3 @@
ns['get_gchooks'] = self.get_gchooks
PyPyTarget().interface(globals())
-
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -671,7 +671,10 @@
self.fromcache(State).build_api()
self.getbuiltinmodule('sys')
self.getbuiltinmodule('_imp')
- self.getbuiltinmodule('_frozen_importlib')
+ if self.config.objspace.usemodules._frozen_importlib:
+ self.getbuiltinmodule('_frozen_importlib')
+ if self.config.objspace.usemodules._dummy_importlib:
+ self.getbuiltinmodule('_dummy_importlib')
self.getbuiltinmodule('builtins')
for mod in self.builtin_modules.values():
mod.setup_after_space_initialization()
diff --git a/pypy/module/_dummy_importlib/__init__.py
b/pypy/module/_dummy_importlib/__init__.py
new file mode 100644
diff --git a/pypy/module/_dummy_importlib/interp_import.py
b/pypy/module/_dummy_importlib/interp_import.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_dummy_importlib/interp_import.py
@@ -0,0 +1,10 @@
+from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.error import OperationError
+
+
+@unwrap_spec(name='text0', level=int)
+def importhook(space, name, w_globals=None,
+ w_locals=None, w_fromlist=None, level=-1):
+ return space.w_None
+
+importhook = interp2app(importhook, app_name='__import__')
diff --git a/pypy/module/_dummy_importlib/moduledef.py
b/pypy/module/_dummy_importlib/moduledef.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_dummy_importlib/moduledef.py
@@ -0,0 +1,20 @@
+from pypy.interpreter.mixedmodule import MixedModule
+from pypy.module._dummy_importlib import interp_import
+
+class Module(MixedModule):
+ interpleveldefs = {
+ }
+
+ appleveldefs = {
+ }
+
+ def install(self):
+ """NOT_RPYTHON"""
+ super(Module, self).install()
+ self.w_import = self.space.wrap(interp_import.importhook)
+
+ def startup(self, space):
+ """Copy our __import__ to builtins."""
+ # use special module api to prevent a cell from being introduced
+ self.space.builtin.setdictvalue_dont_introduce_cell(
+ '__import__', self.w_import)
diff --git a/pypy/module/_dummy_importlib/test/__init__.py
b/pypy/module/_dummy_importlib/test/__init__.py
new file mode 100644
diff --git a/pypy/module/_dummy_importlib/test/test__dummy_importlib.py
b/pypy/module/_dummy_importlib/test/test__dummy_importlib.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_dummy_importlib/test/test__dummy_importlib.py
@@ -0,0 +1,10 @@
+from pypy.tool.pytest.objspace import gettestobjspace
+
+def test_default_is_dummy_importlib():
+ space = gettestobjspace()
+ assert space.config.objspace.usemodules._dummy_importlib
+ assert not space.config.objspace.usemodules._frozen_importlib
+ #
+ space = gettestobjspace(usemodules=['_frozen_importlib'])
+ assert not space.config.objspace.usemodules._dummy_importlib
+ assert space.config.objspace.usemodules._frozen_importlib
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit