bootchk / resynthesizer

Suite of gimp plugins for texture synthesis
GNU General Public License v3.0
1.47k stars 163 forks source link

Migrate to python3 #67

Open luyatshimbalanga opened 5 years ago

luyatshimbalanga commented 5 years ago

Python2 end of life is on 1 January 2020. It will be nice to prepare the transition from python2 to python3 when Gimp development will finally use the latter.

bootchk commented 5 years ago

Even when Python org ends life of Python 2, I think GIMP will continue to ship their own version of Python 2 interpreter, as they do now. In other words, GIMP and PyGimp will continue to work after the fast approaching date of Jan. 2020.

To prepare in advance would require hard work of mocking up Python3 inside GIMP. I think it would be easier to wait for the GIMP org to put Python3 in GIMP and release a beta version, and then test and make changes to Resynthesizer.

band-a-prend commented 4 years ago

Hello. The gimp master branch (2.99) already compatible only with >=python-3.6 via pygobject introspection.

bootchk commented 4 years ago

Yes.

There is a branch of resynthesizer that removes its dependence on GTK2 for the control panel plugin, rewriting that plugin from C to Python using PyGimp/GimpFu.

The rest of the resynthesizer plugins are Python. They can easily be converted to Python3. But they also depend on PyGimp/GimpFu. (As do most other third party plugins.)

I am working on porting PyGimp/GimpFu to Python 3. I don't think anyone else is working on it for Gimp 3. But preliminary results show it will work, and allow most existing Python/PyGimp/Gimpfu plugins to work with only minimal changes. Including the Python plugins in resynthesizer. See my repository GimpFuv3 (but it is in a continual state of flux.)

As a fallback, I can convert the resynthesizer plugins to use GI. There are examples of how to do that in the Gimp 2.99 branch.

The Gimp org would probably prefer that I convert resynthesizer engine (in C language) to be a gegl plugin. But that doesn't solve the problem of the other resynthesizer Python plugins that just call the resynthesizer engine.

darix commented 4 years ago

JFYI: basically all linux distributions and I also heard freebsd are dropping python2 in the next few weeks. ubuntu 20.04 is the first linux distribution that shipped without python2.

so your plugin is already not working on that platform anymore.

hellocatfood commented 4 years ago

The main Resynthesizer is still working in GIMP it's just the Python plugins (e.g. Heal Selection, Heal Transparency) that aren't working.

nhendin commented 4 years ago

Is there a suggested workaround for ubuntu 20.04 users?

bootchk commented 4 years ago

Some say that there is an appimage that includes plugins and python for gimp.

There is also a flatpak gimp, and flatpaked resynthesizer plugin (and other plugins) for it.

The problem for Ubuntu 20.04 is that Ubuntu stopped distributing package "gimp-python" which was the Python2 expressly for Gimp. I think the above solutions bundle Python 2 for Gimp.

nhendin commented 4 years ago

Thank you for the tip!

Just to update this thread for the convenience of future readers; I've found 2 options that work:

Option 1: Manually pull python-gimp and python-gtk2 from Ubuntu 19.10 and install alongside gimp. Option 2: Use the App Image found here: GIMP AppImage I picked the latest one with plugins included.

I am going with option 2. I did try option 1 and it does work, but at the cost of making the package configuration a bit non-standard by having Python2 installed on a system that doesn't expect it. The AppImage seems to run fine.

jonasstein commented 4 years ago

Is it possible to remove the incompatible code and continue with a Py3 compatible collection?

bootchk commented 4 years ago

If you mean, use the resynthesizer without the Python plugins, yes you can do that, the main resynthsizer plugin, (implemented in resynthesizer_gui.c, the "control panel") does not depend on Python. But the "heal selection" plugin does some simplifications for ease of use, so to do the same thing using the control panel, you the user must know how to replicate those simplifications (duplicate images, make appropriate selections, etc.)

If you mean rewrite the resynthesizer python plugins to be Python 3 compatible? I don't think that will work. The resythesizer plugins use a Python module, called "gimpfu" that is part of Gimp. I don't think GimpFu will work with Python 3 (although I have not tested it.) GimpFu is written in C mostly, it statically binds Python to the libgimp API. If Python 2 bindings will still work with Python3, it would work, but I suspect Python 2 bindings will not work with Python3. And Gimp 2.10 still wants to start its own Python 2 interpreter, you would need to change that also.

The gimp.org definitely does not now plan to maintain or port the GimpFu modules (the binding of Python to libgimp.) Instead, they prefer that plugins be rewritten to use PyGObject, dynamic bindings of Python, to libgimp.

