Travis-ci.org and Coveralls.io: Continuous Integration and QA made easy

Posted on Sun 02 March 2014 in Linux, Programmazione, Python

Developing a large web application or before deploying some code is very important to verify the quality of the code itself, check if we have introduced any regression or bug and have something that tell us if we are increasing or decreasing the quality of the code.

Suppose we are in an organization or a company where the basic rule is: master branch is always ready/stable to be deployed. In a team usually people work on personal branches, then when the code is stable it's merged with master.

How do we check if the code is stable and ready to be merged? First of all we need to cover all our code with proper tests (I won't go in details about unit testing here, I assume that the reader knows what I'm talking about), then we need to actually run them, possibly in an isolated environment that is similar to the production one, and check if they all pass. If they do, we are quite safe to merge our code with master branch.

How can we ensure that all the developers remember to run tests when they push some new code? To make things a bit more real, let's take the example of a Python/Django product (or even a library) that currently supports Python 2.6, 2.7, 3.3 and Django 1.4.x, 1.5.x, 1.6.x. The whole matrix consists of 9 possible combinations. Do we have to manually run tests on 9 configurations? No, we don't.

Travis-ci.org

Travis is a continuous integration tool that, once configured, takes care of these tasks and let us save lot of time (that we can use to actually write code). Travis-ci.org is an online service that works with GitHub (it requires we use GitHub as repository for our code), and once we have connected the two accounts and configured a very simple file in our projects, it's automatically triggered when we push on our GitHub repository.

The configuration consists of adding a file named .travis.yml in the root of our project. A working example is available here https://github.com/andreagrandi/workshopvenues/blob/master/.travis.yml (all the env variables I set are not required normally, but that's where I save the values of my configuration, so they need to be initialized before I can run tests).

The service supports most of the languages that are commonly used and even a good number of PAAS, making it very easy to automatically deploy our code. If it should not be enough for your needs, they also expose a public API. I suggest you to give a look at the official documentation that will explain everything in details http://docs.travis-ci.com

Once everything is configured, we will have something like this on our console https://travis-ci.org/andreagrandi/workshopvenues/jobs/19882128

travis-ci-console

If something goes wrong (if tests don't pass for example) we receive a notification with all the informations about the failing build, and if we had configured an automatic deployment of course the code would not be deployed in case of a failing build.

Travis-ci.org is completly free for opensource projects and has also a paid version for private repositories.

Coveralls.io

There is a nice tool available for Python called coverage. Basically it runs tests and checks the percentage of the source code that is covered by tests, producing a nice report that shows us the percentage for every single file/module and even the lines of code that have been tested.

Thanks to Coveralls.io and the use of Travis, even these tasks are completly automatized and the results are available online like in this example https://coveralls.io/builds/560853

The configuration is quite easy. We need to connect our Coveralls.io profile with GitHub, like we did for Travis-ci.org and then enable the repository. To trigger Coveralls after a successful Travis build, we need to have these lines at the end of our .travis.yml file

after_success:
  - coveralls

coveralls-console
Even Coveralls.io is completly free for opensource projects and offers a paid version for private repositories.

Heroku

I use Heroku to host and run my web application. Normally to deploy on Heroku you so something like this: git push heroku master

Adding these settings to the .travis.yaml file, I can automatically deploy the application on Heroku, if the build was successful:

deploy:
  provider: heroku
  api_key:
    secure: R4LFkVu1/io9wSb/FvVL6UEaKU7Y4vfen/gCDe0OnEwsH+VyOwcT5tyINAg05jWXhRhsgjYT9AuyB84uCuNZg+lO7HwV5Q4WnHo5IVcCrv0PUq/CbRPUS4C2kDD7zbA1ByCd224tcfBmUtu+DPzyouk23oJH+lUwa/FeUk0Yl+I=
  app: workshopvenues
  on:
    repo: andreagrandi/workshopvenues
  run:
    - "python workshopvenues/manage.py syncdb"
    - "python workshopvenues/manage.py migrate"

Not only the code is deployed, after deployment the South migrations are executed.

Conclusion

These two tools are saving me lot of time and are ensuring that the code I release for a project I'm working on (WorkshopVenues) is always tested when I push it on my repository.


Inizia il PyCon: Richard Stallman oggi a Palazzo Vecchio (Firenze) ore 16:00

Posted on Fri 09 May 2008 in Linux, Programmazione, Python • Tagged with conferenza, firenze, palazzo, pycon, richard, stallman, talk, vecchio

Richard Stallman

Come da programma, oggi a Palazzo Vecchio

(Firenze) ci sarà il talk di apertura del PyCon Italia 2008, tenuto dal leader e fondatore della Free Software Foundation, Richard Stallman.

Richard Stallman parlerà degli obiettivi e della filosofica del Movimento per il Software Libero, e della storia e stato attuale del sistema operativo GNU che, in combinazione con il kernel Linux, è usato oggi da decine di milioni di utenti in tutto il mondo.

L'evento di oggi è completamente gratuito e aperto a tutti (fino ad esaurimento dei posti disponibili). Quelli che si sono registrati per il PyCon avranno ovviamente la precedenza.

Per ulteriori informazioni sull'evento e sul PyCon, potete consultare il sito ufficiale dell'evento.


Using GtkIconView in Python: a small tutorial

Posted on Tue 15 April 2008 in Linux, Programmazione, Python • Tagged with gtk, gtkiconview, gtkliststore, HowTo, programming, Python, tutorial

In these days I was looking for a simple tutorial to understand how to use GtkIconView, but the only thing I was able to find was an example in PHP-Gtk. So I decided to translate it in Python language, thinking it would be useful for other people trying to use that Gtk control. You can find the code here:

import gtk
import gobject

DEFAULT_IMAGE_WIDTH = 100

# Main Window setup  
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_size_request(400, 240)
window.connect("destroy", gtk.main_quit)
window.set_title("Python GtkIconView Test")

# Add a VBox  
vbox = gtk.VBox()  
window.add(vbox)

# Setup Scrolled Window  
scrolled_win = gtk.ScrolledWindow()
scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

# Setup ListStore to contain images and description  
model = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)

