Archive for the ‘free software’ Category
Friday, September 5th, 2008
Playing with the new Django features, specially with the NewForms-Admin, I was looking for a way to change the add view behavior for some models.
It’s really easy and obvious (it’s always easy and obvious with Python and Django).
First, you’ll need the admin.py file in your app directory.
from django.contrib import admin
from myproject.myapp.models import MyModel
class MyModelAdmin(admin.ModelAdmin):
def add_view(self, request):
if request.method == 'POST':
# do whatever you want
# remember, POSTing means that someone entered data.
return admin.ModelAdmin.add_view(self, request)
admin.site.register(MyModel, MyModelAdmin)
The add_view method is called when you try to add an entry using the admin. There are other interesting methods you should look too, for customizing the admin behavior (change_view, delete_view, etc).
Another way to customize things is to write your own ModelForm, but it’s beyond the scope of this post
Tags: add_view, admin, customize, django, newforms, newforms-admin, python
Posted in coding, free software, python | No Comments »
Thursday, September 4th, 2008
I’m not crazy at all. (yet)
Thanks to Google (I think specially to Rodolpho) DjangoCon will be transmitted to Google’s Office in São Paulo while the conference is held in Mountain View.
Cool
I’m definitively going! So, Saturday and Sunday (September 6th and 7th) @ Google’s Office, see you there!
Tags: django, djangocon, google, python
Posted in coding, free software, python | No Comments »
Thursday, August 28th, 2008
Last week I did some fixes to PyPy 2.5-features branch because the translator was crashing. That’s because some of the code I wrote in the last four months were not RPython.
The changes were mostly to help the annotator (with assertions). Now you can have a pypy-c with full 2.5 support.
There are some bugs so stdlib may not be fully working. I’m working on that.
svn co http://codespeak.net/svn/pypy/branch/2.5-features/ pypy-2.5-features
cd pypy-2.5-features/pypy/translator/goal/
python translate.py targetpypystandalone --allworkingmodules
# wait........
./pypy-c
Please, read PyPy’s documentation on translating and if you find any problem while translating let me know. Note that this docs are for the trunk so some of the options may not be available in 2.5-features branch.
I wrote this post last week and it was in my drafts. Actually I fixed some other bugs (one related to PEP 352) and it seems that my changes broke the translator again. Talking in #pypy Armin said that this is probably a bug in the annotator. I don’t know much about the translation process or about the annotator… I guess it’s time to start looking at it
Tags: 2.5-features, pypy, pypy-c, translate
Posted in coding, computer science, free software, pypy, python | No Comments »
Thursday, August 28th, 2008
After months postponing I’ve installed Gentoo in my laptop. I really like portage and probably everything I know about configuring linux using /etc and a bunch of commands I know because of gentoo.
The first time I installed Gentoo it I had a copy of the Gentoo Handbook and that was it. No internet connection to help. It was a great experience and I’ve learned a lot about how linux works internally. Before Gentoo I was using Fedora Core 2.
After those days I decided that I should became a programmer and not a sysadmin, so I did it, and I decided to install Ubuntu… now after two years using Ubuntu I’m back to Gentoo.Things are different of course. The installation process is easier (with a graphical interface LiveCD!). But, it’s nice to decide what I want to install and have full (or almost full?) control of my machine again!
Well.. let me go back to work, portage just finished to compile…
Tags: compile, fedora, gentoo, linux, portage, ubuntu
Posted in free software, gnu/linux | 1 Comment »
Saturday, August 9th, 2008
This year’s PyConBrasil will be held at Universidade Veiga de Almeida, Rio de Janeiro – RJ. I’m definitely going! Last year’s PyConBrasil was great.
So, if you are in Brazil or planning come near September 18th, 19th and 20th, don’t miss the chance to meet the awesome guys from Python Brasil community
Tags: pyconbrasil, python, pythonbrasil, rio, uva
Posted in coding, computer science, free software, python | 1 Comment »
Wednesday, August 6th, 2008
A little late I know.
This week I finished to fix all the failing tests and to implement PEP 328 (Absolute/Relative import).
Now it’s the final step for supporting Python2.5 on PyPy, to port the standard library.
I’m starting with it today and I really hope I can finish it all (including tests and everything else) until the end of next week.
Well, one more time, if anyone want to help me, test your python programs (specially the ones that use python2.5 specific features, like with statement, conditional expressions and new generator stuff) in PyPy-2.5-features (svn co http://codespeak.net/svn/pypy/2.5-features pypy-2.5-features).
How to test? Simple:
$ cd pypy-2.5-features
$ ./bin/py.py your_python_program.py
Be careful and patient, it may take a little bit to things start happening
Of course you can translate PyPy using the translator if you want. Take a look at PyPy’s website for more information.
Tags: 2.5-features, gsoc, import, pep, pep328, pypy, status report, stdlib
Posted in coding, computer science, free software, pypy, python | 1 Comment »
Friday, July 18th, 2008
Here comes another GSoC status update
Some finished tasks:
- throw() method on generators
- close() method…
- faking 2.5 behavior for IMPORT_NAME and IMPORT_FROM opcodes
- changing the default value for magic attribute of PyCode objects
- changing the magic number that goes in .pyc files compiled by PyPy
- fixing tests and more tests…
From those changes the only one I would like to comment is the change of both magic numbers.
First, they have different values and meanings in PyPy. The magic number for .pyc files (defined in pypy/modules/__builtin__/importing.py) is the number that identifies the bytecode “version”. It’s used to know if the interpreter should use the .pyc file or should recompile the .py. PyPy’s value is different from CPython’s one. As we are changing some opcodes (as IMPORT_NAME, mentioned before) this number had to be changed. The old value in PyPy was 1024 (or 1024 + 2 or 1024 + 4 or 1024 + 2 + 4, depending on some command line options), the new value is 1034 (or ….). We are just using the same policy CPython uses to change the value, add 10 to the old value.
Now the PyCode magic attribute. This value is the CPython magic number (the one explained above)., the old default value was the value from CPython 2.4 (62021). Some checks against this value are made through the code to decide if the bytecode should be interpreted one way or another. One example is the IMPORT_NAME opcode. In Python 2.4 IMPORT_NAME did not have the level parameter, this parameter is new in 2.5 because of the absolute import feature. So if the bytecode represented by a PyCode object is 2.4, when we visit a import statement we should not try to pop the level value from the stack (because it’s not there), but if it is 2.5 we should! So we check the magic value. The problem is, the default value was 2.4 but we changed the opcodes to behave like 2.5, so those checks were not working. The solution was to change the magic default value to 63231 (2.5c2 value I think), so now our bytecode interpreter is (almost?) compatible with 2.5 bytecode. And our compiler is generating 2.5 compatible bytecode as well.
Tags: gsoc, import, magic number, opcodes, pyc, pycode, pypy, python, status update
Posted in coding, computer science, free software, pypy, python | No Comments »
Monday, July 7th, 2008
After two weeks without any writing, here comes another status update of my GSoC (and I promise I’ll do it more frequently).
Today I’m working on PEP 342 – “Coroutines via Enhanced Generators”. I’ve finished to implement the .send() method and all the stuff it should do “behind the scenes” (e.g. push the value into the frame stack).
Last week some other PEPs and small changes were supported as well.
PEPs 308 (conditional expressions) and 343 (with statement) were already supported, I just needed to write tests and remove a SyntaxWarning for conditional expressions. PEP 352 (BaseException and raise “string”) is now supported as well.
Some changes were made to Grammar2.5 because pyparser could not read it the right way. Those changes were already present to Grammar2.4. The main problem is that when the parser finds a rule that has alternatives (like, ‘is’ | ‘is’ ‘not’ ) and the first alternative matches (imagine it trying to match ‘is not’, it will match ‘is’) it doesn’t look for the other alternatives and then fails (because there is no rule that matches a ‘not’ after an ‘is’). The solution in that case is to change the order (which doesn’t make much sense, before looking the parser’s code), so the rule should be ‘is’ ‘not’ | ‘is’.
Next steps: check PyCode magic number and finish PEP 342
Tags: gsoc, peps, pypy, python
Posted in coding, free software, pypy, python | No Comments »
Thursday, June 19th, 2008
This weekend (Jun 21st and 22nd) will happen (again) the Global Python Sprint Weekend and one more time our Python User Group (GruPy-SP) will meet to work together.
Our meeting will be held at Google’s São Paulo Office. Thanks Rodolpho and Google
If you are in São Paulo you can take a look at our wiki (portuguese only) to see how you can join us. If you are not in São Paulo but in Brazil visit the PythonBugDay page to see if anyone in your town is organizing a meet too
Tags: google office, grupy-sp, grupysp, python, pythonbrasil, pythonbugday, são paulo, sprint
Posted in coding, free software, python | 1 Comment »
Wednesday, June 18th, 2008
After almost three weeks (more?) I’m back
Well, this week I’ve fixed two small 2.5 features in PyPy.
The first one was UnicodeWarning. From Python’s docs:
…UnicodeWarning is triggered when you attempt to compare a Unicode string and an 8-bit string that can’t be converted to Unicode using the default ASCII encoding…
In PyPy to trigger a Warning when in Interpreter-level you can use the method space.warn, this method, internally, will use the warnings module to trigger the warning properly.
The second was ImportWarning. Again from Python’s docs:
ImportWarning warning is triggered when an import would have picked up a directory as a package but no __init__.py was found
After searching for a while I’ve found the pypy/lib/__buitins__/importing.py file that holds, obviously, pypy importing stuff. I’ve looked to CPython’s implementation to see when I should trigger the ImportWarn and load_part() seemed to be the right place.
The ImportWarning should be silently ignored unless you provide the -Wd command line option but PyPy does not accept the -W option, so I’ve implemented it. It is simple, you just need to append the argument (‘d’ in this case) to the sys.warnoptions list.
While working on this issues I’ve found a bug in the parser when using the 2.5 Grammar. It is raising a SyntaxError when you call a function passing a keyword argument (like f(x=3)). Because of this (and other small bugs) I’ve decided that I will work on the pyparser to make it compatible with the 2.5 Grammar now.
Tags: gsoc, pyparser, pypy, python, warnings
Posted in coding, computer science, free software, pypy, python | No Comments »