From 891f78be374d7f1ab2aaef9728a6faa1b21e46b5 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 28 Oct 2020 22:32:27 +0200 Subject: [PATCH] Use "ensure_python3" util --- platformio/commands/remote/command.py | 12 +++--------- platformio/compat.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/platformio/commands/remote/command.py b/platformio/commands/remote/command.py index cafbbd1f..1a2c8ee2 100644 --- a/platformio/commands/remote/command.py +++ b/platformio/commands/remote/command.py @@ -23,12 +23,12 @@ from time import sleep import click -from platformio import exception, fs, proc +from platformio import fs, proc from platformio.commands.device import helpers as device_helpers from platformio.commands.device.command import device_monitor as cmd_device_monitor from platformio.commands.run.command import cli as cmd_run from platformio.commands.test.command import cli as cmd_test -from platformio.compat import PY2 +from platformio.compat import ensure_python3 from platformio.package.manager.core import inject_contrib_pysite from platformio.project.exception import NotPlatformIOProjectError @@ -37,13 +37,7 @@ from platformio.project.exception import NotPlatformIOProjectError @click.option("-a", "--agent", multiple=True) @click.pass_context def cli(ctx, agent): - if PY2: - raise exception.UserSideException( - "PlatformIO Remote Development requires Python 3.5 or above. \n" - "Please install the latest Python 3 and reinstall PlatformIO Core using " - "installation script:\n" - "https://docs.platformio.org/page/core/installation.html" - ) + assert ensure_python3() ctx.obj = agent inject_contrib_pysite(verify_openssl=True) diff --git a/platformio/compat.py b/platformio/compat.py index bf88c681..0fde6b46 100644 --- a/platformio/compat.py +++ b/platformio/compat.py @@ -23,6 +23,8 @@ import os import re import sys +from platformio.exception import UserSideException + PY2 = sys.version_info[0] == 2 CYGWIN = sys.platform.startswith("cygwin") WINDOWS = sys.platform.startswith("win") @@ -59,6 +61,17 @@ def ci_strings_are_equal(a, b): return a.strip().lower() == b.strip().lower() +def ensure_python3(raise_exception=True): + if not raise_exception or not PY2: + return not PY2 + raise UserSideException( + "Python 3.5 or later is required for this operation. \n" + "Please install the latest Python 3 and reinstall PlatformIO Core using " + "installation script:\n" + "https://docs.platformio.org/page/core/installation.html" + ) + + if PY2: import imp