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

From Gramps
Jump to: navigation, search
m (Related Gramps Bugs)
m (Related Gramps Bugs)
 
Line 43: Line 43:
 
* Enhancement Request #2620: GEPS 031: Python 3 support - 3.2<br />'''''Lost''' - 1 of 4495 issues disappeared due to a table lost during a MantisBT upgrade. Per a developer [https://sourceforge.net/p/gramps/mailman/message/30069046/ maillist posting], this Python 3.0 compatibility enhancement was completed in 2009 for the Gramps 3.2 version.''  
 
* Enhancement Request #2620: GEPS 031: Python 3 support - 3.2<br />'''''Lost''' - 1 of 4495 issues disappeared due to a table lost during a MantisBT upgrade. Per a developer [https://sourceforge.net/p/gramps/mailman/message/30069046/ maillist posting], this Python 3.0 compatibility enhancement was completed in 2009 for the Gramps 3.2 version.''  
  
See also [[GEPS_032:_Python_3_support/Python_3_Deprecated|Python 3 Deprecated]]
+
See also: GEPS 032 - [[GEPS_032:_Python_3_support/Python_3_Deprecated|Python 3 Deprecated]]
 
[[Category:GEPS|P]]
 
[[Category:GEPS|P]]

Latest revision as of 02:03, 21 June 2022

Gnome-important.png
GEPS Closed

This GEPS (Gramps Enhancement Proposal) is closed and available in the version of Gramps indicated below.
Do not edit this page. Submit bugs/features to https://gramps-project.org/bugs/.

Python 3 support added for the release of Gramps 4.0
Python 2 support dropped for the release of Gramps 4.2
The Python.org team chose a sunset date for Python 2 of 1 Jan 2020.

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

Tips

  1. If you work with python3, edit the ~/.subversion/config files, and add the section
global-ignores = __pycache__
  1. Give a family tree a name that contains 32 if you use python 3, and 27 if you use python 2. Once you open a python 2 family tree, the database is upgrade and you canot open it again in python 2 (you could export to xml and import in python 2 though)

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

  • Enhancement Request #2620: GEPS 031: Python 3 support - 3.2
    Lost - 1 of 4495 issues disappeared due to a table lost during a MantisBT upgrade. Per a developer maillist posting, this Python 3.0 compatibility enhancement was completed in 2009 for the Gramps 3.2 version.

See also: GEPS 032 - Python 3 Deprecated