connectedhomeip: Pigweed code breaks with python 3.10

Problem

  • Expected - Python 3 update would be handled seamlessly
  • Actual - See screenshot
  • Steps - upgrade to Jellyfish try to activate master
  • Config - N/A
  • screenshots, images, logs, etc.
  • image

Proposed Solution

Change third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py

    # We expect Python 3.8, but if it came from CIPD let it pass anyway.
    if ('3.8' not in version and '3.9' not in version
            and 'chromium' not in version):
        print('=' * 60, file=sys.stderr)
        print('Unexpected Python version:', version, file=sys.stderr)
        print('=' * 60, file=sys.stderr)
        return False

There may be a better way to do this ^^ It doesn’t appear to choose the recognised default version of python for the shell as set by update-alternatives

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 34 (15 by maintainers)

Commits related to this issue

Most upvoted comments

In conclusion, before bootstrap follow this steps:

  1. Run this code install-python-3.9.12.sh.
  2. Add this patch Pigweed code breaks with python 3.10 #16664 (comment)
  3. Run source scripts/activate.sh from connectedhomeip.
  4. After failure go to the directory mentioned and remove all links.

This is possibly unsafe, and not a real fix, since it requires running a binary to override system defaults. System defaults may be IT policy of a given organization

Like @nekleo reported above, this is no longer an issue.

I just verified that I am able to complete ./scripts/bootstrap.sh without issues on raspberry pi 4 with Ubuntu 22.04, which comes with Python 3.10.

If you change the global python version, sure CHIP will build and work, but there are a lot of packages in Ubuntu 22 which assume Python 3.10. By reverting the system Python back to 3.8 you are going to break those other packages. Maybe you don’t use those other packages, but if you do, you are going to end up with something that is hard to debug when they fail to work.

The deadsnakes technique installs 3.9 along side 3.10 so that both are on your system. Then CHIP is adjusted to use the python3.9 install with that small edit posted above.

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt update && sudo apt upgrade
$ sudo apt install python3.9 python3.9-dev python3.9-venv

This should have worked but it doesn’t. $ export PW_BOOTSTRAP_PYTHON=python3.9

Get annoyed at pigweed and simply hard code it:

jonsmirl@ares:~/aosp/chip/third_party/pigweed/repo$ git diff
diff --git a/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py b/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py
index b8841b99..8bfd447d 100644
--- a/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py
+++ b/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py
@@ -145,6 +145,7 @@ def install(  # pylint: disable=too-many-arguments
 ):
     """Creates a venv and installs all packages in this Git repo."""
 
+    python='python3.9'
     version = subprocess.check_output(
         (python, '--version'), stderr=subprocess.STDOUT).strip().decode()
     # We expect Python 3.8, but if it came from CIPD let it pass anyway.

Then bootstrap will work: source ./scripts/bootstrap.sh

Don’t change the python system definition (update-alternatives), it you do that a whole bunch of other packages are going to cease working.

@chadnorvell will do that tomorrow. Thanks for looking into this.

@tcarmelveilleux @vringar

Still waiting for the real solution.

Solution ahead: If Tornadoweb is updated for Python 3.10.x, there should be no reason not supporting 3.10 in pigweed.

However, matters requirements for numpy must be higher than version 1.22.

Using the docker container for development mitigates this problem (VS Code Instructions)