From 519042a1e2851a05d86560abdc3c691864ff7c19 Mon Sep 17 00:00:00 2001 From: Peter Dragun Date: Mon, 28 Jul 2025 09:56:45 +0200 Subject: [PATCH] feat: Deprecate Python 3.9 BREAKING CHANGE: - Minimal supported Python version is now 3.10. --- .github/workflows/pre_commit_check.yml | 2 +- .gitlab/ci/build.yml | 2 +- .gitlab/ci/common.yml | 6 ++--- .gitlab/ci/host-test.yml | 2 +- .mypy.ini | 2 +- docs/en/api-guides/build-system.rst | 2 +- docs/en/api-guides/tools/idf-docker-image.rst | 4 +++- docs/en/get-started/linux-macos-setup.rst | 22 +++++++++---------- docs/en/get-started/start-project.rst | 2 +- .../release-6.x/6.0/tools.rst | 10 +++++++++ docs/zh_CN/api-guides/build-system.rst | 2 +- .../api-guides/tools/idf-docker-image.rst | 4 +++- docs/zh_CN/get-started/start-project.rst | 2 +- ruff.toml | 3 ++- tools/check_python_dependencies.py | 12 +++------- tools/ci/check_type_comments.py | 2 +- tools/detect_python.fish | 4 ++-- tools/detect_python.sh | 4 ++-- tools/python_version_checker.py | 4 ++-- tools/requirements/requirements.core.txt | 2 -- 20 files changed, 49 insertions(+), 44 deletions(-) diff --git a/.github/workflows/pre_commit_check.yml b/.github/workflows/pre_commit_check.yml index d1d51bedaa..d821efbb57 100644 --- a/.github/workflows/pre_commit_check.yml +++ b/.github/workflows/pre_commit_check.yml @@ -23,7 +23,7 @@ jobs: - name: Set up Python environment uses: actions/setup-python@master with: - python-version: v3.8 + python-version: 3.10 - name: Install python packages run: | pip install pre-commit diff --git a/.gitlab/ci/build.yml b/.gitlab/ci/build.yml index 778edf0464..fa4797caa0 100644 --- a/.gitlab/ci/build.yml +++ b/.gitlab/ci/build.yml @@ -228,7 +228,7 @@ pytest_build_system_macos: - macos parallel: 3 variables: - PYENV_VERSION: "3.9" + PYENV_VERSION: "3.10" # CCACHE_DIR: "/cache/idf_ccache". On macOS, you cannot write to this folder due to insufficient permissions. CCACHE_DIR: "" # ccache will use "$HOME/Library/Caches/ccache". # Workaround for a bug in Parallels executor where CI_PROJECT_DIR is not an absolute path, diff --git a/.gitlab/ci/common.yml b/.gitlab/ci/common.yml index dac12555a0..5962b31ba0 100644 --- a/.gitlab/ci/common.yml +++ b/.gitlab/ci/common.yml @@ -52,9 +52,9 @@ variables: CHECKOUT_REF_SCRIPT: "$CI_PROJECT_DIR/tools/ci/checkout_project_ref.py" # Docker images - ESP_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-env-v6.0:1" - ESP_IDF_DOC_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-doc-env-v6.0:1-1" - TARGET_TEST_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/target-test-env-v6.0:1" + ESP_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-env-v6.0:2" + ESP_IDF_DOC_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-doc-env-v6.0:2-1" + TARGET_TEST_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/target-test-env-v6.0:2" SONARQUBE_SCANNER_IMAGE: "${CI_DOCKER_REGISTRY}/sonarqube-scanner:5" # cache python dependencies diff --git a/.gitlab/ci/host-test.yml b/.gitlab/ci/host-test.yml index b5843f2763..95cfd71e7c 100644 --- a/.gitlab/ci/host-test.yml +++ b/.gitlab/ci/host-test.yml @@ -350,7 +350,7 @@ test_pytest_macos: reports: junit: XUNIT_RESULT.xml variables: - PYENV_VERSION: "3.9" + PYENV_VERSION: "3.10" # Workaround for a bug in Parallels executor where CI_PROJECT_DIR is not an absolute path, # but a relative path to the build directory (builds/espressif/esp-idf instead of ~/builds/espressif/esp-idf. # GitLab sets the project dir to this template `//` diff --git a/.mypy.ini b/.mypy.ini index e4f451ca26..fffc03b032 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -1,7 +1,7 @@ [mypy] # Specifies the Python version used to parse and check the target program -python_version = 3.9 +python_version = 3.10 # Disallows defining functions without type annotations or with incomplete type annotations # True => enforce type annotation in all function definitions diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index 3d17759bfd..c99871ff52 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -130,7 +130,7 @@ For more detailed information about integrating ESP-IDF with CMake into an IDE, Setting up the Python Interpreter --------------------------------- -ESP-IDF works well with Python version 3.9+. +ESP-IDF works well with Python version 3.10+. ``idf.py`` and other Python scripts will run with the default Python interpreter, i.e., ``python``. You can switch to a different one like ``python3 $IDF_PATH/tools/idf.py ...``, or you can set up a shell alias or another script to simplify the command. diff --git a/docs/en/api-guides/tools/idf-docker-image.rst b/docs/en/api-guides/tools/idf-docker-image.rst index 2633a04195..5ed4b5ed62 100644 --- a/docs/en/api-guides/tools/idf-docker-image.rst +++ b/docs/en/api-guides/tools/idf-docker-image.rst @@ -1,3 +1,5 @@ +.. _idf-docker-image: + **************** IDF Docker Image **************** @@ -14,7 +16,7 @@ IDF Docker image (``espressif/idf``) is intended for building applications and l The image contains: - Common utilities such as ``git``, ``wget``, ``curl``, and ``zip``. -- Python 3.9 or newer. +- Python 3.10 or newer. - A copy of a specific version of ESP-IDF. See below for information about versions. ``IDF_PATH`` environment variable is set and points to the ESP-IDF location in the container. - All the build tools required for the specific version of ESP-IDF: CMake, Ninja, cross-compiler toolchains, etc. - All Python packages required by ESP-IDF are installed in a virtual environment. diff --git a/docs/en/get-started/linux-macos-setup.rst b/docs/en/get-started/linux-macos-setup.rst index 643f873816..c6c0b2e700 100644 --- a/docs/en/get-started/linux-macos-setup.rst +++ b/docs/en/get-started/linux-macos-setup.rst @@ -98,25 +98,23 @@ Then you need to install Apple Rosetta 2 by running Installing Python 3 ~~~~~~~~~~~~~~~~~~~ -Based on macOS `Catalina 10.15 release notes`_, use of Python 2.7 is not recommended and Python 2.7 is not included by default in future versions of macOS. Check what Python you currently have:: +Ensure that you have Python 3.10 or newer installed, as this is the minimum version supported by ESP-IDF. - python --version +Note that most of the recent versions of macOS include Python 3.9 (or older) by default, which is no longer supported. You will need to install Python 3.10 or later. -If the output is like ``Python 2.7.17``, your default interpreter is Python 2.7. If so, also check if Python 3 is not already installed on your computer:: +To install supported Python 3 on macOS: - python3 --version - -If the above command returns an error, it means Python 3 is not installed. - -Below is an overview of the steps to install Python 3. - - - Installing with HomeBrew_ can be done as follows:: + - With HomeBrew_, run:: brew install python3 - - If you have MacPorts_, you can run:: + - With MacPorts_, run:: - sudo port install python38 + sudo port install python313 + +.. note:: + + During installation, the install script will check for supported Python versions on your system and select the oldest version that meets the minimum requirement. .. _get-started-get-esp-idf: diff --git a/docs/en/get-started/start-project.rst b/docs/en/get-started/start-project.rst index 800ecfe3d2..3ee0868893 100644 --- a/docs/en/get-started/start-project.rst +++ b/docs/en/get-started/start-project.rst @@ -160,7 +160,7 @@ With some Linux distributions, you may get the error message similar to ``Could Python Compatibility ~~~~~~~~~~~~~~~~~~~~ -ESP-IDF supports Python 3.9 or newer. It is recommended to upgrade your operating system to a recent version satisfying this requirement. Other options include the installation of Python from `sources `_ or the use of a Python version management system such as `pyenv `_. +ESP-IDF supports Python 3.10 or newer. It is recommended to upgrade your operating system to a recent version satisfying this requirement. Other options include the installation of Python from `sources `_ or the use of a Python version management system such as `pyenv `_. .. only:: esp32 or esp32s2 or esp32s3 diff --git a/docs/en/migration-guides/release-6.x/6.0/tools.rst b/docs/en/migration-guides/release-6.x/6.0/tools.rst index 349b6c05b2..c1ba13eaca 100644 --- a/docs/en/migration-guides/release-6.x/6.0/tools.rst +++ b/docs/en/migration-guides/release-6.x/6.0/tools.rst @@ -30,3 +30,13 @@ We recommend to use ``idf.py gdb`` instead of ``idf.py gdbgui``, or debug in Ecl All commands with eFuse functionality now require a serial port to be specified. This was done to prevent accidental use of the wrong port, as these operations are irreversible. For all ``idf.py efuse*`` commands, you now need to specify the serial port with the ``--port`` argument (or ``ESPPORT`` environment variable). If the port is not specified, the command will fail with an error message. + + +Python 3.9 Deprecation +---------------------- + +Python 3.9 is no longer supported. The minimum required Python version is now 3.10. Please upgrade your Python installation to version 3.10 or later. Alternatively, you can use the provided Docker images; for more information, see :ref:`idf-docker-image`. + +Refer to the official `Python documentation `_ for instructions on upgrading Python for your operating system. + +For Linux users, it is recommended to upgrade to a newer version of your distribution that includes a supported Python version. diff --git a/docs/zh_CN/api-guides/build-system.rst b/docs/zh_CN/api-guides/build-system.rst index 680b831fe4..9ebd7c27b0 100644 --- a/docs/zh_CN/api-guides/build-system.rst +++ b/docs/zh_CN/api-guides/build-system.rst @@ -130,7 +130,7 @@ idf.py 设置 Python 解释器 ------------------ -ESP-IDF 适用于 Python 3.9 以上版本。 +ESP-IDF 适用于 Python 3.10 以上版本。 ``idf.py`` 和其他的 Python 脚本会使用默认的 Python 解释器运行,如 ``python``。你可以通过 ``python3 $IDF_PATH/tools/idf.py ...`` 命令切换到别的 Python 解释器,或者通过设置 shell 别名或其他脚本来简化该命令。 diff --git a/docs/zh_CN/api-guides/tools/idf-docker-image.rst b/docs/zh_CN/api-guides/tools/idf-docker-image.rst index 3641297621..7803c4c105 100644 --- a/docs/zh_CN/api-guides/tools/idf-docker-image.rst +++ b/docs/zh_CN/api-guides/tools/idf-docker-image.rst @@ -1,3 +1,5 @@ +.. _idf-docker-image: + ******************** IDF Docker 镜像 ******************** @@ -14,7 +16,7 @@ IDF Docker 镜像 (``espressif/idf``) 为使用特定版本的 ESP-IDF 自动化 该镜像包含以下内容: - 常见的实用工具,如 ``git``、``wget``、``curl`` 和 ``zip``。 -- Python 3.9 或更高版本。 +- Python 3.10 或更高版本。 - 特定版本 ESP-IDF 的副本。有关版本信息,请参阅下文。该副本中设置了 ``IDF_PATH`` 环境变量,并指向容器中 ESP-IDF 的位置。 - 构建特定版本 ESP-IDF 所需工具:CMake、Ninja、交叉编译器工具链等。 - ESP-IDF 需要的所有 Python 软件包。这些软件包均已安装在虚拟环境中。 diff --git a/docs/zh_CN/get-started/start-project.rst b/docs/zh_CN/get-started/start-project.rst index d3c17d3034..131a762917 100644 --- a/docs/zh_CN/get-started/start-project.rst +++ b/docs/zh_CN/get-started/start-project.rst @@ -160,7 +160,7 @@ 兼容的 Python 版本 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -ESP-IDF 支持 Python 3.9 及以上版本,建议升级操作系统到最新版本从而更新 Python。也可选择从 `sources `_ 安装最新版 Python,或使用 Python 管理系统如 `pyenv `_ 对版本进行升级管理。 +ESP-IDF 支持 Python 3.10 及以上版本,建议升级操作系统到最新版本从而更新 Python。也可选择从 `sources `_ 安装最新版 Python,或使用 Python 管理系统如 `pyenv `_ 对版本进行升级管理。 .. only:: esp32 or esp32s2 or esp32s3 diff --git a/ruff.toml b/ruff.toml index 4d795ecbf0..9e4b8ebda6 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,5 +1,5 @@ line-length = 120 -target-version = "py38" +target-version = "py310" [format] quote-style = "single" @@ -12,6 +12,7 @@ target-version = "py38" "F", # pyflakes "W", # pycodestyle "I", # reorder-imports + "UP", # pyupgrade ] ignore = [ "E203", # whitespace before ':' diff --git a/tools/check_python_dependencies.py b/tools/check_python_dependencies.py index 77bace591e..45f261a15b 100755 --- a/tools/check_python_dependencies.py +++ b/tools/check_python_dependencies.py @@ -20,15 +20,9 @@ except ImportError: ) sys.exit(1) -try: - from importlib.metadata import PackageNotFoundError - from importlib.metadata import requires as _requires - from importlib.metadata import version as _version -except ImportError: - # compatibility for python <=3.7 - from importlib_metadata import PackageNotFoundError # type: ignore - from importlib_metadata import requires as _requires # type: ignore - from importlib_metadata import version as _version # type: ignore +from importlib.metadata import PackageNotFoundError +from importlib.metadata import requires as _requires +from importlib.metadata import version as _version try: from typing import Set diff --git a/tools/ci/check_type_comments.py b/tools/ci/check_type_comments.py index 38865b0842..f720f7ef5a 100755 --- a/tools/ci/check_type_comments.py +++ b/tools/ci/check_type_comments.py @@ -29,7 +29,7 @@ def types_valid_ignored_rules(file_name): # type: (str) -> bool """ Run Mypy check with rules for ignore list on the given file, return TRUE if Mypy check passes """ - mypy_exit_code = subprocess.call('mypy {} --python-version 3.8 --allow-untyped-defs'.format(file_name), shell=True) + mypy_exit_code = subprocess.call('mypy {} --python-version 3.10 --allow-untyped-defs'.format(file_name), shell=True) return not bool(mypy_exit_code) diff --git a/tools/detect_python.fish b/tools/detect_python.fish index 5b53fb9ab5..8e9947f3a8 100644 --- a/tools/detect_python.fish +++ b/tools/detect_python.fish @@ -3,11 +3,11 @@ # This is a port of detect_python.sh. More information are provided there. set OLDEST_PYTHON_SUPPORTED_MAJOR 3 -set OLDEST_PYTHON_SUPPORTED_MINOR 9 +set OLDEST_PYTHON_SUPPORTED_MINOR 10 set -x ESP_PYTHON python -for p_cmd in python3 python python3.9 python3.10 python3.11 python3.12 python3.13; +for p_cmd in python3 python python3.10 python3.11 python3.12 python3.13; $p_cmd --version >/dev/null 2>&1; or continue echo "Checking \"$p_cmd\" ..." diff --git a/tools/detect_python.sh b/tools/detect_python.sh index eb3b759f92..3f84a9b91e 100644 --- a/tools/detect_python.sh +++ b/tools/detect_python.sh @@ -8,11 +8,11 @@ # 3. If required version of python is not found, script will fail OLDEST_PYTHON_SUPPORTED_MAJOR=3 -OLDEST_PYTHON_SUPPORTED_MINOR=9 +OLDEST_PYTHON_SUPPORTED_MINOR=10 ESP_PYTHON=python -for p_cmd in python3 python python3.9 python3.10 python3.11 python3.12 python3.13; do +for p_cmd in python3 python python3.10 python3.11 python3.12 python3.13; do $p_cmd --version >/dev/null 2>&1 || continue echo "Checking \"$p_cmd\" ..." diff --git a/tools/python_version_checker.py b/tools/python_version_checker.py index aadaa29df4..634326637a 100755 --- a/tools/python_version_checker.py +++ b/tools/python_version_checker.py @@ -8,7 +8,7 @@ # # There are related tools/detect_python.{sh,fish} scripts which are called earlier when the paths are not properly # set-up and they only intend to prefer the use of Python 3 over Python 2. Why not more? All possible executables -# (python3.9, python3.10, ...) cannot be hardcoded there and at the end, the user is responsible to set-up a system +# (python3.10, python3.11, ...) cannot be hardcoded there and at the end, the user is responsible to set-up a system # where "python" or "python3" of compatible version is available. import sys @@ -19,7 +19,7 @@ try: except ImportError: pass -OLDEST_PYTHON_SUPPORTED = (3, 9) # keep it as tuple for comparison with sys.version_info +OLDEST_PYTHON_SUPPORTED = (3, 10) # keep it as tuple for comparison with sys.version_info def _ver_to_str(it): # type: (Iterable) -> str diff --git a/tools/requirements/requirements.core.txt b/tools/requirements/requirements.core.txt index 13cbb8a1e6..a944b6abe6 100644 --- a/tools/requirements/requirements.core.txt +++ b/tools/requirements/requirements.core.txt @@ -6,8 +6,6 @@ setuptools packaging -# importlib_metadata: is part of python3.8 and newer as importlib.metadata -importlib_metadata; python_version < "3.8" click pyserial cryptography