Hi Armin, Great thanks for the method! I had a try, but found it seemed only work for writing module tests, and failed for writing app level code for a new module.
Here are what we tried: In the new module __init__.py, we defined app level code: appleveldefs = { 'tid': 'app_wrap.tid' } And in app_wrap.py, we tried to use "thread.get_ident()" from builtin module's interperter code: class wrapAPI: spaceconfig = dict(usemodules=['thread']) def thread_wrap(self): import thread return thread.get_ident() w = wrapAPI() def tid(): print w.thread_wrap() Finally, we wrote a pytest to test the module: import pytest class AppTest: spaceconfig = dict(usemodules=['wrap']) def test_wrap(self): import wrap print wrap.tid() The pytest failed and reported the error: def test_wrap(self): import wrap > print wrap.tid() E (application-level) ImportError: No module named thread >From the experiment, we still could not import and use the builtin module's function for writing a new module. On Wed, Jun 3, 2015 at 2:49 PM, Armin Rigo <ar...@tunes.org> wrote: > Hi Yicong, > > On 3 June 2015 at 05:37, Yicong Huang <hengha....@gmail.com> wrote: > > We tried to import the module in app level code, but failed. > > That's how it is done in various modules. See for example > pypy/module/_collections/app_defaultdict. Maybe you wrote a test that > did you start with: > > class AppTestTestAPI: > spaceconfig = dict(usemodules=['modulename']) > > which is needed, otherwise the test runs in a configuration in which > the module is not present. > > > A bientôt, > > Armin. >
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev