[pypy-dev] Memap in numpypy

Amaury Forgeot d'Arc amauryfa at gmail.com
Sun Jun 16 21:29:06 CEST 2013


2013/6/16 Mike Beller <mike at tradeworx.com>

> Ok -- made some progress.  Built a unit test -- it's similar to the
> doctest from memmap.py, but rewritten in py.test format (uses
> BaseNumpyAppTest from pypy.module.micronumpy.test.test_base, just like
> test_numeric.py does).
>
> Here is the next problem I face:  To run my unit test, I added in an
> import of my new memmap.py, which I have placed in
> lib_pypy/numpypy/core/memmap.py, and linked into core/__init__.py.  This
> module imports mmap.py for obvious reasons (it wants to use mmap.py to
> create the mmap object).  That import fails when I run the test: python2.7
> pytest.py pypy/module/test_lib_pypy/numpypy/core/test_memmap.py ("Import
> error: no module named mmap")
>

great progress anyway!


> It fails because it can not import the module mmap.  Whereas if I just
> fire up a normal interpreter-level pypy I have no problem importing mmap.
>  Clearly it does exist in pypy.
>

> I don't understand which modules will be loadable and which modules will
> not be loadable when I run in pytest.py.  Somehow, clearly, the
> BaseNumpyAppTest inheritance mechanism has allowed all the numpypy stuff to
> show up (but only inside the class definition, not at module scope), but
> other pypy application-level modules are not available.  I need to somehow
> invoke the same magic for mmap if I want to be able to use the mmap module
> to implement the numpypy memmap functionality.    I read coding-guide.rst
> but it's still not obvious to me.  (Alternatively I suppose the answer
> could be full translation, but testing this way would take a full 90-minute
> translation every time I wanted to change a line of code.)
>

That's because most built-in modules are not made available by default. You
need to pass the equivalent of "--withmod-mmap" to the interpreter. In a
test, this is done in a statement like:
    spaceconfig = dict(usemodules=["mmap"])
at the top of the test class. There certainly is already one (in order to
import numpy), you could add "mmap" to the existing list.

>

>
> If you feel this detailed emailing is wasting your time, just let me know
> and I can drop it.   (Or if you want to take the conversation off pypy-dev
> that's ok too.)
>

You are welcome. PyPy is a wonderful platform with powerful tools, but they
are often not documented enough.
Pypy-dev traffic is not that high these days; to get immediate answers
there many of us are hanging on IRC: #pypy at freenode.net.

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


More information about the pypy-dev mailing list