Posts Tagged ‘google summer of code’

PyPy 2.5 features – news

Tuesday, May 13th, 2008

Changes! Now I’m free to work “full-time” on my GSoC project, last Friday was my last day on my old job (Ikwa) :-)

Today I’ve read lots of docs and code, specially the pyparser code. I’ll try to maintain a list of features I’m currently working on here.

Last week (ok, Friday before last Friday) we went to Werneck’s cave to code. One thing I’ve made there was implement the defaultdict object in the collections module. This module is written in C originally, so I needed to port it.

The code is relatively simple and I’ve just “copied” the C implementation (of course it’s clearer and more beautiful in Python :P ). Werneck also helped me with the pyparser but we couldn’t find a solution for supporting the full Python 2.5 Grammar .

Today I’ve worked on a small Python 2.5 change, the empty base classes list syntax.

Until Python 2.5 the list of base classes could not be empty. So you couldn’t define a class like:

class A():
    pass

The right way for doing this was

class A:
    pass

Now, in Python 2.5, both ways are legal.

Last week I’ve committed a slight changed Grammar for Python 2.5 syntax support to PyPy’s 2.5-features branch (the only change I’ve made was removing the support for the new import syntax, as it crashes the parser, I need to work on that).

With part of the 2.5 Grammar already supported, to support this new class definition syntax the only change needed was in pyparser (more specifically to the AST builder).

While the build_classdef method expected 4 atoms (< class keyword >, < white space >, < class name > and < comma >) or 7 (the same 4 plus < ( >, < base classes > and < ) > before the < comma >) in Python 2.4, now in Python 2.5 it can receive 6 atoms too (< class keyword >, < white space >, < class name >, < ( >, < ) > and < comma >). The change was really simple, but it was a good exercise for me because I could apply what I’m learning in my compilers classes at school (while reading the sources) :-)

Some code (pypy/interpreter/pyparser/astbuilder.py:634):

def build_classdef(builder, nb):
    ...
    if l == 4: # class NAME:
        basenames = []
        body = atoms[3]
    elif l == 6: # class NAME():  # 2.5
        basenames = []
        body = atoms[5]
    else:
        assert l == 7
        basenames = []
        body = atoms[6]
        base = atoms[3]
    ...

I don’t think I need to explain this code, it’s very simple (of course, it’s Python! :-) ).

I’ve made some tests and it seemed to work great, but I’ve decided to compare the bytecode generated by PyPy and by CPython (both 2.4 and 2.5). While in CPython 2.4 the statement “class A: pass” produces the following bytecode:

>>> from dis import dis; c = compile("class A: pass", "/dev/null", "exec"); dis(c)
  1           0 LOAD_CONST               0 ('A')
              3 BUILD_TUPLE              0
              6 LOAD_CONST               1 ()
              9 MAKE_FUNCTION            0
             12 CALL_FUNCTION            0
             15 BUILD_CLASS
             16 STORE_NAME               0 (A)
             19 LOAD_CONST               2 (None)
             22 RETURN_VALUE

CPython 2.5 produces for both statements (the old syntax and the new one) something slight different:

>>> from dis import dis; c = compile("class A: pass", "/dev/null", "exec"); dis(c)
  1           0 LOAD_CONST               0 ('A')
              3 LOAD_CONST               3 (())
              6 LOAD_CONST               1 ()
              9 MAKE_FUNCTION            0
             12 CALL_FUNCTION            0
             15 BUILD_CLASS
             16 STORE_NAME               0 (A)
             19 LOAD_CONST               2 (None)
             22 RETURN_VALUE

The only difference between 2.4 and 2.5 is the instruction BUILD_TUPLE in 2.4 against the LOAD_CONST in 2.5. I'm not a bytecode expert, but it seems that this is an optimization, of course I may be completely wrong :P

Well, as I expected the bytecode produced by PyPy is identical the one produced by CPython 2.4, so I think I have more things to change to complete this task. ;)

But not tonight, after 14 hours of PyPy code reading and some debugging (plus Linear Programming and Computer Theory classes) I think I should sleep.

:-)

Python friends meeting

Monday, May 5th, 2008

Last Friday, me, Luciano Pacheco and Marcelo Honório went to Pedro Werneck‘s house (or werneck’s cave) to talk, eat and, of course, code python :-)

We wrote a small guide (portugues only, sorry… I promise i’Il translate it to English) about preparing the environment for those who want to participate of the PythonBugDay (or even for the curious who want to play with the cpython code).

Of course I’ve worked on my GSoC project implementing the new (2.5) “defaultdict” object (in the collections module), but this is subject of another post :-)

Werneck and Pacheco also worked on some issues/bugs listed in the CPython bugtracker and I’ve introduced them to PyPy (and vice-versa hehe).

