Moving to Python 3

Tuesday, April 23, 2019
Reading time 8 minutes

Over the past 6 months, approximately, I have been revisiting some of my projects written in Python (that means, basically all my public projects plus some more that have been not released) to explore the possibility of moving them all from Python 2.x versions to Python 3. As you probably know (or if not, I tell you), Python 2.x will reach end of life at January 2020, so we are suggested to update our projects to work with the latest major Pytohn version as it’s the present of the language.

I just wanted to write this post to indicate what exactly it means for end users. Because during the last months we have been talking, both in Twitter, GitHub, or in private conversations about moving the codebases to Python 3, but, what exactly does it mean? and how you, as normal users, are going to be affected?

The simple and short answer is “You are not going to be affected, probably. Unless You use Windows XP”. So if you have Windows 7, 8, 8.1 or 10 and don’t want to read more, you shouldn’t. It’s unlikely you will notice a change in the projects, besides a better memory management, faster loading times and other possible new additions present in Python 3 that will make things faster and more confortable for developers.

But if you have Windows xp, the story is different, as all of my projects will drop support for XP, officially, before august 2019.

During my short time in software development, I have been trying my best to keep my projects available for most people. However, there are some times where I have to make a smart choice and taking into account that Python 2, as a programming language, will be unsupported very soon, and Windows XP is no longer supported by Microsoft and almost all relevant projects (the most notable example here is LibVLC, which we use in TWBlue. It shows an error every time the library gets loaded in XP because they already dropped support for XP), i think it’s time to drop support for Python 2.x versions in my projects, thus allowing me to use better coding techniques and get the best performance of new Python 3 features.

As always, I have a plan for the move, and as, in some cases, I have received some reports of people still having XP (I’m not going to say you should or not should upgrade, i think it’s a personal choice and not everyone can afford to upgrade a computer), I’ll try to detail the end of support for XP in all my released projects in the following lines. My goal is to develop only Python 3 compatible software in August.

Socializer

Status: Already on Python 3 (Python 2 support was removed in february 2019).

My most recent project (and the one where I spend most of my developing time, currently) is Socializer. If you don’t know what is it, you can take a look to the project’s website and get an idea. When I have started to work again in Socializer, in the last december, I tried to migrate the codebase to be used in Python 3.7 while was still compatible with Python 2.7. The experiment was simple: I would release updates over the alpha channel for about a month, built with Python 3. If no reports were found in such version for a few weeks (alpha versions were being released almost dayly), then the Python 3 versions would become the default in the CI architecture and new stable versions would be generated in Python 3. Still, Python 2 versions would be generated until I introduce a change that breaks compatibility between both major versions. And this change arrived with a feature I have used to differentiate cases in names when using the interface in russian, which is the translation used by the 99% of the user base of Socializer. Everyone seem to be using the Python 3 version without any issue related to the new language syntax or unexpected errors, at all. So this proved the move was possible (Socializer shares a lot of dependencies and features with TWBlue).

TWBlue

Status: In progress.

TWBlue is probably the most popular project I have developed so far. During the last time, I must admit I have not spent so much time coding and adding new features to this client. I think it’s due to a mix of feelings originated by the Twitter limits (removed the streaming API, forced everyone to pass a “review process” for our applications, and there are lots of methods that are not going to be available for us as third party developers, such as group direct messages, getting quoted tweets, polls support. For me, it’s clear they want to convince everyone to use their official apps, and the best way to do so is making people to think they can offer a feature rich client, while we are not able to do the same). Mastodon support is also in the works, and I made a big move on that direction, namely separating some of the Twitter specific code from the rest of the TWBlue code, but still, I consider we are still far to integrate both Twitter and Mastodon in the same application.

some people have been asking for adding Python 3 support to TWBlue. We have a few pull requests and issues in github where people ask or suggest some changes in the code to support Pytohn 3, but dropping support to Python 2 and windows XP is a side effect of the migration. I have started some efforts to make code compatible with both Python 2 and 3, because i still would like to release the next stable Version of TWBlue to be compatible with Python 2 and Windows XP users. This means the next TWBlue stable will be the last version available for Windows XP, because right after this release, I probably will merge a pull request and continue working on it, which will make TWBlue fully compatible with Python 3. I still have a few things to take into account before migrating everything, namely the distributable files generation, the CI infrastructure (right now I am considering wether we should Stay at appvellour’s service or migrate the snapshots generation to gitlab) and a few minor issues.

In short: the last TWBlue version, 0.95, will be the last version available for windows XP users. After 0.95, all other snapshots and stable versions will be built with Python 3. That also means, Snapshot users will be required to download a fresh copy of TWBlue (Python 2 and 3 versions must be considered as different programs).

MusicDL

Status: Already on Python 3.

MusicDL’s source code is already compatible with Python 3. In fact, this was my first project including full compatibility with Python 3 since the first release. In the next version, though, i will drop support to Python 2 in MusicDL, that will mean only Python 3 will be supported, which will make everything easier for the update architecture, development and in features, as I will not have to care about testing the code in different Python versions.

Lees

Status: already on Python 3 (pending release)

I have made a little software to read ebooks for Windows. I knew there were other alternatives, I knew some of those were mainstream applications and were half accessible. But I wanted to do my own, just for the fun of making it by myself. After a few versions, I did not have enough time to keep improving and developing the application further, so i stopped the project’s development. But never deleted the source code. Over the years, some people have been using the little project I created, and have asked me when I will release new versions, or if the application would be released as open source if I will not continue the development. At first, I considered just one or two people were using the project, and they could use something else if they want the job done. As I said before, my project was not the only application accessible for the blind. But later I have received more and more questions about the same project, and that let me to think there are more than two people using, or at least asking, for the project. So I have decided to revive it back, as i did with Socializer.

So, the next release of the project (I still have to create a section for it here on my website, though) will be already built with Python 3. I have ported the source code and it works reasonably well with Python 3, I just have to clean things a bit (I have some unfinished experiments in the repository) and that should be ready for release.

conclusion

Moving a project from Python 2.x to 3.x is not that hard, most of the times. We have some nice tools capable of doing almost all the job of changing the source code for ourselves. However, due to some syntactical changes introduced or removed in the latest Python 3 versions, some of the projects require manual changes before we can run them in Python 3. Also, there are certain dependencies, or changes between str and byte objects, that need to be reviewed before making any change. I planned to have everything ready for about august, and I just detailed the process and status of my projects regarding the migration. I hope to accomplish the goal and keep you updated.

Projects