schollii / pypubsub

A Python publish-subcribe library (moved here from SourceForge.net where I had it for many years)
194 stars 29 forks source link

Python 2 support #9

Closed swt2c closed 5 years ago

swt2c commented 6 years ago

Any chance that you would be willing to consider supporting Python 2 again? The embedded copy of PyPubSub was removed from wxPython Phoenix and a external dependency was added on PyPubSub. However, Phoenix still supports Python 2, so this has resulted in Phoenix being uninstallable in certain cases.

Ref https://github.com/wxWidgets/Phoenix/issues/887

schollii commented 6 years ago

It is likely not possible because code uses type annotations, I don't think there is a backward compatibility lib that could help with that (contrary to many python 3 stdlib functions/modules which have been backported to 2.7). I suppose a script could be written that strips the hints and translates stuff that six just cannot handle, but I don't have the time to do this. I'd be happy to offer guidance and support for a PR.

swt2c commented 6 years ago

Okay, so you wouldn't be opposed to a PR? PEP 484 specifies an alternative syntax for type hints which is compatible with 2.7: https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code Would you be opposed to that?

schollii commented 6 years ago

I took a look and a different solution is needed because it would affect the Python 3 api too much. Python 2 is on its way out. A solution based on "import py27pubsub" and that package would be generated from a script that uses lib3to2 eg. Then all you need is a small module that wxpython user imports in their main module, it figures out which pypubsub to load (effectively binding "pypubsub" name to either py27pubsub module or pypubsub module). This might complicate packaging of a wx app into an exe (would have to try, might be no problem), so it might be better to document that for running app on python 2.7 theres one line of code to change in main.

swt2c commented 6 years ago

Python 2 may be on its way out, but it's not gone yet - and will be around for a while, especially in enterprise distributions.

I am not sure about lib3to2. It seems unmaintained for several years.

jensgoe commented 6 years ago

The main problem is that calling "pip install pypubsub" with python 2.7 installs pypubsub 4. Maybe it is enough to publish version 3.3.0 as the last py27 package at pip.

schollii commented 6 years ago

@jensgoe Overriding the default is not feasible for you? pip install pypubsub=3.3.0

Alternately, I just merged a PR from Ned that adds the python_requires which will basically make pypubsub v4 ignored by pip of python 2.x. No official 4.0.1 release yet as there are a couple other fixes to make, so you will have to git clone or git archive followed by pip install . --no-index or python setup.py install develop.

swt2c commented 6 years ago

@jensgoe Overriding the default is not feasible for you? pip install pypubsub=3.3.0 Alternately, I just merged a PR from Ned that adds the python_requires which will basically make pypubsub v4 ignored by pip of python 2.x. No official 4.0.1 release yet as there are a couple other fixes to make, so you will have to git clone or git archive followed by pip install . --no-index or python setup.py install develop.

Just to confirm: 3.3.0 and 4.0.0 are API compatible with each other?

schollii commented 6 years ago

Backward but not forward compatible: Code written for 3.3.0 API will work with 4.0.0 API (IIRC, and based on the code changes from merge I just looked at), but code written that uses stuff specific to 4.0.0 (one or two functions have extra kwarg) will not work in an app written for 3.3.0.

swt2c commented 6 years ago

Okay, I suppose that would probably work then. The only downside is that I'm going to have to package both 3.3.0 (for Python 2) and 4.0.0 (for Python 3) separately.

schollii commented 6 years ago

Can you clarify: Package pypubsub? with your app?

swt2c commented 6 years ago

Can you clarify: Package pypubsub? with your app?

Distribution packages.

schollii commented 6 years ago

If you expand on that, there might be alternative. For one thing, if your app is compatible with both Python 2 and 3, and lists pypubsub as a depencency, then the correct version of pypubsub will be fetched (3.3.0 if your app gets installed via Python 2's pip, 4.0 via Python 3's pip), once I release 4.0.1 (which will have the python_requries in setup.py).

RobinD42 commented 6 years ago

He's talking about .rpm or .deb package files

schollii commented 5 years ago

To address the original issue, namely that wxPython Phoenix supports Python 2.7 in which case pypubsub cannot be used in such wxPython app: a viable fix is to have wx.lib.pypubsub be pypubsub 4, and wx.lib.pypubsub_old be the old one. Or some alternative naming scheme, but basically have 2 separate libraries, because Python 2 is no longer maintained and is only going to be around for a short while, and is far inferior to Python 3. Any measure to support Python 2 should be temporary.

Since such fix belongs on the wxPython side, I'm going to close this, but I'm happy to discuss other approaches than the ones proposed (which is to pollute the pypubsub 4.x implementation to support a dead version of Python), either here or in the dev forum of pypubsub.