Fork me on GitHub

Using the pipeline module ruffus with Python 3.2

No Comments

The Python module ruffus is a great companion for setting up pipelines easily and quickly. Unfortunately the development has been focused on Python 2.x ... until recently. There are some recent adaptations to get it running under Python 3.x but there are some modifications needed.

At first download the development version of ruffus:

$ svn checkout http://ruffus.googlecode.com/svn/trunk/ ruffus-read-only

Then use the 2to3 tool to for the code conversion:

$ 2to3 -w ruffus-read-only/

Let's check if this works by running a small script:

$ cd ruffus-read-only/
$ emacs -nw test.py
$ cat test.py
from ruffus import *

def first_task():
    print("One")

@follows(first_task)
def second_task():
    print("Two")

pipeline_run(second_task)
$ python --version
Python 3.2
$ python test.py
Traceback (most recent call last):
  File "test.py", line 10, in 
    pipeline_run(second_task)
  File "[...]/ruffus-read-only/ruffus/task.py", line 2675, in
pipeline_run
    pool_func = imap
NameError: global name 'imap' is not defined

As you can see 2to3 did not do the full job. But the code needs only a small adaptation to be Python 3.x compatible (it is a tiny problem due to changes in itertools):

$ cp ruffus/task.py ruffus/task.py.org
$ emacs -nw ruffus/task.py
$ diff ruffus/task.py.org ruffus/task.py
2675c2675
         pool_func = imap
---
>         pool_func = map

$ python test.py
One
    Job completed
Completed Task = first_task
Two
    Job completed
Completed Task = second_task 

Now it works!

Be the first to write a comment!

Notice: Undefined variable: commenter_name in user/themes/charcoal_konrads_version/commentform.php line 10 " size="30" tabindex="1">

Notice: Undefined variable: commenter_email in user/themes/charcoal_konrads_version/commentform.php line 14 " size="30" tabindex="2">

Notice: Undefined variable: commenter_url in user/themes/charcoal_konrads_version/commentform.php line 18 " size="30" tabindex="3">

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '} t
			INNER JOIN {tag2post} tp
			ON t.id=tp.tag_id
			INNER JOIN habari_posts ' at line 2 in system/classes/databaseconnection.php line 271
Warning: Invalid argument supplied for foreach() in user/themes/charcoal_konrads_version/theme.php line 157
    Warning: Invalid argument supplied for foreach() in user/themes/charcoal_konrads_version/taglist.php line 2