chirp icon indicating copy to clipboard operation
chirp copied to clipboard

Python 3.9 fixups

Open asheplyakov opened this issue 2 years ago • 22 comments

As of now CHIRP fails to start with Python 3.9:

  • Complains about missing importlib_resources module (although importlib is available as a part of the standard library)
  • Application icon and stock configs can't be found (since chirp.share is not a proper python package)

With this patchset I can use CHIRP with Python 3.9.

asheplyakov avatar Dec 29 '22 04:12 asheplyakov

You need to install the packages in requirements.txt to get the importlib-resources compatibility package. 

I've tried that (via pip install -r requirements.txt), the application failed to start anyway. I haven't bothered to find out the exact cause, instead I tweaked imports to use the importlib.resources from the stdlib, and it worked for me. 

Also setup.py skips chirp/share and chirp/stock_configs directories (they are not python packages), as a result the application can't find icon and fails to start. 

The macos build is already using python 3.8 and it works fine that way.

asheplyakov avatar Dec 29 '22 08:12 asheplyakov

They're good enough for the bundler to pick up - I didn't really think they had to be proper python packages to be considered resources, but I dunno. Maybe @vishwin has some context here, but I can poke with python3.9 a little later. I thought that the thing we specifically needed was only in 3.10...

kk7ds avatar Dec 29 '22 16:12 kk7ds

The new-style API was introduced in Python 3.10, and to simplify maintenance (especially when Python 3.11 formally marked the old-style but imo more concise API deprecated), the package is used for Python < 3.10.

vishwin avatar Dec 29 '22 16:12 vishwin

As for package detection itself, setuptools does (or at least did) consider chirp.share a package implicitly, but of course explicit is always better than implicit.

vishwin avatar Dec 29 '22 16:12 vishwin

@asheplyakov Is it possible that just the __init__.py additions make it work for you? Like @vishwin it surely seems like 3.9 should require importlib_resources to work properly. Have you verified that your pip install command is actually installing that lib and that it's importable via the python that you're using to run chirp?

kk7ds avatar Dec 29 '22 16:12 kk7ds

On a clean python 3.9 docker image, python3 setup.py install installs importlib-resources as a dep as expected, and I can launch chirp from the installed directory just fine and it runs, finds the stock stuff, icons, etc, which I can confirm is installed to the proper location.

So, I'm not sure what the problem is, but I don't think it's specific to 3.9.

kk7ds avatar Dec 29 '22 17:12 kk7ds

python3 setup.py install installs importlib-resources as a dep as expected ...

Installing via setup.py directly is deprecated. pip3 install [directory] seems to be the way forward.

You should see an error message like the following when you invoke setup.py directly:

SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.

Sorry for interjecting...

goldstar611 avatar Dec 29 '22 21:12 goldstar611

That's not an error, but a warning. And yes PEP-517 compliance is next on the list. Until then, setuptools can theoretically be pinned to 58, which is the last version with full setup.py support.

vishwin avatar Dec 29 '22 22:12 vishwin

On second look, both of these commits are wrong. The importlib_resources package has to be used for Python < 3.10, not only for the new-style files() and as_files() API introduced in 3.9, but PEP-420 namespace package support only landed in time for 3.10. Both chirp.share and chirp.stock_configs are namespace packages, which are not to have __init__.py.

vishwin avatar Dec 29 '22 23:12 vishwin

On second look, both of these commits are wrong. The importlib_resources package has to be used for Python < 3.10, not only for the new-style files() and as_files() API introduced in 3.9, but PEP-420 namespace package support only landed in time for 3.10. Both chirp.share and chirp.stock_configs are namespace packages, which are not to have __init__.py.

Yep, this is exactly what I meant when I said "I thought that the thing we specifically needed was only in 3.10...". Further confirmed, I think, by the fact that it works fine for me in 3.9.

kk7ds avatar Dec 29 '22 23:12 kk7ds

python3 setup.py install installs importlib-resources as a dep as expected ...

Yes. But it skips share and stock_configs (unless there is the __init__.py file in the directory)

Installing via setup.py directly is deprecated. pip3 install [directory] seems to be the way forward.

  1. pip calls setup.py install anyway, and prints the corresponding warning:
  removing build/bdist.linux-x86_64/wheel
  Building wheel for chirp (setup.py) ... done
  Created wheel for chirp: filename=chirp-py3dev-py3-none-any.whl size=1274863 sha256=1ab33209db1015ce3e02b9300a5daeef568b97d1d150da2ed31f8a7a7bf929f3
  Stored in directory: /usr/src/tmp/pip-ephem-wheel-cache-zqphcjaw/wheels/20/54/1a/b3128b303c56af26a8ebbd9f771961fb0e2c24b0734d4c6b09
  WARNING: Built wheel for chirp is invalid: Metadata 1.2 mandates PEP 440 version, but 'py3dev' is not
