From c74c9778a18cafab0f57e03f70d082aab200567a Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 6 Jan 2024 16:24:01 +0200 Subject: [PATCH] Enhance PIP dependency declarations // Resolve #4819 --- .github/workflows/deployment.yml | 3 +- HISTORY.rst | 1 + platformio/__init__.py | 19 ---------- platformio/commands/upgrade.py | 9 ++--- platformio/pipdeps.py | 61 ++++++++++++++++++++++++++++++++ setup.py | 23 ++---------- 6 files changed, 71 insertions(+), 45 deletions(-) create mode 100644 platformio/pipdeps.py diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 0941b759..8517d7bd 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -35,7 +35,8 @@ jobs: tox -e testcore - name: Build Python source tarball - run: python setup.py sdist bdist_wheel + # run: python setup.py sdist bdist_wheel + run: python setup.py sdist - name: Publish package to PyPI if: ${{ github.ref == 'refs/heads/master' }} diff --git a/HISTORY.rst b/HISTORY.rst index 2df7ccd7..dd40176f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -25,6 +25,7 @@ test-driven methodologies, and modern toolchains for unrivaled success. * Drastically enhanced the speed of project building when operating in verbose mode (`issue #4783 `_) * Upgraded the build engine to the latest version of SCons (4.6.0) to improve build performance, reliability, and compatibility with other tools and systems (`release notes `__) * Enhanced the handling of built-in variables in |PIOCONF| during |INTERPOLATION| (`issue #4695 `_) +* Enhanced PIP dependency declarations for improved reliability and extended support to include Python 3.6 (`issue #4819 `_) * Implemented a fail-safe mechanism to terminate a debugging session if an unknown CLI option is passed (`issue #4699 `_) * Rectified an issue where ``${platformio.name}`` erroneously represented ``None`` as the default `project name `__ (`issue #4717 `_) * Resolved an issue where the ``COMPILATIONDB_INCLUDE_TOOLCHAIN`` setting was not correctly applying to private libraries (`issue #4762 `_) diff --git a/platformio/__init__.py b/platformio/__init__.py index 3d5d9b87..677958c8 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -52,22 +52,3 @@ __check_internet_hosts__ = [ "88.198.170.159", # platformio.org "github.com", ] + __registry_mirror_hosts__ - -__install_requires__ = [ - # Core requirements - "bottle == 0.12.*", - "click >=8.0.4, <=8.2", - "colorama", - "marshmallow == 3.*", - "pyelftools == 0.30", - "pyserial == 3.5.*", # keep in sync "device/monitor/terminal.py" - "requests == 2.*", - "semantic_version == 2.10.*", - "tabulate == 0.*", -] + [ - # PIO Home requirements - "ajsonrpc == 1.2.*", - "starlette >=0.19, <=0.34", - "uvicorn >=0.16, <=0.25", - "wsproto == 1.*", -] diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py index 3fb611ea..129e3fa1 100644 --- a/platformio/commands/upgrade.py +++ b/platformio/commands/upgrade.py @@ -18,9 +18,10 @@ import subprocess import click -from platformio import VERSION, __install_requires__, __version__, app, exception +from platformio import VERSION, __version__, app, exception from platformio.http import fetch_remote_content from platformio.package.manager.core import update_core_packages +from platformio.pipdeps import get_pip_dependencies from platformio.proc import get_pythonexe_path PYPI_JSON_URL = "https://pypi.org/pypi/platformio/json" @@ -37,7 +38,7 @@ DEVELOP_INIT_SCRIPT_URL = ( @click.option("--verbose", "-v", is_flag=True) def cli(dev, only_dependencies, verbose): if only_dependencies: - return upgrade_pypi_dependencies(verbose) + return upgrade_pip_dependencies(verbose) update_core_packages() @@ -102,7 +103,7 @@ def cli(dev, only_dependencies, verbose): return True -def upgrade_pypi_dependencies(verbose): +def upgrade_pip_dependencies(verbose): subprocess.run( [ get_pythonexe_path(), @@ -111,7 +112,7 @@ def upgrade_pypi_dependencies(verbose): "install", "--upgrade", "pip", - *__install_requires__, + *get_pip_dependencies(), ], check=True, stdout=subprocess.PIPE if not verbose else None, diff --git a/platformio/pipdeps.py b/platformio/pipdeps.py new file mode 100644 index 00000000..f5512cde --- /dev/null +++ b/platformio/pipdeps.py @@ -0,0 +1,61 @@ +# Copyright (c) 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import platform +import sys + +PY36 = sys.version_info[0:2] == (3, 6) + + +def get_pip_dependencies(): + core = [ + "bottle == 0.12.*", + "click >=8.0.4, <9", + "colorama", + "marshmallow == 3.*", + "pyelftools == 0.30", + "pyserial == 3.5.*", # keep in sync "device/monitor/terminal.py" + "requests == 2.*", + "semantic_version == 2.10.*", + "tabulate == 0.*", + ] + + home = [ + # PIO Home requirements + "ajsonrpc == 1.2.*", + "starlette >=0.19, <0.35", + "uvicorn %s" % ("== 0.16.0" if PY36 else ">=0.16, <0.26"), + "wsproto == 1.*", + ] + + extra = [] + + # issue #4702; Broken "requests/charset_normalizer" on macOS ARM + if platform.system() == "Darwin" and "arm" in platform.machine().lower(): + extra.append("chardet>=3.0.2,<6") + + # issue 4614: urllib3 v2.0 only supports OpenSSL 1.1.1+ + try: + import ssl # pylint: disable=import-outside-toplevel + + if ssl.OPENSSL_VERSION.startswith("OpenSSL ") and ssl.OPENSSL_VERSION_INFO < ( + 1, + 1, + 1, + ): + extra.append("urllib3<2") + except ImportError: + pass + + return core + home + extra diff --git a/setup.py b/setup.py index bdb10a31..7a7c5076 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import platform from setuptools import find_packages, setup from platformio import ( @@ -23,26 +22,8 @@ from platformio import ( __title__, __url__, __version__, - __install_requires__, ) - -# issue #4702; Broken "requests/charset_normalizer" on macOS ARM -if platform.system() == "Darwin" and "arm" in platform.machine().lower(): - __install_requires__.append("chardet>=3.0.2,<4") - -# issue 4614: urllib3 v2.0 only supports OpenSSL 1.1.1+ -try: - import ssl - - if ssl.OPENSSL_VERSION.startswith("OpenSSL ") and ssl.OPENSSL_VERSION_INFO < ( - 1, - 1, - 1, - ): - __install_requires__.append("urllib3<2") -except ImportError: - pass - +from platformio.pipdeps import get_pip_dependencies setup( name=__title__, @@ -53,7 +34,7 @@ setup( author_email=__email__, url=__url__, license=__license__, - install_requires=__install_requires__, + install_requires=get_pip_dependencies(), python_requires=">=3.6", packages=find_packages(include=["platformio", "platformio.*"]), package_data={