After all this coding we ate Japanese food and our friend Andrews suggested a new kind of development method, Sushi-Driven Development… nice! :)

Supporting Python 2.5 features in PyPy – GSoC 2008

Tuesday, April 22nd, 2008

As you probably know my GSoC proposal to work on PyPy interpreter, supporting the Python 2.5 features, has been accepted. This post is a short explanation of my Google Summer of Code project.

PyPy

The PyPy project aims at producing a flexible and fast Python implementation. The guiding idea is to translate a Python-level description of the Python language itself to lower level languages. Rumors have it that the secret goal is being faster-than-C which is nonsense, isn’t it?

PyPy is divided into the python interpreter and the translator framework. The interpreter is written in RPython (a subset of Python) and the main goal is to provide an easy-to-hack (for python programmers ;) ) Python interpreter.

PyPy’s interpreter currently supports only a few features introduced in Python 2.5, like __index__ (for slicing) and some part of the ‘with’ statement. Also, the 2.5 changes to the language and to the standard library have not been ported yet (although some have been, like the ctypes).

Goal

This proposal idea is to bring Python 2.5 features and changes to PyPy interpreter, this includes porting the modules and writing code for the features it self.

Here are some of the features I’ll work on:

  • PEP 308: Conditional Expressions[*]
  • 328: Absolute and Relative Imports
  • PEP 342: New Generator Features
  • PEP 343: The with statement[*]
  • PEP 352: Exceptions as New-Style Classes

[*] part of this features are already supported by PyPy

Benefits

With support to 2.5 features and changes more the PyPy interpreter will be up-to-date so people who wants to use this features can be happy using PyPy. This probably means more people using PyPy (i hope!) :-)

Why this project?

The first reason I’ve chosen the PyPy project is that I really like their ideas and goals. I was looking for collaborating to it in some way for a long time, but it took me some time to read the docs and to really understand the project.

As I like PyPy ideas and I’m starting to plan my graduation project/bachelor’s thesis, my work on PyPy interpreter will be a big part of it. Maybe I can explain my ideas in another post :-)

I would like to thank Google (and the SoC folks), Python Software Foundation, PyPy and specially to Carl Friedrich Bolz* who will be my GSoC mentor and Leonardo Santagada who helped me to understand PyPy and to write my application.

* morepypy is a blog where PyPy developers talk to the community, it’s not Carl’s personal blog.

Thanks to my friends from Python Brasil community too.

Approved in GSoC

Monday, April 21st, 2008

As mentioned before I’ve applied to GSoC to work on PyPy for the Python Software Foundation.

Today I’m very happy to say that my project got approved and I will work on PyPy interpreter the next three months. It means that a lot of PyPy posts are coming, and the first one will be a introduction to the project, what is PyPy, the interpreter and the translation framework :)

Stay tuned if you are interested in PyPy! Congratulations to everybody that have applied to GSoC this year =)

Google Summer of Code 2008: deadline for applications extended

Monday, March 31st, 2008

For those who were thinking to apply to GSoC, good news and no more excuses, the student applications open and deadline have been extended by one week. The deadline now is Monday – Jan 7th.

If you are applying, stay tunned to the official calendar and good luck!

Google Summer of Code 2008

Wednesday, March 26th, 2008

Well, it’s time for students to apply for Google Summer of Code.

What is GSoC ?

You can read about GSoC in their website, but I will try to resume here what is GSoC.

Google pays you (a student) US$ 4500,00 for three months of work on a free/open source software.

First the organizations apply for GSoC as a mentoring organization. Each organization accepted by Google receive slots and distribute this slots in project ideas.

Then the student find a mentoring organization, choose a project (or propose a new one) and asks for a mentor (applying). The organization will choose the students and then monitor the student work. Note that a student can apply for 20 projects but if approved in more than one he will need to choose only one to work.

The student will receive from Google US$ 500,00 when the program starts, then US$ 2000,00 after a month of work and US$ 2000,00 when the program finishes. Obviously the mentor will check the student process/work and decide if he should receive the money or not.

When the student finishes the program, he receives a GSoC t-shirt and a Google certificate (nice! :) ).

Benefits

For students (like me):

  • Contribute do free/open source software
  • Learn and gain experience
  • Get paid to code free/open source software
  • A beautiful t-shirt :)
  • think about your new job offers … :P

For organizations (like Python Software Foundation):

  • More people involved in the development process
  • People getting paid to develop needed features

I’m applying for BlueZ, the project idea is simple, build a high-level interface/layer upon python-dbus to provide the services/interfaces offered by BlueZ by D-Bus.

I’ll probably try to apply to OLPC as well.

I’m also applying (maybe too late) for Python Software Foundation to work on PyPy. The project idea is to support CPython 2.5 features and changes missing in PyPy.

For more information in GSoC I recommend watching this screencast by Titus Brown.

That’s all.