From 831f7f52bc4b11c1b878d6ddddbd6154b9e27349 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 29 Jul 2023 16:01:57 +0300 Subject: [PATCH 1/4] Automatically update PIO Core PyPi dependencies on "upgrade" operation --- platformio/__init__.py | 19 ++++++++++++++ platformio/commands/upgrade.py | 36 +++++++++++++++++++++---- setup.py | 48 +++------------------------------- 3 files changed, 53 insertions(+), 50 deletions(-) diff --git a/platformio/__init__.py b/platformio/__init__.py index aa43c2d1..8ca26c74 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -56,3 +56,22 @@ __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.29", + "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.32", + "uvicorn >=0.16, <0.24", + "wsproto == 1.*", +] diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py index 9e4d61d2..3fb611ea 100644 --- a/platformio/commands/upgrade.py +++ b/platformio/commands/upgrade.py @@ -18,7 +18,7 @@ import subprocess import click -from platformio import VERSION, __version__, app, exception +from platformio import VERSION, __install_requires__, __version__, app, exception from platformio.http import fetch_remote_content from platformio.package.manager.core import update_core_packages from platformio.proc import get_pythonexe_path @@ -33,9 +33,14 @@ DEVELOP_INIT_SCRIPT_URL = ( @click.command("upgrade", short_help="Upgrade PlatformIO Core to the latest version") @click.option("--dev", is_flag=True, help="Use development branch") +@click.option("--only-dependencies", is_flag=True) @click.option("--verbose", "-v", is_flag=True) -def cli(dev, verbose): +def cli(dev, only_dependencies, verbose): + if only_dependencies: + return upgrade_pypi_dependencies(verbose) + update_core_packages() + if not dev and __version__ == get_latest_version(): return click.secho( "You're up-to-date!\nPlatformIO %s is currently the " @@ -50,11 +55,21 @@ def cli(dev, verbose): pkg_spec = DEVELOP_ZIP_URL if to_develop else "platformio" try: + # PIO Core subprocess.run( [python_exe, "-m", "pip", "install", "--upgrade", pkg_spec], check=True, stdout=subprocess.PIPE if not verbose else None, ) + + # PyPI dependencies + subprocess.run( + [python_exe, "-m", "platformio", "upgrade", "--only-dependencies"], + check=False, + stdout=subprocess.PIPE, + ) + + # Check version output = subprocess.run( [python_exe, "-m", "platformio", "--version"], check=True, @@ -87,9 +102,20 @@ def cli(dev, verbose): return True -def get_pkg_spec(to_develop): - if to_develop: - return +def upgrade_pypi_dependencies(verbose): + subprocess.run( + [ + get_pythonexe_path(), + "-m", + "pip", + "install", + "--upgrade", + "pip", + *__install_requires__, + ], + check=True, + stdout=subprocess.PIPE if not verbose else None, + ) def get_latest_version(): diff --git a/setup.py b/setup.py index ef9543e3..5872ccf5 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ # 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 ( @@ -22,52 +23,9 @@ from platformio import ( __title__, __url__, __version__, + __install_requires__, ) -py_37 = "python_version == '3.7'" -py_below_37 = "python_version < '3.7'" -py_gte_37 = "python_version >= '3.7'" -py_gte_38 = "python_version >= '3.8'" - -minimal_requirements = [ - "bottle==0.12.*", - "click==8.0.4; " + py_below_37, - "click==8.1.*; " + py_gte_37, - "colorama", - "marshmallow==3.14.1; " + py_below_37, - "marshmallow==3.19.0; " + py_37, - "marshmallow==3.20.*; " + py_gte_38, - "pyelftools==0.29", - "pyserial==3.5.*", # keep in sync "device/monitor/terminal.py" - "requests==2.*", - "semantic_version==2.10.*", - "tabulate==0.*", -] - -home_requirements = [ - "ajsonrpc==1.2.*", - "starlette==0.19.1; " + py_below_37, - "starlette==0.29.0; " + py_37, - "starlette==0.31.*; " + py_gte_38, - "uvicorn==0.16.0; " + py_below_37, - "uvicorn==0.22.0; " + py_37, - "uvicorn==0.23.*; " + py_gte_38, - "wsproto==1.0.0; " + py_below_37, - "wsproto==1.2.*; " + py_gte_37, -] - -# 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, - ): - minimal_requirements.append("urllib3<2") -except ImportError: - pass setup( @@ -79,7 +37,7 @@ setup( author_email=__email__, url=__url__, license=__license__, - install_requires=minimal_requirements + home_requirements, + install_requires=__install_requires__, python_requires=">=3.6", packages=find_packages(include=["platformio", "platformio.*"]), package_data={ From 89f4574680e6269e562bff849a90372a33ed3c40 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 29 Jul 2023 16:02:18 +0300 Subject: [PATCH 2/4] Remove unused files --- scripts/get-platformio.py | 105 -------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 scripts/get-platformio.py diff --git a/scripts/get-platformio.py b/scripts/get-platformio.py deleted file mode 100644 index 9d99ea97..00000000 --- a/scripts/get-platformio.py +++ /dev/null @@ -1,105 +0,0 @@ -# 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 tempfile -import io -import sys -import subprocess - -MAIN_SCRIPT_URL = "https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py" - - -def download_with_requests(url, dst): - import requests - - resp = requests.get(url, stream=True) - itercontent = resp.iter_content(chunk_size=io.DEFAULT_BUFFER_SIZE) - with open(dst, "wb") as fp: - for chunk in itercontent: - fp.write(chunk) - return dst - - -def download_with_urllib3(url, dst): - import urllib3 - - http = urllib3.PoolManager() - r = http.request("GET", url, preload_content=False) - - with open(dst, "wb") as out: - while True: - data = r.read(io.DEFAULT_BUFFER_SIZE) - if not data: - break - out.write(data) - - r.release_conn() - return dst - - -def download_with_urllib(url, dst): - if sys.version_info[0] == 3: - from urllib.request import urlopen - else: - from urllib import urlopen - - response = urlopen(url) - CHUNK = 16 * 1024 - with open(dst, "wb") as f: - while True: - chunk = response.read(CHUNK) - if not chunk: - break - f.write(chunk) - - return dst - - -def download_with_curl(url, dst): - subprocess.check_output(["curl", "-o", dst, url]) - return dst - - -def download_with_wget(url, dst): - subprocess.check_output(["wget", "-O", dst, url]) - return dst - - -def download_file(url, dst): - methods = [ - download_with_requests, - download_with_urllib3, - download_with_urllib, - download_with_curl, - download_with_wget, - ] - for method in methods: - try: - method(url, dst) - return dst - except: - pass - raise Exception("Could not download file '%s' to '%s' " % (url, dst)) - - -def main(): - with tempfile.NamedTemporaryFile() as tmp_file: - dst = download_file(MAIN_SCRIPT_URL, str(tmp_file.name)) - command = [sys.executable, dst] - command.extend(sys.argv[1:]) - subprocess.check_call(command) - - -if __name__ == "__main__": - sys.exit(main()) From 9170eee6e465b0baba9977e0fe964689f0e667bb Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 29 Jul 2023 16:03:14 +0300 Subject: [PATCH 3/4] Resolved an issue with "ModuleNotFoundError: No module named 'chardet'" on macOS ARM // Resolve #4702 --- HISTORY.rst | 1 + setup.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index cfe23a1c..c66f136c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -22,6 +22,7 @@ PlatformIO Core 6 * Resolved an issue encountered while utilizing the `pio pkg exec `__ command on the Windows platform to execute Python scripts from a package * Implemented a crucial improvement to the `pio run `__ command, guaranteeing that the ``monitor`` target is not executed if any of the preceding targets, such as ``upload``, encounter failures * `Cppcheck `__ v2.11 with new checks, CLI commands and various analysis improvements +* Resolved a critical issue that arose on macOS ARM platforms due to the Python "requests" module, leading to a "ModuleNotFoundError: No module named 'chardet'" (`issue #4702 `_) 6.1.9 (2023-07-06) ~~~~~~~~~~~~~~~~~~ diff --git a/setup.py b/setup.py index 5872ccf5..46716cc5 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,9 @@ from platformio import ( __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") setup( From f8b5266c1eafcc7c3528d8f845c531066dfe9758 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 29 Jul 2023 16:04:20 +0300 Subject: [PATCH 4/4] Bump version to 6.1.10a4 --- platformio/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio/__init__.py b/platformio/__init__.py index 8ca26c74..643dcc2e 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -VERSION = (6, 1, "10a3") +VERSION = (6, 1, "10a4") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio"