Skip to content

Migration to Python3

Kashiko Koibumi edited this page May 31, 2024 · 2 revisions

The first try

Current official PyBitmessage is written in Python2 and runs with PyQt4. Both of Python2 and PyQt4 are obsolete, so migration to recent versions is highly desirable.

But official developers does not release new versions for past long years. I wondered what were the core obstacles which prevent to upgrade, so I began trying to port the official PyBitmessage to Python3 as an unofficial private research project.

I'm using Devuan GNU+Linux Daedalus which is almost compatible to Debian GNU/Linux bookworm except systemd related elements. Python2 is already dropped from Debian packages, so I have to use Python3 for the research project anyway. I found there are Qt6 packages already, so I decided to use PyQt6 from Debian packages.

I modified the launcher script "start.sh" to use Python3, and executed it. Some messages were printed saying that PyBitmessage does not support Python3, and the program was terminated. So I removed the version check code, and retried. Then some errors were printed which may due to incompatibilities between Python3 and Python2. I tried to resolve errors heuristically by minimal abrupt ad hoc modifications. I also replaced PyQt4 with PyQt6, so many formal changes were required.

The road seemed to be very long and no goals were in sight. I thought that I would give up soon, but I had plenty of time to kill, so I continued the job as a hobby.

Then, by three days of work, an unofficial dirty version of PyBitmessage which seemed to be running with Python3 and PyQt6 in some degree had been created. The dirty version was not tested almost at all, and it shall contain many many bugs anyway, but it launched with partially broken main window and it was able to send and receive some messages. It is the main branch.

I had pushed a pull request abruptly to the official PyBitmessage repository at GitHub. I never thought it should be merged to the mainline. It might be a kind of message, possibly a love letter. Love has many forms.

The second try

In the conversations of the pull request, I heard that there were some pull requests in the past which aim to migrate to Python3 or PyQt5. I had not checked them at all. One of the pull requests had used Qt.py module which can abstract away the differences of PyQt versions. By using the module, applications can run with any version of PyQts including PyQt4 or PyQt5 or perhaps also PyQt6. If I had known the module, I used it definitely, but it was too late.

I re-planned to split the project to two branches, a branch to migrate to Python3 and another branch to migrate to PyQt5 by using Qt.py.

First, I fetched the qt5-wip branch which uses Qt.py and merged to current official v0.6 branch. It became a version which run with Python2 and PyQt5 or PyQt4.

Alternatively, second, I managed to modify the current official v0.6 version to run with both Python3 or Python2 and PyQt4, which does not use Qt.py. It is the py3 branch.

Finally, I merged these two branches, which run with both Python3 and Python2, and which run with both PyQt5 and PyQt4, perhaps with PyQt6. Any combination works. It is the py3qt branch. It is more clean than main branch.

Clone this wiki locally