Avoid python pitfalls and be happy
Posted by Gabriel Falcão - 21/01/10 at 08:01:43 amThis morning I was just reading the feed, when I stumbled on this post about one of the weird behaviors of lists in Python.
In a few words, lists and dictionaries behave like C pointers, thus they are mutable objects.
So, if you are beginning on python, you probably will like those articles:
Hope it helps
Introducing Sponge, a python web framework aimed on testing
Posted by Gabriel Falcão - 01/09/09 at 11:09:18 pm
Some time ago, a friend of mine created a cherrypy-based continuous integration application, we both work with Django, but we think that its stack is too big for simple web projects, specially when we do not need to access SQL databases.
More on Django
In adition, I think that Django-powered applications are hard to make unit tests, mostly related to the fact that models, templates and other django helpers need the DJANGO_SETTINGS_MODULE environment variable set, which turn its tests wired.
We have created a few patterns to make Django projects unit-testable, but it is for another post
Are you trying to say that Django is not a good framework ?
Nope! I work with Django, and I just LOVE Django, that is a great framework. Its models, forms, and everything else are awesome, and help me to write web applications without much effort, thus keeping high level of quality.
So, why did you create another framework ?
As I’ve just said some posts ago, I really enjoy agile, and I use to write simple web applications that does not demand the whole Django stack, and I need to have agility to write my tests.
CherryPy is a good solution for me, I don’t want another huge-ish framework, even if its based on cherrypy. I just need a few helpers functions, and a pattern to follow.
Idealizing sponge
Bernardo and me wrote a few web applications with cherrypy, and always focusing in TDD, we needed to create some helper classes to cherrypy. Sometime after, we figured out that those helpers could be grouped in a simple library, or a kind of tiny framework.
I started some mashups, and Sponge has been developed.
The name comes from the fact that a sponge can be used to dry stuff. We like the concept of DRY, hence the name
Sponge has been developed with TDD, but that is not all.
I’m trying to keep 100% of code coverage in both unit + functional tests, at minimum. It’s because 100% of coverage does not assure that the code works. Lines of code can be covered with some tests, but the same lines can have one or more different behaviours that won’t be found with 100% of coverage.
Principles
- Help and incentivate developer to write unit and functional tests
- Less friction as possible
- Be simple to configure
- Be simple to deploy
- Be 100% testable, specially with unit tests
- Provide pretty URLS through a rails-like syntax
- Be as most compliant as possible, with package-systems, such as APT
- Free software (LGPL-3)
- Comes with jQuery javascript library and 960 grid system
- Fun to use
Hands on!
Installing
If you are using Debian Unstable, just run:
sudo aptitude install python-sponge
If not, you will need, unfortunately, to use setuptools:
In this case, just grab the bleeding edge version through git:
git clone git://github.com/gabrielfalcao/sponge.git
Or just the latest stable relase:
Extract, if needed, and run:
sudo python setup.py install
Tutorial
Sponge comes with a simple tutorial within its documentation, but you can access it online
Emacs + Snippets
Posted by Gabriel Falcão - 16/08/09 at 11:08:16 pmPeople use to joke on me about the fact that I use EMACS, some say that I even need to use my toes to acomplish EMACS commands, and so on…
But I keep being even more productive, and every day I figure out new ways to improve it.
I really use EMACS the whole day, I keep editing anything with this awesome editor.
This weekend I was starting a new project, and as I use to, I was needing to repeat the same GPL headers at every file.
So I found myself questioning if it could be more productive than inserting rough templates on my files.
Then I found out this yasnippet, which is totally awesome, and made me be even more productive.
For those who also like emacs, I share my emacs configuration on github.
There is a screencast that I made. Is a EMACS snippet demo.
Bolacha, httplib2 wrapper with cookie handling and file upload.
Posted by Gabriel Falcão - 09/08/09 at 01:08:08 amI really like httplib2, but unfortunately it does not oficially support sending multipart/form-data.
So last Monday I was at work, and realized that I was needing exactly to make a http upload from within a python program, and also needed to make a session login right before.
I remember that I needed that before, but I could not find something simple and concise, yet pythonic and well tested.
So I decided to work on a proof of concept, 2 days after that, at last wednesday, I got really sick. I thought was just a simple flu, but I got even worst. Going to hospital, doctors found out I have sinusitis.
So since wednesday I am at home, having lots of damn medicines.
But the good thing is that I got time enough to hack
So I would like to introduce you Bolacha.
You can see de docs here
There is a debian package available here
The code is available at my github page: http://github.com/gabrielfalcao/bolacha/tree/master
New projects + agile = releases
Posted by Gabriel Falcão - 05/07/09 at 05:07:31 pmWhen I lived in Belo Horizonte/MG, I used to make hack parties with some friends of mine (nothing to say about all those pizzas and beer).
The hack parties had no specific goal, but a main idea: Hack some free software, and share the knowledge.
Many of us, but specifically Lincoln and I, used to create new projects in every hack party,but only a handful of those were actually released. It was often matter for jokes like: “Oh, you are up to raise the “too many projects” exception”.
I have two words for that fact: “not agile”.
Our projects were often POCs, and we had no culture of TDD, short releases and so on.
But since I started to work at Globo.com, I learned so much about agile, specially Scrum. And some months ago I’ve just accomplished what I call as “agile feeling”.
I mean, it’s a feeling that I can deliver software with quality in a short period of time.
But how ?
The idea is quite simple, you just have to follow some principles:
Think simple
This basically means focusing at the problem at hand, never trying to solve future problems you don’t have. Most of the time the problems your foresaw will never happen, yet you spent a lot of time preparing for them.
Test before programming
Write tests for small parts of your software, they will be very modular, and you will get a trust-able software, and I can assure you that you will be 100% able to embrace the changes.
Release fully functional versions, with simple features
As human beings, we want to embrace all possibilities and solve all possible problems at once.
But this is not agile at all. Talk to your client, be pragmatic, he will like to listen the truth: “You can not ship a full-featured final version of software within the term. But you can totally ship a primary version, fully functional, with all the basic needs of the client. Keep improving the software in next releases”
I tried to summarize those thoughts, but I need blog posts for each one.
Applying those thoughts to personal projects
As I said, I have unfinished projects, and they are still unfinished, mostly because were started with a non-agile approach, and I can’t get interested to finish them.
But there are a few projects I worked in, and others I am the creator. For instance:
- Dead Parrot, a pythonic RESTFul framework django-based. Is on release 0.1-hellopolly, being used within some globo.com projects.
- Ma-Chérie, a simple filesystem-based web application to navigate through pictures. Current release: 0.1
- Sponge, a tiny web framework built on top of CherryPy and used Genshi as default template language. Sponge is the base of Ma-Chérie. Current release: 0.1
- Pyccuracy, s BDD acceptance testing tool. Heynemann started that project, as a comitter, I worked in the biggest refactoring. Current release 1.0.3-viagra
- Sleepy, is a crude, slow and rough template language, 100% based in regular expressions (which mades sleepy so slow). Actually I do not plan release it by now, I am just having some proofs of concept of how possible is to write a template language 100% regex based, just with TDD.
All projects above, except Sleepy, were released as well, all them were developed with TDD and have a good code coverage.
But the big deal is that, actually they will never get finished, for a simple reason. They will be in continuous development and continuous released as well.
By the way, if you want to contribute, just go to my github profile and check them out.
Geeks from venus eat geeks from mars at breakfast
Posted by gabriel - 31/01/09 at 05:01:45 pmMany of my friends (maybe, so many) are geeks, but i’ve recently noticed that they are forked in two kinds thus I found completely fair to name as “Hedonistic Geeks” and “Parnasian Geeks”. Therefore, the hedonistic ones can also be labeled as “geeks from mars”, thus makes the parnasian ones from “venus”.
The hedonistic geeks
They keep doing computing stuff every single day of their lives, but it’s kinda enough for them. The rest of the days (vacation and weekends), are free day in which they feel the social duty of keeping at least a bit away from their computers.
Most of them have videogames such as Wii and XBOX, and it works like a “more social life”, they use Macbooks, and do use softwares such as iPhoto, Safari, Quicksilver and so on. Oh… yeah, I almost forgot, they use to have an iphone too.
Putting bluntly, hedonistic geeks can define themselves as geeks or not, because they don’t always accept their geekness to everybody. They are too cool for doing programming, hacking and stuff through the free days.
The parnasian geeks
Parnasian geeks love what they do, love what they are good when doing. They do programming and hacking for work, and keep doing it at the free time for fun.
They prefer Thinkpad as macbook, EMACS or VIM instead of Coda or Textmate. They dont have videogames, because they just can’t waste their hacking time playing videogames.
Instead, they create softwares suck as linux kernel, GNOME apps, python true stuff and so on.
Parnasian geeks are romantic with their geekness, and if they decide to don’t geeking in the free time, will not be playing videogames, but looking for people to have a real social life, to dance, to make the difference. And even to look for a partner to get married and keep their specimen in this world.
To be continued …
Hosting and deploying django apps on Dreamhost
Posted by gabriel - 02/12/08 at 09:12:00 amAbout two years ago, I’ve signed up to Dreamhost. My goals were and still being to host my personal projects, websites and so on.
Once I am a Django web developer, one of my first actions were to create a django deployment setup, good and flexible enough. The time passed on and have been got new experiences, and the best desision, i think, was to create a new python sandbox, i mean, a customized python environment.
How is it possible ?
Simple! Just compiling python from scratch, with a fake root path (a prefix)
Anyway, the deployment process involves more variables, like setting both htaccess and dispatch files for each project, installing some basic modules such PIL and MySQL and so on…
So, i ever wanted to create a super duper script to do all that “dirty” work. And i did it last weekend!
I were working ia a freelance job and decided to create a subdomain to host test instance of them.
A new sandbox, ready to make my tests to create the super script.
So folks, i present you the brand new: django_dreamhost.sh
It’s composed by 4 files:
- django_dreamhost.sh itself
- djangify.template – a template with will become a script to setup new projects (htaccess and dipatch files, for instance)
- htaccess.template – a template that will become the .htaccess of each project of yours
- dispatch.template – will become the dispatch.fcgi for your projects as well
“But do i need to download all them ?”, of course NO!
You just download the main script, and he will do all do hard work!
“I wanna contribute, modify or do anything with that script, can I ?”, of course yes! All parts of the script are GPLv2 +
You can also always get the development version through git repository:
git clone http://git.nacaolivre.org/django_dreamhost
Don’t want to get all code, just the script ?
Download it at: http://gnu.gabrielfalcao.com/django_dreamhost/django_dreamhost.sh
What does that script do ?
He will do the following steps:
- Download Python, Django, Python-setuptools, Python-fastcgi to a directory called downloads
- Extract all
- Create a local root at $HOME/.myroot and the subdirs etc and usr
- Set the new bin path to you global path through bashrc and bash_profile
- Compile and install python to the new prefix: $HOME/.myroot/usr
- Install Django, rename django-admin.py to django-admin
- Setup your bash-completion to support django scripts
- Install the python modules above with the new python
- Install PIL and MYSQL modules through easy_install (setuptools)
- Download the template scripts to $HOME/projects/script_templates
- Replace the custom tags in templates
- Move the djangify.template to the new bin PATH: $HOME/usr/bin and give it execution permission
I thinks it’s all.
I currently use Fabric to help on deployment, and i have a quite smart basic setup for it to work with this dreamhost django environment, but it will be approached in the next blog post
See you, folks!
Graduation done!
Posted by gabriel - 12/07/08 at 07:07:51 pmToday i’ve reached my first graduation.
It’s funny to think that i’ve made a friend during the course, but he wasn’t from my class, actually, he done another course, but our classes joined to some lessons. The funny fact is a long history….
The government of Brazil have a project who support students with “high scores”, paying private universities, this is really awesome and give great oportunities to people who could not get it by themself.
The thing work like this: You make a test, based on your score, you can choose a range of different courses and universities.
So, this dude, Glauco, choose as first option the course of “Free Software Technology” and as second option he choose “Web development technology”, and I choose the inverse: Web developement as first and Free Software as second option.
The funny fact in all this is because we got the inverse of first options. So if nowadays i know, develop and give my blood trying to help free softwares, maybe Glauco should be in my place, and I in yours, but i am so happy to this haven’t happened
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.