Difference between revisions of "GEPS 031: Python 3 support"

From Gramps
Jump to: navigation, search
m (Ubuntu 12.10)
Line 27: Line 27:
 
Python 3.2.3 ships with Ubuntu 12.10. To run Gramps, you will also need the packages:
 
Python 3.2.3 ships with Ubuntu 12.10. To run Gramps, you will also need the packages:
 
# python3-gi: gobject introspection
 
# python3-gi: gobject introspection
 +
# python3-gi-cairo: cairo gobject instrospection
 
# python3-cairo : This is needed to have ''import cairo'' work
 
# python3-cairo : This is needed to have ''import cairo'' work
 
# python3-bsddb3: This is needed to have ''import bsddb3'' work
 
# python3-bsddb3: This is needed to have ''import bsddb3'' work

Revision as of 23:16, 14 November 2012

Gramps was written with python 2. Slowly the default python is becoming python 3. Gramps 4.0 will require python 2.7+. Ideally we also support python 3. Then in 2014-15 we can drop python 2.7 support. For convenience, we aim for python 3.2+


Guideline

No python 2.7 only constructs should be present, and no python 3.2 only constructs should be present.

Can I work with both pythons?

On the same family tree, normally not! For python3, bsddb is no longer a core package. You need to install python3-bsddb, and that will normally be a more recent version than what is present in python 2.7.

So, once you open a family tree with python3, you will not be allowed to open it with python 2.7. The only way to open it with python 2.7 is using the bsddb3 option of Gramps, and installing from source the bsddb3 package for python 2.7 that is as current as the one given in python3

How?

See patchset in [1].

Main attention points:

  • we should not use unicode anymore. Instead, import from gramps.gen.constfunc the cuni or friends functions to convert to unicode
  • we should not compare to basestring or unicode type. Instead use UNITYPE and STRTYPE from gramps.gen.constfunc
  • in python 3 many functions became iterators. Remove the old 2.7 names and replace with the 3.2 names as much as possible. Only when performance is really an issue, use an if construct on python version so that python 2.7 also uses an iterator.
  • you will see a lot of list(map ...) or list(range...) after conversion. Only remove this if you studied the code and know it will work in python 2 and 3
  • If special unicode symbols are needed, then use from __future__ import unicode_literals and # -*- coding: utf-8 -*- and adapt the 2.7 code to have it working with this.
  • to test on python version, use if sys.version_info[0] < 3: for consistency with the other patches.

Requirements

Ubuntu 12.10

Python 3.2.3 ships with Ubuntu 12.10. To run Gramps, you will also need the packages:

  1. python3-gi: gobject introspection
  2. python3-gi-cairo: cairo gobject instrospection
  3. python3-cairo : This is needed to have import cairo work
  4. python3-bsddb3: This is needed to have import bsddb3 work

Related Gramps Bugs

  • #2620: GEPS 031: Python 3 support - 3.2

See also Python 3 Deprecated