# Create a tuple with image files
immagini = (
    "BD786-TFR.jpg", "guido_sottozero.jpg", "IMG_0056.JPG", "movies_card.jpg"
)

for im in immagini:
    try:  
        pixbuf = gtk.gdk.pixbuf_new_from_file(im)
        pix_w = pixbuf.get_width()
        pix_h = pixbuf.get_height()
        new_h = (pix_h * DEFAULT_IMAGE_WIDTH) / pix_w # Calculate the scaled height before resizing image
        scaled_pix = pixbuf.scale_simple(
            DEFAULT_IMAGE_WIDTH, new_h, gtk.gdk.INTERP_TILES
        )
        model.append((scaled_pix, im))
    except:
        pass

# Setup GtkIconView  
view = gtk.IconView(model)  # Pass the model stored in a ListStore to the GtkIconView
view.set_pixbuf_column(0)
view.set_text_column(1)
view.set_selection_mode(gtk.SELECTION_MULTIPLE)
view.set_columns(0)
view.set_item_width(150)

# Pack objects and show them all  
scrolled_win.add(view)  
vbox.pack_start(scrolled_win)
window.show_all()

gtk.main()

The important thing to notice is that you have to store all the images in a GtkListStore and pass it to the GtkIconView as "model" parameter. I hope this example is clear. If you have any question, please comment this post and I'll try to answer.

This is a screenshot of this example:

gtkiconview


PyCon2: conferenza italiana dedicata al linguaggio Python

Posted on Sun 06 April 2008 in Linux, Programmazione, Python • Tagged with conferenza, firenze, italiana, linguaggio, Programmazione, pycon, pycon2, Python, sviluppatori

Python

PyCon Due

è la seconda conferenza italiana dedicata al linguaggio di programmazione Python. La conferenza è organizzata da un gruppo di appassionati e senza finalità di lucro; si prefigge la divulgazione di Python, e di dare visibilità agli sviluppatori professionisti, studenti, aziende e semplici interessati al linguaggio.

Dove e quando

La conferenza si tiene a Firenze nelle giornate di Venerdì 9, Sabato 10 e Domenica 11 Maggio. L'evento di apertura si terrà a Palazzo Vecchio nel pomeriggio di Venerdì, durante il quale terrà un keynote Richard Stallman. Sabato e Domenica, al Viva Hotel Laurus (Via Cerretani 54/r), nei pressi del Duomo, si svolgeranno 3 track parallele di conferenze.

Gli Interventi

Durante la conferenza si terranno due tipi di interventi: i keynote ed i talk.

I keynote sono interventi di ampio respiro che trattano temi di attualità del mondo dell'informatica; hanno una durata indicativa di 90' e verranno tenuti in occasione dell'evento di apertura di venerdì 9 ed alla chiusura delle due giornate successive.

I talk

sono invece interventi focalizzati su un particolare argomento; hanno una durata indicativa di 45', comprensivi del tempo per le domande del pubblico. I talk di PyCon Due si tengono durante le giornate di sabato 10 e domenica 11, e si dividono in tre track: "Scoprire Python", "Diffondere Python" e "Imparare Python":

  • Scoprire Python è una track introduttiva su librerie, framework e metodologie, pensata per chi si sta avvicinando al Python o desidera una prima trattazione di un argomento;
  • Diffondere Python è una track dedicata ad aspetti più avanzati del linguaggio, esempi di integrazione della piattaforma e casi d'uso in azienda;
  • Imparare Python è una track interattiva: i talk sono parzialmente guidati dal pubblico, che discute la trattazione dell'argomento insieme al relatore, proponendo scenari e commentando le soluzioni proposte.

Registrazione

per partecipare all'evento occorre registrarsi. La registrazione puo' essere fatta direttamente sul sito ufficiale del PyCon2. Sempre sul sito ufficiale, potrete trovare a breve l'elenco delle conferenze che verranno fatte, non appena si concluderanno le votazioni per il Call For Paper che sono in corso in questi giorni.