Author: Wim Lavrijsen <wlavrij...@lbl.gov> Branch: cppyy-packaging Changeset: r94498:4600e4a5a904 Date: 2018-05-07 19:25 -0700 http://bitbucket.org/pypy/pypy/changeset/4600e4a5a904/
Log: do not pull in the backend until the very last moment to prevent errors when importing _cppyy for doc purposes diff --git a/pypy/module/_cppyy/__init__.py b/pypy/module/_cppyy/__init__.py --- a/pypy/module/_cppyy/__init__.py +++ b/pypy/module/_cppyy/__init__.py @@ -22,7 +22,7 @@ } appleveldefs = { - '_init_pythonify' : 'pythonify._init_pythonify', + '_post_import_startup' : 'pythonify._post_import_startup', 'add_pythonization' : 'pythonify.add_pythonization', 'Template' : 'pythonify.CPPTemplate', } @@ -35,9 +35,3 @@ # code generation is not, so give it a chance to run now from pypy.module._cppyy import capi capi.register_pythonizations(space) - - def startup(self, space): - from pypy.module._cppyy import capi - capi.verify_backend(space) # may raise ImportError - - space.call_method(self, '_init_pythonify') diff --git a/pypy/module/_cppyy/capi/loadable_capi.py b/pypy/module/_cppyy/capi/loadable_capi.py --- a/pypy/module/_cppyy/capi/loadable_capi.py +++ b/pypy/module/_cppyy/capi/loadable_capi.py @@ -308,7 +308,7 @@ c_call = state.capi_calls[name] except KeyError: if state.backend is None: - load_backend(space) + verify_backend(space) iface = state.capi_call_ifaces[name] cfunc = W_RCTypeFunc(space, iface[0], iface[1], False) c_call = state.backend.load_function(cfunc, 'cppyy_'+name) diff --git a/pypy/module/_cppyy/pythonify.py b/pypy/module/_cppyy/pythonify.py --- a/pypy/module/_cppyy/pythonify.py +++ b/pypy/module/_cppyy/pythonify.py @@ -1,5 +1,5 @@ # NOT_RPYTHON -# do not load _cppyy here, see _init_pythonify() +# do not load _cppyy here, see _post_import_startup() import types import sys @@ -22,7 +22,7 @@ class CPPClass(CPPScope): pass -# namespace base class (class base class defined in _init_pythonify) +# namespace base class (class base class defined in _post_import_startup() class CPPNamespace(object): __metatype__ = CPPMetaNamespace @@ -407,7 +407,7 @@ pyclass.__len__ = return2 -def _init_pythonify(): +def _post_import_startup(): # _cppyy should not be loaded at the module level, as that will trigger a # call to space.getbuiltinmodule(), which will cause _cppyy to be loaded # at pypy-c startup, rather than on the "import _cppyy" statement diff --git a/pypy/module/_cppyy/test/test_advancedcpp.py b/pypy/module/_cppyy/test/test_advancedcpp.py --- a/pypy/module/_cppyy/test/test_advancedcpp.py +++ b/pypy/module/_cppyy/test/test_advancedcpp.py @@ -22,7 +22,8 @@ def setup_class(cls): cls.w_test_dct = cls.space.newtext(test_dct) cls.w_advanced = cls.space.appexec([], """(): - import ctypes + import ctypes, _cppyy + _cppyy._post_import_startup() return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) def test01_default_arguments(self): diff --git a/pypy/module/_cppyy/test/test_cpp11features.py b/pypy/module/_cppyy/test/test_cpp11features.py --- a/pypy/module/_cppyy/test/test_cpp11features.py +++ b/pypy/module/_cppyy/test/test_cpp11features.py @@ -14,7 +14,8 @@ def setup_class(cls): cls.w_test_dct = cls.space.newtext(test_dct) cls.w_example01 = cls.space.appexec([], """(): - import ctypes + import ctypes, _cppyy + _cppyy._post_import_startup() return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) def test01_shared_ptr(self): diff --git a/pypy/module/_cppyy/test/test_cppyy.py b/pypy/module/_cppyy/test/test_cppyy.py --- a/pypy/module/_cppyy/test/test_cppyy.py +++ b/pypy/module/_cppyy/test/test_cppyy.py @@ -33,6 +33,7 @@ cls.w_lib, cls.w_instantiate, cls.w_example01, cls.w_payload = \ cls.space.unpackiterable(cls.space.appexec([], """(): import _cppyy, ctypes + _cppyy._post_import_startup() lib = ctypes.CDLL(%r, ctypes.RTLD_GLOBAL) def cpp_instantiate(tt, *args): inst = _cppyy._bind_object(0, tt, True) diff --git a/pypy/module/_cppyy/test/test_crossing.py b/pypy/module/_cppyy/test/test_crossing.py --- a/pypy/module/_cppyy/test/test_crossing.py +++ b/pypy/module/_cppyy/test/test_crossing.py @@ -72,7 +72,9 @@ # to allow the generated extension module be loaded first) cls.w_test_dct = cls.space.newtext(test_dct) cls.w_pre_imports = cls.space.appexec([], """(): - import ctypes, _cppyy""") # prevents leak-checking complaints on ctypes' statics + import ctypes, _cppyy + _cppyy._post_import_startup()""") # early import of ctypes + # prevents leak-checking complaints on ctypes' statics def setup_method(self, func): @unwrap_spec(name='text', init='text', body='text') diff --git a/pypy/module/_cppyy/test/test_datatypes.py b/pypy/module/_cppyy/test/test_datatypes.py --- a/pypy/module/_cppyy/test/test_datatypes.py +++ b/pypy/module/_cppyy/test/test_datatypes.py @@ -14,7 +14,8 @@ def setup_class(cls): cls.w_test_dct = cls.space.newtext(test_dct) cls.w_datatypes = cls.space.appexec([], """(): - import ctypes + import ctypes, _cppyy + _cppyy._post_import_startup() return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) cls.w_N = cls.space.newint(5) # should be imported from the dictionary diff --git a/pypy/module/_cppyy/test/test_fragile.py b/pypy/module/_cppyy/test/test_fragile.py --- a/pypy/module/_cppyy/test/test_fragile.py +++ b/pypy/module/_cppyy/test/test_fragile.py @@ -14,7 +14,8 @@ def setup_class(cls): cls.w_test_dct = cls.space.newtext(test_dct) cls.w_fragile = cls.space.appexec([], """(): - import ctypes + import ctypes, _cppyy + _cppyy._post_import_startup() return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) def test01_missing_classes(self): diff --git a/pypy/module/_cppyy/test/test_operators.py b/pypy/module/_cppyy/test/test_operators.py --- a/pypy/module/_cppyy/test/test_operators.py +++ b/pypy/module/_cppyy/test/test_operators.py @@ -15,7 +15,8 @@ cls.w_N = cls.space.newint(5) # should be imported from the dictionary cls.w_test_dct = cls.space.newtext(test_dct) cls.w_operators = cls.space.appexec([], """(): - import ctypes + import ctypes, _cppyy + _cppyy._post_import_startup() return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) def teardown_method(self, meth): diff --git a/pypy/module/_cppyy/test/test_overloads.py b/pypy/module/_cppyy/test/test_overloads.py --- a/pypy/module/_cppyy/test/test_overloads.py +++ b/pypy/module/_cppyy/test/test_overloads.py @@ -17,7 +17,8 @@ def setup_class(cls): cls.w_test_dct = cls.space.newtext(test_dct) cls.w_overloads = cls.space.appexec([], """(): - import ctypes + import ctypes, _cppyy + _cppyy._post_import_startup() return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) def test01_class_based_overloads(self): diff --git a/pypy/module/_cppyy/test/test_pythonify.py b/pypy/module/_cppyy/test/test_pythonify.py --- a/pypy/module/_cppyy/test/test_pythonify.py +++ b/pypy/module/_cppyy/test/test_pythonify.py @@ -16,7 +16,8 @@ def setup_class(cls): cls.w_test_dct = cls.space.newtext(test_dct) cls.w_example01 = cls.space.appexec([], """(): - import ctypes + import ctypes, _cppyy + _cppyy._post_import_startup() return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) def test01_finding_classes(self): diff --git a/pypy/module/_cppyy/test/test_stltypes.py b/pypy/module/_cppyy/test/test_stltypes.py --- a/pypy/module/_cppyy/test/test_stltypes.py +++ b/pypy/module/_cppyy/test/test_stltypes.py @@ -15,7 +15,8 @@ cls.w_N = cls.space.newint(13) cls.w_test_dct = cls.space.newtext(test_dct) cls.w_stlvector = cls.space.appexec([], """(): - import ctypes + import ctypes, _cppyy + _cppyy._post_import_startup() return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) def test01_builtin_type_vector_types(self): diff --git a/pypy/module/_cppyy/test/test_templates.py b/pypy/module/_cppyy/test/test_templates.py --- a/pypy/module/_cppyy/test/test_templates.py +++ b/pypy/module/_cppyy/test/test_templates.py @@ -14,7 +14,8 @@ def setup_class(cls): cls.w_test_dct = cls.space.newtext(test_dct) cls.w_datatypes = cls.space.appexec([], """(): - import ctypes + import ctypes, _cppyy + _cppyy._post_import_startup() return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) def test01_template_member_functions(self): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit