← Back to team overview

zim-wiki team mailing list archive

Re: plans for python3?

 

Hello Jaap,

I would prefer to port to both GTK 3 and Python 3 in one go (2) after
a thorough preparatory phase (1). Here are my thoughts:

(1) The first phase - Forward-compatible Python 2.7

# Goal:

To make the Python 2 codebase as much forward compatible with Python 3
as possible, identify tricky code and (for me) to get familiar with
the codebase.

# Key requirements:

- Zim is stable and fully functional.
- It is still possible to add new features, fix bugs and make releases.
- A working branch (py27?) can be regularly merged to the trunk after
a code review.

# Plan

a) We should study the incompatibilities between Python 2 and 3 (e.g.
[1][2]) and review the whole Zim codebase file by file. If the
incompatibility can be solved with a forward-compatible Python 2.7
code (e.g. `except KeyError as e:` istead of `except KeyError, e:`),
port it immediately. Otherwise mark it with `# py2!` (optionally with
a description).

[1]: http://python-future.org/compatible_idioms.html
[2]: http://python3porting.com/

b) We should use `from __future__ import ...` features such as
print_function, unicode_literals, division and absolute_import.

c) We may run Zim with `python -3` option to enable extra warnings.

d) We should port Zim to the new PyGTK 2.24 APIs (e.g. widget.window →
widget.get_window(), container.child → container.get_child(), etc.) to
make it compatible with PyGTKCompat [3].

[3]: https://wiki.gnome.org/Projects/PyGObject/PyGTKCompat

e) I propose using a Python-2 compatible variant of type hints [4][5].
I use them a lot in my Python 3 + GTK+ 3 project at work and they have
proved to be really useful as the PyCharm IDE supports them quite well
(including the free Community Edition). It can even generate
type-checking stubs for GTK+. I don't know what is your tooling but
the mypy type checker can be used independently. There is no extra
run-time dependency as the typing module is necessary only during the
static type analysis.

[4]: http://mypy.readthedocs.io/en/latest/python2.html
[5]: https://www.python.org/dev/peps/pep-0484/

If you are not fond of the type annotations, we may strip them off
easily after porting (regex "#\s*type:\s+.*$"). However, I believe the
annotations will help me to get familiar with the code and should spot
some (but not all) errors without the need to run Zim again and again.

# Outcome

After this first phase, we will have a fully functional Python 2.7
version of Zim. We may even keep it around as a LTS release for users
who cannot switch to Python 3.

(2) The second phase - Python 3 and GTK 3 port

# Goal

To port Zim to Python 3 and Gtk3 in one go

# Plan

- Decide on a minimal Python 3 and GTK+ 3 version. Python 3.4 is
available in Debian Jessie and Ubuntu 14.04 LTS, Python 3.5 in Debian
Stretch and Ubuntu 16.04 LTS.
- A new branch is created.
- All plugins and non-essential modules are disabled.
- We may try to run Python's 2to3 script. I don't know how useful it
actually is.
- All code marked with # py2! is ported manually.
- PyGTKCompat [3] module is used to get the app running fast and then
GUI is ported flle-by-file to PyGObject GTK+ 3.

Best regards,

Jiri Janousek

On Tue, Mar 14, 2017 at 12:22 PM, Jaap Karssenberg
<jaap.karssenberg@xxxxxxxxx> wrote:
> Hi Jiri,
>
> Would like to take you on on that offer. I will set up a branch to be used
> for porting (I have a preferred starting point, not current trunk).
>
> Strategy wise I believe we need to go to Gtk3 before we can go to Python3,
> so that will be 2 phases.
> For the first step going to Gtk3 I would like to split up the application in
> modules. Trying to get the basic application running first, than port
> additional modules and plugins one-by-one.
>
> Let's simply use a wiki page to track progress and who-does-what. I prefer
> (private) email for quick questions / discussions.
>
> Is this what you had in mind?
>
> Regards,
>
> Jaap
>
>
> On Sat, Mar 11, 2017 at 7:39 PM Jiří Janoušek <janousek.jiri@xxxxxxxxx>
> wrote:
>>
>> > Yes, I have plans to port zim to python 3, but can't commit to a
>> > concrete
>> > timeline on this moment.
>>
>> I might help with the porting to Python 3 & GTK+ 3. What is the best
>> place to discuss the strategy? Mailing list, bug tracker or Launchpad
>> blueprints? I prefer the bug tracker.
>>
>> Best regards,
>>
>> Jiri Janousek
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~zim-wiki
>> Post to     : zim-wiki@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~zim-wiki
>> More help   : https://help.launchpad.net/ListHelp


Follow ups

References