So, for Gimp 3 and Python3, I will either port the resynthesizer Python plugins to Python3 using PyGObject (recommended by gimp.org) or I will port GimpFu myself, which I have already undertaken (see my repository GimpFuv3.) There is a thread of discussion about this in the issues of the Gitlab repository of Gimp. (And also I might port resynthesizer to be a GEGL plugin, but I think that still leaves out the simplifications that for example "heal selection" does, although that too could be another GEGL plugin. The architecture, how to accomplish and present to the user the set of resynthesizer plugins, is complicated.)

msdobrescu commented 4 years ago

Hi, I use Sabayon. Sabayon and Gentoo dropped Python 2, now are dropping GIMP Resynthesizer too. I depend on it! Please migrate it!

wesleycsj commented 4 years ago

@bootchk You will go on with porting GimpFu by yourself? There is some paper who explains how resynthetizer works? I would like to know how can i contribute to port this project and getting it working again.

bootchk commented 4 years ago

GimpFu is a separate project. It would let Resynthesizer and many other Gimp Python plugins continue to work in Gimp 3, with only minor changes.

Resynthesizer C code does not change. It is the Resynthesizer Python plugins that need porting (unless GimpFu is ported, as above). That is not hard, you just follow the example Python plugins in the Gimp 3 branch, which use PyGObject (instead of GimpFu.)

Neither of the above are solutions until Gimp 3 is released. That is, Gimp 2.10.x still uses Python 2, which many distributions are no longer distributing. (It might be that PyGObject Gimp plugins will already work with Gimp 2.10.x, I have not tried.)

If you want to work on the Resynthesizer itself, we could make it into a GEGL plugin. Briefly, just adapt the GEGL API to the API of the resynthesizer library (which uses its own flavor of pixmap structures.). But that only provides the "engine" plugin, and the Python plugins still need to be ported to provide the "simplified special-use" plugins (e.g. Heal Selection.)

You are welcome to contribute to any of the above. I should document in more detail (in a document in the repository) exactly what and how to do any of the above.

Sembiance commented 4 years ago

@msdobrescu I run Gentoo and here is an ebuild I created that uses the GIMP AppImage which has resynthesizer built in: https://gist.github.com/Sembiance/ff82ab5af482627773dd80e3e04d3718

msdobrescu commented 4 years ago

@Sembiance, thank you, me too, as advised by a Mageia maintainer also. But why an ebuild?

Sembiance commented 4 years ago

@msdobrescu I got into the habit of making custom ebuilds in my own local overlay a while ago. It makes my monthly 'update the system' task a lot easier. For example to update to the latest AppImage in this case, I just change the name of the ebuild to the new version number and ebuild <gimp*.ebuild> digest and then emerge it. So only like 2 commands. Not as big a deal with just an AppImage wrapper ebuild like this, but for other programs it makes more sense :)

danielesegato commented 3 years ago

Distributions are dropping python2 in the next few months.

Your plugin doesn't work anymore in gimp installed with major distributions (ex. Ubuntu)

band-a-prend commented 3 years ago

In Gentoo the support of python2 for GIMP was dropped in Nov 2020.

bootchk commented 3 years ago

The solution is to use flatpak.

gimp.org is packaging GIMP as a flatpak now, and that flatpak includes Python2 to support GIMP.

A flatpak may support "extensions" i.e. plugins and the GIMP flatpak does.

Resynthesizer is available as a flatpak extension. Other popular and large GIMP plugins are available as flatpaks.

jonasstein commented 3 years ago

It is no rocketscience to port from the dead python2 to py3, but flatpack is a dead end. http://flatkill.org/

band-a-prend commented 3 years ago

The problem also is that gimp python2 interface depends on pygtk seems to provide dialog windows.

rautamiekka commented 3 years ago

GIMP 3.0.0 will be Python 3; 2.99.6 is at 3.6.0 according to https://gitlab.gnome.org/GNOME/gimp/-/blob/master/configure.ac, PEP 619 projects 3.10.0 for 2021-10-04.

So, GIMP could potentially be at Python 3.10.0 by the end of the year, otherwise 3.9.x.

danielesegato commented 3 years ago

The solution is to use flatpak.

no, it's not a solution. It's a workaround and I don't like it :)

band-a-prend commented 3 years ago

By the way the Gimp project switched their master branch to gtk+-3.0 in Oct 2010 but only at the end of Oct 2020 introduced first developer preview - Gimp-2.99.2.

So plugins developers actually had no time to port plugins yet as it was not clear is stabilized Gimp python3 plugin engine API stable or not. And I don't know if it currently "stable" or not. Also gtk+3 it seems significally changed this years.

The dialog windows for python2 plugins were provided by pygtk and it's not clear for me what the official tool now provides this interaction in Gimp-2.99.x.