All | 43 Folders | Accessibility | BoingBoing | Books | Computer Related | Family | Films | General | Hacking | Hobbies | Humor | Java | Links | Omni | Puzzles and Games

« Whither Decent/Worki... | Main | What's In Gcalctool... »
20080306 Thursday March 06, 2008

Converting Orca to Python 3.0

Something we've got to be thinking about soon is seeing what needs to be done to get Orca to run with Python 3.0, which is planned to be available in Auguest 2008.

So I thought I'd give it a try now with the current Python 3.0a3 download.

Building it was trivial:

  $ cd /home/richb/Python-3.0a3
  $ ./configure --prefix=/usr
  $ make
  $ sudo make install

Guido and team have even made the conversion trivial. There is a tool called 2to3 in the Tools directory that will do the refactor for you.

I checked out a clean copy of the Orca sources from SVN and converted it with:

  $ cd /home/richb/Python-3.0a3/Tools/2to3
  $ python refactor.py /home/richb/gnome/orca/trunk/src >/tmp/diffs

This generated about 115KB of patch diffs on standard out which I then applied to the Orca source code:

  $ cd /home/richb/gnome/orca/trunk
  $ patch -p0 </tmp/diffs

I then configured, built and installed Orca with:

  $ cd /home/richb/gnome/orca/trunk
  $ ./autogen.sh --prefix=/usr
  $ make
  $ sudo make install

As it was byte-compiling all the Orca Python modules it bitched about the following two problems:

orca.py", line 1306
    + Q_("option|main-window") + "]", end=' ')
                                         ^
SyntaxError: invalid syntax

orca_prefs.py", line 636
    os.close(os.open(initFile, os.O_CREAT, 0o700))
                                               ^
SyntaxError: invalid syntax

For the second one, it looks like "0o700" should be "o0700" but I couldn't work out what was wrong with the first one. The original code was:

    print "-e, --enable=[" \
        + Q_("option|speech") + "|" \
        + Q_("option|braille") + "|" \
        + Q_("option|braille-monitor") + "|" \
        + Q_("option|magnifier") + "|" \
        + Q_("option|main-window") + "]",

and it refactored it to:

    print("-e, --enable=[" \
        + Q_("option|speech") + "|" \
        + Q_("option|braille") + "|" \
        + Q_("option|braille-monitor") + "|" \
        + Q_("option|magnifier") + "|" \
        + Q_("option|main-window") + "]", end=' ')

According to the What's New in Python 3.0 web page, that seems okay. For now I've just removed the "end=' '" part and I have a successful install (with a minor run-time formatting error when you print out the usage message).

When I run Orca, everything seems to work fine. No tracebacks and Orca is happy brailling and speaking away.

What worries me is that when I check the version number of /usr/bin/python (which is the same binary as /usr/bin/python3.0) I get:

  $ /usr/bin/python3.0 --version
  Python 2.5.2

So I'm not convinced I've done everything correctly.

Still it was nice to know that the conversion should hopefully be fairly trouble free when we do it for real. I guess that comes from pylinting the code to within an inch of its life.

[]

[]

( Mar 06 2008, 05:56:29 PM PST ) [Listen] Permalink Comments [5]

Comments:

Does orca have a good set of unittests? They are essential to the migration.

Also, you are supposed to migrate to python2.6 first (the first beta was released last week IIRC), and make your code run without warnings with the '-3' flag, and then migrate to py3k with 2to3.
http://www.artima.com/weblogs/viewpost.jsp?thread=208549

In python 3k, octals aren't anymore in the 0NNN format, but 0oXXX. But I cant see why it gives an SyntaxError.

As for the wrong version info, it probably just wasn't fixed yet -- you can report a bug in bug.python.org.
I used to have the last svn checkut of py3k branch compiled on my laptop, but now I formated it to test the Ubuntu hardy heron install, so it vanished...
It is good to see brave early adopters providing feedback to such a crazy project!

Posted by 201.27.208.252 on March 06, 2008 at 07:18 PM PST #

just
print("-e, --enable=["
+ Q_("option|speech") + "|"
+ Q_("option|braille") + "|"
+ Q_("option|braille-monitor") + "|"
+ Q_("option|magnifier") + "|"
+ Q_("option|main-window") + "]")

should work
or even better,
print("-e --enable=[%s|%s|%s|%s|%s]" % (
Q_("option|speech"),
Q_("option|braille"),
Q_("option|braille-monitor"),
Q_("option|magnifier"),
Q_("option|main-window")
)

Posted by Justin on March 06, 2008 at 07:38 PM PST #

Are you sure those syntax errors aren't coming from a Python 2.x interpreter?

The "print" syntax error looks like a correctly formated function call, but would be an error in 2.x where print is a statement with funky syntax.

The "0o700" one is the new Python 3.0 octal literal syntax. "o0700" is valid syntax in both 2.x and 3.0 but is a variable name rather than a number.

Posted by James Henstridge on March 06, 2008 at 08:58 PM PST #

> Are you sure those syntax errors aren't coming
> from a Python 2.x interpreter?

I'm not. /usr/bin/python is the same binary
as /usr/bin/python3.0 on my machine but the
files were installed under:
/usr/lib/python2.5/site-packages/orca

I'll investigate some more tomorrow.

Posted by Rich Burridge on March 06, 2008 at 10:17 PM PST #

Yup, it was definitely using Python 2.5.
When I tried the following:

$ PYTHON=/usr/bin/python3.0 ./autogen.sh --prefix=/usr

I get:
...
checking whether /usr/bin/python3.0 version >= 2.4... configure: error: too old

Getting tired. I'll try again tomorrow.

Posted by Rich Burridge on March 06, 2008 at 10:25 PM PST #

Post a Comment:

Comments are closed for this entry.