Wednesday, February 20, 2008

Running Pyglet on PyPy

As part of our efforts of making PyPy's Python interpreter usable we put quite some effort into interfacing with external libraries. We were able, in quite a short amount of time (I think beginning really from Leysin sprint, or slightly earlier) to provide a prototype of the ctypes library. It is written in completely normal Python, at applevel, based on a very thin wrapper around the libffi library. This makes development a lot easier, but it makes the resulting ctypes implementation rather slow. The implementation is not complete yet and it will still need quite some effort to make it feature-complete (ctypes has lots of details and special cases and do-what-I-mean magic). Yet another point will be to make it faster, but that's for much later.
The implementation is good enough to run those parts of Pyglet that don't depend on PIL (which PyPy doesn't have). Here are a few pictures of running Pyglet demos on top of compiled pypy-c. To compile a version of PyPy that supports ctypes, use this highly sophisticated command line
./translate.py --gc=generation ./targetpypystandalone.py --allworkingmodules --withmod-_rawffi
Note: this works on linux only right now.
The list of missing small ctypes features is quite extensive, but I consider the current implementation to be usable for most common cases. I would love to hear about libraries written in pure python (using ctypes), to run them on top of PyPy and use them as test cases. If someone knows such library, please provide a link.

9 comments:

  1. This is very cool news indeed! The second screenshot seems to show a strange artefact though on the inside of the torus. Is that running the unmodified examples/opengl.py code, or has the example been modified to display a second torus? It should also be noted that pyglet is perfectly usable without PIL (as long as you have libgdk installed under Linux which almost everyone will do).

    ReplyDelete
  2. ps. it's "pyglet" with a little "p" :)

    ReplyDelete
  3. Very cool :)

    Here's two more ctypes things... which you probably know about already, but eh :)

    http://pyopengl.sf.net/
    http://www.pygame.org/ctypes/

    cu,

    ReplyDelete
  4. Congratulations from me!

    ReplyDelete
  5. hi illume,

    yep, we know about those, thank you anyway :-).

    Cheers,

    Carl Friedrich

    ReplyDelete
  6. Very exciting to see my humble 'triangles' pyglet demo being used in the blue colored screenshot. If anyone's interested, the code for that is here: http://tartley.com/?p=264

    I should remember to put an explicit CC license on my whole site.

    ReplyDelete
  7. http://utidylib.berlios.de/

    needs only ctypes, iirc.

    ReplyDelete
  8. Please try the ctypes-based pysqlite reimplementation at http://hg.ghaering.de/pysqlite3/

    It's meant to become the "sqlite3" module for PyPy.

    ReplyDelete
  9. Hi Gerhard,

    yip, we know about this sqlite implementation, thank you! We are already using it for our tests (and most of its tests already work).

    Cheers,

    Carl Friedrich

    ReplyDelete

See also PyPy's IRC channel: #pypy at freenode.net, or the pypy-dev mailing list.
If the blog post is old, it is pointless to ask questions here about it---you're unlikely to get an answer.