[pypy-dev] How to use interperter level code from a module for app level code in another module

Amaury Forgeot d'Arc amauryfa at gmail.com
Tue Jun 9 11:39:00 CEST 2015


2015-06-09 11:34 GMT+02:00 Yicong Huang <hengha.mao at gmail.com>:

> No, I' am trying to call interp code from app code, and found the module
> could not be imported:
>
> import select     =>  ImportError: No module named select
> import pypy.module.select     =>ImportError: No module named pypy
>

"import select" is the one which should work at applevel.
But for this, the PyPy object space must have the option "spaceconfig =
dict(usemodules=['select'])", or be translated with --withmod-select.
In which context are you running the code above?


>
> But __pypy__ module is able to be imported.
>

some modules are always selected: sys, posix, __pypy__... that's why you
see a difference here.
Put usemodules=['select'], somewhere.



>
> On Tue, Jun 9, 2015 at 5:27 PM, Amaury Forgeot d'Arc <amauryfa at gmail.com>
> wrote:
>
>> 2015-06-09 11:15 GMT+02:00 Yicong Huang <hengha.mao at gmail.com>:
>>
>>> Great thanks!
>>> "posix" module is a good example. But this interp code reference is in
>>> the same module.
>>>
>>> How about a new module's app code to use interp code from other module?
>>> One method to follow "posix" example is to define interp code in the
>>> same module and wrap the interp function from other module for app code in
>>> the same module to use.
>>>
>>
>> This is not clear to me.
>> Are you trying to call interp code from interp code? Then just import the
>> interp module (pypy.module.xxx.yyy)
>>
>>
>>>
>>> But I observed __pypy__ module is different. Interp functions of _pypy_
>>> module could be directly import in app code for other modules.
>>> We are curious how does it work?
>>>
>>>
>>>
>>> On Tue, Jun 9, 2015 at 4:25 PM, Amaury Forgeot d'Arc <amauryfa at gmail.com
>>> > wrote:
>>>
>>>> 2015-06-09 10:20 GMT+02:00 Yicong Huang <hengha.mao at gmail.com>:
>>>>
>>>>> "The interpreter gateway has more options for exposing interp-level
>>>>> functions and types to app-level​."
>>>>>
>>>>> How does this work?
>>>>> We tried several builtin modules, as well as "select" module that you
>>>>> mentioned, all thses modules's interp-level code are invisble to other
>>>>> module's app-level.
>>>>>
>>>>> We would like to take your advices to make a new module. But the
>>>>> problem is how to make the new module's interp-level code visible to
>>>>> app-level?
>>>>>
>>>>
>>>> See the "posix" module for example. Most functions are defined at
>>>> interp-level,
>>>> but there is also a file "app_posix.py" which just does "import posix"
>>>> and happily calls interp-level code.
>>>>
>>>>
>>>>
>>>>>
>>>>>
>>>>> On Tue, Jun 9, 2015 at 9:30 AM, William ML Leslie <
>>>>> william.leslie.ttg at gmail.com> wrote:
>>>>>
>>>>>> On 8 June 2015 at 21:22, Yicong Huang <hengha.mao at gmail.com> wrote:
>>>>>>
>>>>>>> By reading modules in pypy/module, finally we found out the
>>>>>>> workaround method.
>>>>>>>
>>>>>>> For most of modules in 'pypy/module', their interp code could not be
>>>>>>> imported or used by other module's app code.
>>>>>>> But there is special module '__pypy__', it exposed several interp
>>>>>>> functions, and those code are used by other module's app code.
>>>>>>>
>>>>>>
>>>>>> ​There's nothing special about __pypy__ for exposing interp-level
>>>>>> code, the modules in pypy/modules​ usually include interp level code.
>>>>>>
>>>>>> ​For example, the select module exposes the interp-level function
>>>>>> select_interp.select.  Here's how it does so:
>>>>>>
>>>>>>>>>>>> https://bitbucket.org/pypy/pypy/src/b0c01840baea472c834635de627bb596c05d3bd5/pypy/module/select/__init__.py?at=default
>>>>>>
>>>>>> The interpreter gateway has more options for exposing interp-level
>>>>>> functions and types to app-level​.
>>>>>>
>>>>>> The workaround solution is simple: add one more interface in __pypy__
>>>>>>> module's __init__.py
>>>>>>>
>>>>>>
>>>>>> ​You should make a new module rather than adding to one existing one.​
>>>>>>
>>>>>>
>>>>>>>  PYC_MAGIC = get_pyc_magic(self.space)
>>>>>>
>>>>>>  self.extra_interpdef('PYC_MAGIC', 'space.wrap(%d)' % PYC_MAGIC)
>>>>>>
>>>>>>
>>>>>>> Are the above code do the magic thing to expose interp code?
>>>>>>>
>>>>>>
>>>>>> ​They are exposing an integer value called PYC_MAGIC, which is the
>>>>>> value for determining what python the .pyc file was compiled for.​
>>>>>>
>>>>>> ​This is about exposing an integer rather than a function, it's
>>>>>> probably not relevant to you.
>>>>>>
>>>>>>
>>>>>> --
>>>>>> William Leslie
>>>>>>
>>>>>> Notice:
>>>>>> Likely much of this email is, by the nature of copyright, covered
>>>>>> under copyright law.  You absolutely MAY reproduce any part of it in
>>>>>> accordance with the copyright law of the nation you are reading this in.
>>>>>> Any attempt to DENY YOU THOSE RIGHTS would be illegal without prior
>>>>>> contractual agreement.
>>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> pypy-dev mailing list
>>>>> pypy-dev at python.org
>>>>> https://mail.python.org/mailman/listinfo/pypy-dev
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Amaury Forgeot d'Arc
>>>>
>>>
>>>
>>
>>
>> --
>> Amaury Forgeot d'Arc
>>
>
>


-- 
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20150609/06a198e1/attachment-0001.html>


More information about the pypy-dev mailing list