Failed to build chirp
Installing collected packages: chirp
[skipped]
  Running command Running setup.py install for chirp
  /usr/lib64/python3/site-packages/setuptools/dist.py:499: UserWarning: The version specified ('py3dev') is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.

  Running setup.py install for chirp ... done
  DEPRECATION: chirp was installed using the legacy 'setup.py install' method, because a wheel could not be built for it. A possible replacement is to fix the wheel build issue reported above. Discussion can be found at https://github.com/pypa/pip/issues/8368
Successfully installed chirp-py3dev

  1. I'm building an rpm package. python3 -m pip install is not the best tool for the task, so I use pyproject_installer instead like this
python3 -m pyproject_installer -v build
python3 -m pyproject_installer -v install --destdir=%buildroot

This one successfully builds a wheel and dist-info.

asheplyakov avatar Dec 30 '22 08:12 asheplyakov

Yes. But it skips share and stock_configs (unless there is the __init__.py file in the directory)

If that was the case, I would not have had implemented this the way it is.

I'm building an rpm package

Any chance you have some outdated components in your chain by virtue of using RPMs provided by your operating system's repositories?

vishwin avatar Dec 30 '22 11:12 vishwin

Yes. But it skips share and stock_configs (unless there is the __init__.py file in the directory)

If that was the case, I would not have had implemented this the way it is.

Apparently it didn't work as intended.

I'm building an rpm package

Any chance you have some outdated components in your chain by virtue of using RPMs provided by your operating system's repositories?

Which components should I check, and what are the correct versions? (the only versioned dependency in requirements.txt is wxPython>=4.0,<4.2.0 ; platform_system=="Linux", and I use wxPython 4.0.7)

asheplyakov avatar Dec 31 '22 15:12 asheplyakov

Yes. But it skips share and stock_configs (unless there is the __init__.py file in the directory)

If that was the case, I would not have had implemented this the way it is.

Apparently it didn't work as intended.

As noted, it does for me, on python 3.8, 3.9, and 3.10.

kk7ds avatar Dec 31 '22 16:12 kk7ds

I am trying to run chirp on Python3 to help test the drivers, but seems the installer doesnt work and is looking for python package wxPython which i cant install because somehow its looking for GTK2 ?

Any pointers on getting this running on Python 3.8 ?

kooscode avatar Jan 05 '23 05:01 kooscode

I am trying to run chirp on Python3 to help test the drivers, but seems the installer doesnt work and is looking for python package wxPython which i cant install because somehow its looking for GTK2 ?

Any pointers on getting this running on Python 3.8 ?

It would help to know what system you're running, but it works fine on python 3.8 without anything specific. See this page: https://chirp.danplanet.com/projects/chirp/wiki/DevelopersPython3Environment

Probably best to discuss further on the devel mailing list, separate from this PR.

kk7ds avatar Jan 05 '23 05:01 kk7ds

Ah - good point. sorry. I am running Ubuntu 20.04

kooscode avatar Jan 05 '23 05:01 kooscode

It would help to know what system you're running, but it works fine on python 3.8 without anything specific. See this page: https://chirp.danplanet.com/projects/chirp/wiki/DevelopersPython3Environment

Seems there is no branch py3 for this repo and the above instructions call out to checkout that branch?

fatal: 'origin/py3' is not a commit and a branch 'py3' cannot be created from it

kooscode avatar Jan 05 '23 05:01 kooscode

Seems there is no branch py3 for this repo and the above instructions call out to checkout that branch?

fatal: 'origin/py3' is not a commit and a branch 'py3' cannot be created from it

Because py3 is now the main branch.

vishwin avatar Jan 05 '23 06:01 vishwin

After a very lengthy build process, I was able to get CHIRP and all of it's dependencies installed on a fresh Ubuntu 20.04 VM using the commands below. (It is probably not necessary to run pip as root and you'll see a message discouraging it.)

sudo apt install python3-pip libgtk-3-dev libpng-dev libtiff-dev libjpeg-dev libcurl4-openssl-dev
sudo -H pip3 install attrdict
sudo -H pip3 install "chirp[wx] @ git+https://github.com/kk7ds/chirp.git"

goldstar611 avatar Jan 05 '23 14:01 goldstar611

Guys, on linux, don't install wxpython from pip - it builds the entire thing for no reason. Follow the instructions on the build page, install the distro package and then do the pip stuff. Should be two seconds.

kk7ds avatar Jan 05 '23 14:01 kk7ds

Ah, I knew there should be a faster way. Thanks for the tip Dan. And now I understand why wx is listed as an extra in setup.py

From https://chirp.danplanet.com/projects/chirp/wiki/DevelopersPython3Environment:

sudo apt install git python3-wxgtk4.0 python3-serial python3-six python3-future python3-requests python3-pip

then

pip install git+https://github.com/kk7ds/chirp

Another confirm that the current tip of master installs (and runs) on Ubuntu 20.04 with python 3.8.

goldstar611 avatar Jan 05 '23 15:01 goldstar611