From 2c94fb2aad804e10bae53704e113e107d04c2b89 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 27 Apr 2023 14:24:34 +0300 Subject: [PATCH] Resolved installation issues with PIO Remote on Raspberry Pi and other small form-factor PCs // Resolve #4425 , Resolve #4493 , Resolve #4607 --- HISTORY.rst | 1 + docs | 2 +- platformio/__init__.py | 4 +- platformio/package/manager/core.py | 139 +---------------------------- platformio/remote/cli.py | 10 ++- 5 files changed, 13 insertions(+), 143 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 6869230c..0f9223e9 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -33,6 +33,7 @@ PlatformIO Core 6 * Resolved an issue where native tests would fail if a custom program name was specified (`issue #4546 `_) * Resolved an issue where the PlatformIO |DEBUGGING| solution was not escaping the tool installation process into MI2 correctly (`issue #4565 `_) * Resolved an issue where multiple targets were not executed sequentially (`issue #4604 `_) +* Resolved installation issues with PIO Remote on Raspberry Pi and other small form-factor PCs (`issue #4425 `_, `issue #4493 `_, `issue #4607 `_) 6.1.6 (2023-01-23) ~~~~~~~~~~~~~~~~~~ diff --git a/docs b/docs index 890d8e20..88d4514c 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 890d8e20fed40f653ac84ff366ac16d805b4bf01 +Subproject commit 88d4514cccd0b99d7d5578e27c1396cb61b617e3 diff --git a/platformio/__init__.py b/platformio/__init__.py index 1f3229d9..8b19e12b 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys - VERSION = (6, 1, "7b2") __version__ = ".".join([str(s) for s in VERSION]) @@ -46,7 +44,7 @@ __pioremote_endpoint__ = "ssl:host=remote.platformio.org:port=4413" __core_packages__ = { "contrib-piohome": "~3.4.2", - "contrib-pysite": "~2.%d%d.0" % (sys.version_info.major, sys.version_info.minor), + "contrib-pioremote": "~1.0.0", "tool-scons": "~4.40502.0", "tool-cppcheck": "~1.270.0", "tool-clangtidy": "~1.150005.0", diff --git a/platformio/package/manager/core.py b/platformio/package/manager/core.py index 28fab07b..ca5c5e01 100644 --- a/platformio/package/manager/core.py +++ b/platformio/package/manager/core.py @@ -12,19 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import os -import shutil -import subprocess -import sys -from datetime import date -from platformio import __core_packages__, exception, fs, util -from platformio.exception import UserSideException +from platformio import __core_packages__, exception from platformio.package.exception import UnknownPackageError from platformio.package.manager.tool import ToolPackageManager -from platformio.package.meta import PackageItem, PackageSpec -from platformio.proc import get_pythonexe_path +from platformio.package.meta import PackageSpec def get_installed_core_packages(): @@ -98,131 +91,3 @@ def remove_unnecessary_core_packages(dry_run=False): pm.uninstall(pkg) return candidates - - -def inject_contrib_pysite(): - # pylint: disable=import-outside-toplevel - from site import addsitedir - - try: - contrib_pysite_dir = get_core_package_dir("contrib-pysite") - except UnknownPackageError: - pm = ToolPackageManager() - contrib_pysite_dir = build_contrib_pysite_package( - os.path.join(pm.package_dir, "contrib-pysite") - ) - - if contrib_pysite_dir in sys.path: - return True - - addsitedir(contrib_pysite_dir) - sys.path.insert(0, contrib_pysite_dir) - - try: - # pylint: disable=import-error,unused-import,unused-variable - from OpenSSL import SSL - - except: # pylint: disable=bare-except - build_contrib_pysite_package(contrib_pysite_dir) - - return True - - -def build_contrib_pysite_package(target_dir, with_metadata=True): - systype = util.get_systype() - if os.path.isdir(target_dir): - fs.rmtree(target_dir) - os.makedirs(target_dir) - - # issue 3865: There is no "rustup" in "Raspbian GNU/Linux 10 (buster)" - os.environ["CRYPTOGRAPHY_DONT_BUILD_RUST"] = "1" - - # build dependencies - args = [ - get_pythonexe_path(), - "-m", - "pip", - "install", - "--no-compile", - "-t", - target_dir, - ] - if "linux" in systype: - args.extend(["--no-binary", ":all:"]) - try: - subprocess.run(args + get_contrib_pysite_deps(), check=True, env=os.environ) - except subprocess.CalledProcessError as exc: - if "linux" in systype: - raise UserSideException( - "\n\nPlease ensure that the next packages are installed:\n\n" - "sudo apt install python3-dev libffi-dev libssl-dev\n" - ) from exc - raise exc - - # build manifests - with open( - os.path.join(target_dir, "package.json"), mode="w", encoding="utf8" - ) as fp: - json.dump( - dict( - name="contrib-pysite", - version="2.%d%d.%s" - % ( - sys.version_info.major, - sys.version_info.minor, - date.today().strftime("%y%m%d"), - ), - system=list( - set([systype, "linux_armv6l", "linux_armv7l", "linux_armv8l"]) - ) - if systype.startswith("linux_arm") - else systype, - description="Extra Python package for PlatformIO Core", - keywords=["platformio", "platformio-core"], - homepage="https://docs.platformio.org/page/core/index.html", - repository={ - "type": "git", - "url": "https://github.com/platformio/platformio-core", - }, - ), - fp, - ) - - # generate package metadata - if with_metadata: - pm = ToolPackageManager() - pkg = PackageItem(target_dir) - pkg.metadata = pm.build_metadata( - target_dir, PackageSpec(owner="platformio", name="contrib-pysite") - ) - pkg.dump_meta() - - # remove unused files - for root, dirs, files in os.walk(target_dir): - for t in ("_test", "test", "tests"): - if t in dirs: - shutil.rmtree(os.path.join(root, t)) - for name in files: - if name.endswith((".chm", ".pyc")): - os.remove(os.path.join(root, name)) - - return target_dir - - -def get_contrib_pysite_deps(): - systype = util.get_systype() - twisted_version = "22.1.0" - if "linux_arm" in systype: - result = [ - # twisted[tls], see setup.py for %twisted_version% - "twisted == %s" % twisted_version, - # pyopenssl depends on it, use RUST-less version - "cryptography >= 3.3, < 35.0.0", - "pyopenssl >= 16.0.0, <= 21.0.0", - "service_identity >= 18.1.0, <= 21.1.0", - ] - else: - result = ["twisted[tls] == %s" % twisted_version] - if "windows" in systype: - result.append("pywin32 != 226") - return result diff --git a/platformio/remote/cli.py b/platformio/remote/cli.py index f9462e0f..f1775d49 100644 --- a/platformio/remote/cli.py +++ b/platformio/remote/cli.py @@ -17,7 +17,9 @@ import os import subprocess +import sys import threading +from site import addsitedir from tempfile import mkdtemp from time import sleep @@ -29,7 +31,7 @@ from platformio.device.monitor.command import ( device_monitor_cmd, get_project_options, ) -from platformio.package.manager.core import inject_contrib_pysite +from platformio.package.manager.core import get_core_package_dir from platformio.project.exception import NotPlatformIOProjectError from platformio.project.options import ProjectOptions from platformio.run.cli import cli as cmd_run @@ -41,7 +43,11 @@ from platformio.test.cli import cli as test_cmd @click.pass_context def cli(ctx, agent): ctx.obj = agent - inject_contrib_pysite() + # inject twisted dependencies + contrib_dir = get_core_package_dir("contrib-pioremote") + if contrib_dir not in sys.path: + addsitedir(contrib_dir) + sys.path.insert(0, contrib_dir) @cli.group("agent", short_help="Start a new agent or list active")