From f9e8ea66eaa88540f3a62276376577df40745d86 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 26 Aug 2016 11:46:59 +0300 Subject: [PATCH] Remove ``enable_prompts`` setting. Now, all PlatformIO CLI is non-blocking! --- .pylintrc | 2 +- HISTORY.rst | 4 ++-- docs/envvars.rst | 8 ++----- docs/faq.rst | 15 ------------- docs/installation.rst | 5 ----- docs/userguide/cmd_settings.rst | 19 ---------------- docs/userguide/index.rst | 3 +-- platformio/__init__.py | 2 +- platformio/app.py | 19 ++-------------- platformio/commands/lib.py | 39 +++++++++++++++++++++++---------- platformio/commands/platform.py | 12 +++------- platformio/commands/test.py | 9 ++++---- platformio/managers/lib.py | 36 ++++++++++++++++++++---------- platformio/managers/package.py | 5 ++++- platformio/managers/platform.py | 11 ++++++---- platformio/telemetry.py | 21 +++++------------- platformio/util.py | 9 ++++---- tests/conftest.py | 2 +- 18 files changed, 91 insertions(+), 130 deletions(-) diff --git a/.pylintrc b/.pylintrc index bdf25c27..66581ace 100644 --- a/.pylintrc +++ b/.pylintrc @@ -20,4 +20,4 @@ confidence= # --disable=W" # disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating -disable=locally-disabled,missing-docstring,invalid-name,too-few-public-methods,redefined-variable-type,import-error,similarities,unsupported-membership-test,unsubscriptable-object,ungrouped-imports +disable=locally-disabled,missing-docstring,invalid-name,too-few-public-methods,redefined-variable-type,import-error,similarities,unsupported-membership-test,unsubscriptable-object,ungrouped-imports,cyclic-import diff --git a/HISTORY.rst b/HISTORY.rst index 60e9fbf4..6f289027 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -65,6 +65,7 @@ PlatformIO 3.0 + Support for the 3rd party manifests (Arduino IDE "library.properties" and ARM mbed "module.json") +* Removed ``enable_prompts`` setting. Now, all PlatformIO CLI is non-blocking! * Switched to SSL PlatformIO API * Build System: Attach custom Before/Pre and After/Post actions for targets (`issue #542 `_) @@ -1126,8 +1127,7 @@ PlatformIO 0.0 ~~~~~~~~~~~~~~~~~~ * Replaced "dark blue" by "cyan" colour for the texts (`issue #33 `_) -* Added new setting `enable_prompts `_ - and allowed to disable all *PlatformIO* prompts (useful for cloud compilers) +* Added new setting ``enable_prompts`` and allowed to disable all *PlatformIO* prompts (useful for cloud compilers) (`issue #34 `_) * Fixed compilation bug on *Windows* with installed *MSVC* (`issue #18 `_) diff --git a/docs/envvars.rst b/docs/envvars.rst index 4aea55c0..7749e9ce 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -35,8 +35,8 @@ PlatformIO handles ``CI`` variable which is setup by `Continuous Integration `_ (Travis, Circle and etc.) systems. PlatformIO uses it to disable prompts and progress bars. In other words, -``CI=true`` automatically setup :envvar:`PLATFORMIO_SETTING_ENABLE_PROMPTS` to -``false`` and :envvar:`PLATFORMIO_DISABLE_PROGRESSBAR` to ``true``. +``CI=true`` automatically setup :envvar:`PLATFORMIO_DISABLE_PROGRESSBAR` to +``true``. .. envvar:: PLATFORMIO_FORCE_COLOR @@ -154,10 +154,6 @@ Allows to override setting :ref:`setting_check_platformio_interval`. Allows to override setting :ref:`setting_check_platforms_interval`. -.. envvar:: PLATFORMIO_SETTING_ENABLE_PROMPTS - -Allows to override setting :ref:`setting_enable_prompts`. - .. envvar:: PLATFORMIO_SETTING_ENABLE_TELEMETRY Allows to override setting :ref:`setting_enable_telemetry`. diff --git a/docs/faq.rst b/docs/faq.rst index 47a55571..8e054883 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -139,21 +139,6 @@ Please upgrade *SetupTools* package: Miscellaneous ~~~~~~~~~~~~~ -.. _faq_troubleshooting_pioblocksprompt: - -PlatformIO blocks command execution using user prompt -''''''''''''''''''''''''''''''''''''''''''''''''''''' - -If you are going to run *PlatformIO* from **subprocess**, you **MUST -DISABLE** all prompts. It will allow you to avoid blocking. -There are a few options: - -- using :option:`platformio --force` option before each command -- using environment variable :envvar:`PLATFORMIO_SETTING_ENABLE_PROMPTS=No ` -- disable global setting ``enable_prompts`` via :ref:`cmd_settings` command -- masking under Continuous Integration system via environment variable - :envvar:`CI=true `. - Serial does not work with panStampAVR board ''''''''''''''''''''''''''''''''''''''''''' diff --git a/docs/installation.rst b/docs/installation.rst index 53dd81ca..81af129a 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -200,11 +200,6 @@ To revert to the latest stable version Troubleshooting --------------- -.. warning:: - If you are going to run *PlatformIO* from **subprocess**, you - :ref:`MUST DISABLE ` all prompts. - It will allow you to avoid blocking. - .. note:: **Linux OS**: Don't forget to install "udev" rules file `99-platformio-udev.rules `_ (an instruction is located in the file). diff --git a/docs/userguide/cmd_settings.rst b/docs/userguide/cmd_settings.rst index 0219b076..2605ed74 100644 --- a/docs/userguide/cmd_settings.rst +++ b/docs/userguide/cmd_settings.rst @@ -111,24 +111,6 @@ Force verbose output when processing environments. This setting overrides * :option:`platformio ci --verbose` * :option:`platformio test --verbose` -.. _setting_enable_prompts: - -``enable_prompts`` -^^^^^^^^^^^^^^^^^^ - -:Default: Yes -:Values: Yes/No - -Can PlatformIO communicate with you via prompts? - -* propose to install platforms which aren't installed yet -* paginate over library search results -* and etc. - -.. warning:: - If you are going to run *PlatformIO* from **subprocess**, you **MUST - DISABLE** all prompts. It will allow you to avoid blocking. - .. _setting_enable_telemetry: ``enable_telemetry`` @@ -172,7 +154,6 @@ Examples check_libraries_interval 7 Check for the library updates interval (days) check_platformio_interval 3 Check for the new PlatformIO interval (days) check_platforms_interval 7 Check for the platform updates interval (days) - enable_prompts Yes Can PlatformIO communicate with you via prompts ... enable_telemetry Yes Telemetry service (Yes/No) diff --git a/docs/userguide/index.rst b/docs/userguide/index.rst index 05ada62a..d6a49049 100644 --- a/docs/userguide/index.rst +++ b/docs/userguide/index.rst @@ -34,8 +34,7 @@ Options .. option:: --force, -f -Force to accept any confirmation prompts. This option allows to avoid an issue -with :ref:`faq_troubleshooting_pioblocksprompt` +Force to accept any confirmation prompts and disable progress bars. .. option:: --version diff --git a/platformio/__init__.py b/platformio/__init__.py index 28860527..f002cab1 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -14,7 +14,7 @@ import sys -VERSION = (3, 0, "0a10") +VERSION = (3, 0, "0a11") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/app.py b/platformio/app.py index 507bf528..42c8ee8d 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -58,15 +58,6 @@ DEFAULT_SETTINGS = { ("Telemetry service (Yes/No)"), "value": True - }, - "enable_prompts": { - "description": - ("Can PlatformIO communicate with you via prompts: " - "propose to install platforms which aren't installed yet, " - "paginate over library search results and etc.)? ATTENTION!!! " - "If you call PlatformIO like subprocess, " - "please disable prompts to avoid blocking (Yes/No)"), - "value": True } } @@ -148,12 +139,6 @@ def set_state_item(name, value): def get_setting(name): - if name == "enable_prompts": - # disable prompts for Continuous Integration systems - # and when global "--force" option is set - if any([util.is_ci(), get_session_var("force_option")]): - return False - _env_name = "PLATFORMIO_SETTING_%s" % name.upper() if _env_name in environ: return sanitize_setting(name, getenv(_env_name)) @@ -188,5 +173,5 @@ def set_session_var(name, value): def is_disabled_progressbar(): - return (not get_setting("enable_prompts") or - getenv("PLATFORMIO_DISABLE_PROGRESSBAR") == "true") + return any([get_session_var("force_option"), util.is_ci(), + getenv("PLATFORMIO_DISABLE_PROGRESSBAR") == "true"]) diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index 8f39f7fe..348c3e05 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -14,10 +14,11 @@ import json from os.path import join +from time import sleep import click -from platformio import app, exception, util +from platformio import exception, util from platformio.managers.lib import LibraryManager from platformio.util import get_api_result @@ -75,11 +76,15 @@ def cli(ctx, **options): # "library dependencies") @click.option( "-s", "--silent", is_flag=True, help="Suppress progress reporting") +@click.option( + "--interactive", + is_flag=True, + help="Allow to make a choice for all prompts") @click.pass_obj -def lib_install(lm, libraries, silent): +def lib_install(lm, libraries, silent, interactive): # @TODO "save" option for library in libraries: - lm.install(library, silent=silent) + lm.install(library, silent=silent, interactive=interactive) @cli.command("uninstall", short_help="Uninstall libraries") @@ -147,6 +152,7 @@ def echo_liblist_item(item): @cli.command("search", short_help="Search for library") +@click.argument("query", required=False, nargs=-1) @click.option("--json-output", is_flag=True) @click.option("--page", type=click.INT, default=1) @click.option("-n", "--name", multiple=True) @@ -154,8 +160,11 @@ def echo_liblist_item(item): @click.option("-k", "--keyword", multiple=True) @click.option("-f", "--framework", multiple=True) @click.option("-p", "--platform", multiple=True) -@click.argument("query", required=False, nargs=-1) -def lib_search(query, json_output, page, **filters): +@click.option( + "--noninteractive", + is_flag=True, + help="Do not prompt, automatically paginate with delay") +def lib_search(query, json_output, page, noninteractive, **filters): if not query: query = [] if not isinstance(query, list): @@ -205,14 +214,20 @@ def lib_search(query, json_output, page, **filters): int(result['total'])): break - if (app.get_setting("enable_prompts") and - click.confirm("Show next libraries?")): - result = get_api_result( - "/lib/search", - dict( - query=" ".join(query), page=int(result['page']) + 1)) - else: + if noninteractive: + click.echo() + click.secho( + "Loading next %d libraries... Press Ctrl+C to stop!" % + result['perpage'], + fg="yellow") + click.echo() + sleep(5) + elif not click.confirm("Show next libraries?"): break + result = get_api_result( + "/lib/search", + dict( + query=" ".join(query), page=int(result['page']) + 1)) @cli.command("list", short_help="List installed libraries") diff --git a/platformio/commands/platform.py b/platformio/commands/platform.py index a8174436..c69c8ceb 100644 --- a/platformio/commands/platform.py +++ b/platformio/commands/platform.py @@ -16,7 +16,7 @@ import json import click -from platformio import app, exception, util +from platformio import exception, util from platformio.managers.platform import PlatformFactory, PlatformManager @@ -150,17 +150,11 @@ def platform_list(json_output): @cli.command("show", short_help="Show details about installed platform") @click.argument("platform") -@click.pass_context -def platform_show(ctx, platform): +def platform_show(platform): try: p = PlatformFactory.newPlatform(platform) except exception.UnknownPlatform: - if (not app.get_setting("enable_prompts") or - click.confirm("The platform '%s' has not been installed yet. " - "Would you like to install it now?" % platform)): - ctx.invoke(platform_install, platforms=[platform]) - else: - raise exception.PlatformNotInstalledYet(platform) + raise exception.PlatformNotInstalledYet(platform) click.echo("{name} ~ {title}".format( name=click.style( diff --git a/platformio/commands/test.py b/platformio/commands/test.py index 6afe1bcd..6820fa31 100644 --- a/platformio/commands/test.py +++ b/platformio/commands/test.py @@ -70,10 +70,11 @@ def cli(ctx, environment, ignore, upload_port, project_dir, verbose): # check ignore patterns _ignore = list(ignore) if projectconf.has_option(section, "test_ignore"): - _ignore.extend([p.strip() - for p in projectconf.get( - section, "test_ignore").split(",") - if p.strip()]) + _ignore.extend([ + p.strip() + for p in projectconf.get(section, "test_ignore").split(",") + if p.strip() + ]) if testname != "*" and \ any([fnmatch(testname, p) for p in _ignore]): results.append((None, testname, envname)) diff --git a/platformio/managers/lib.py b/platformio/managers/lib.py index 730d6b7e..a8a5af23 100644 --- a/platformio/managers/lib.py +++ b/platformio/managers/lib.py @@ -18,7 +18,7 @@ from os.path import join import click import semantic_version -from platformio import app, commands, exception, util +from platformio import commands, exception, util from platformio.managers.package import BasePkgManager @@ -106,7 +106,11 @@ class LibraryManager(BasePkgManager): name, requirements)), requirements) return item['version'] if item else None - def _get_pkg_id_by_name(self, name, requirements, silent=False): + def _get_pkg_id_by_name(self, + name, + requirements, + silent=False, + interactive=False): if name.startswith("id="): return int(name[3:]) # try to find ID from installed packages @@ -115,7 +119,8 @@ class LibraryManager(BasePkgManager): manifest = self.load_manifest(installed_dir) if "id" in manifest: return int(manifest['id']) - return int(self.search_for_library({"name": name}, silent)['id']) + return int( + self.search_for_library({"name": name}, silent, interactive)['id']) def _install_from_piorepo(self, name, requirements): assert name.startswith("id=") @@ -136,15 +141,16 @@ class LibraryManager(BasePkgManager): requirements) return pkg_dir - def install(self, + def install(self, # pylint: disable=too-many-arguments name, requirements=None, silent=False, - trigger_event=True): + trigger_event=True, + interactive=False): _name, _requirements, _url = self.parse_pkg_name(name, requirements) if not _url: _name = "id=%d" % self._get_pkg_id_by_name( - _name, _requirements, silent=silent) + _name, _requirements, silent=silent, interactive=interactive) already_installed = self.get_installed_dir(_name, _requirements, _url) pkg_dir = BasePkgManager.install(self, _name if not _url else name, _requirements, silent, trigger_event) @@ -164,7 +170,8 @@ class LibraryManager(BasePkgManager): if any([s in filters.get("version", "") for s in ("\\", "/")]): self.install("{name}={version}".format(**filters)) else: - lib_info = self.search_for_library(filters, silent) + lib_info = self.search_for_library(filters, silent, + interactive) if filters.get("version"): self.install( lib_info['id'], @@ -180,7 +187,9 @@ class LibraryManager(BasePkgManager): @staticmethod def search_for_library( # pylint: disable=too-many-branches - filters, silent=False): + filters, + silent=False, + interactive=False): assert isinstance(filters, dict) assert "name" in filters if not silent: @@ -206,13 +215,18 @@ class LibraryManager(BasePkgManager): click.secho( "Conflict: More than one library has been found " "by request %s:" % json.dumps(filters), - fg="red") + fg="red", + err=True) commands.lib.echo_liblist_header() for item in result['items']: commands.lib.echo_liblist_item(item) - if not app.get_setting("enable_prompts"): - click.echo("Automatically chose the first available library") + if not interactive: + click.secho( + "Automatically chose the first available library " + "(use `--interactive` option to make a choice)", + fg="yellow", + err=True) lib_info = result['items'][0] else: deplib_id = click.prompt( diff --git a/platformio/managers/package.py b/platformio/managers/package.py index 424a69a7..23ff4483 100644 --- a/platformio/managers/package.py +++ b/platformio/managers/package.py @@ -27,6 +27,8 @@ from platformio.downloader import FileDownloader from platformio.unpacker import FileUnpacker from platformio.vcsclient import VCSClientFactory +# pylint: disable=too-many-arguments + class PackageRepoIterator(object): @@ -424,7 +426,8 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin): name, requirements=None, silent=False, - trigger_event=True): + trigger_event=True, + interactive=False): # pylint: disable=unused-argument name, requirements, url = self.parse_pkg_name(name, requirements) installed_dir = self.get_installed_dir(name, requirements, url) diff --git a/platformio/managers/platform.py b/platformio/managers/platform.py index fb53d255..fcfe3038 100644 --- a/platformio/managers/platform.py +++ b/platformio/managers/platform.py @@ -43,10 +43,13 @@ class PlatformManager(BasePkgManager): def manifest_name(self): return "platform.json" - def install(self, # pylint: disable=too-many-arguments,arguments-differ - name, requirements=None, silent=False, - trigger_event=True, with_packages=None, - without_packages=None, skip_default_package=False): + def install(self, # pylint: disable=too-many-arguments + name, + requirements=None, + with_packages=None, + without_packages=None, + skip_default_package=False, + **_): platform_dir = BasePkgManager.install(self, name, requirements) p = PlatformFactory.newPlatform(self.get_manifest_path(platform_dir)) p.install_packages(with_packages, without_packages, diff --git a/platformio/telemetry.py b/platformio/telemetry.py index b863f862..47150149 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -27,7 +27,6 @@ import click import requests from platformio import __version__, app, exception, util -from platformio.ide.projectgenerator import ProjectGenerator class TelemetryBase(object): @@ -60,7 +59,7 @@ class TelemetryBase(object): class MeasurementProtocol(TelemetryBase): - TRACKING_ID = "UA-1768265-9" + TID = "UA-1768265-9" PARAMS_MAP = { "screen_name": "cd", "event_category": "ec", @@ -72,7 +71,7 @@ class MeasurementProtocol(TelemetryBase): def __init__(self): TelemetryBase.__init__(self) self['v'] = 1 - self['tid'] = self.TRACKING_ID + self['tid'] = self.TID self['cid'] = self.get_cid() self['sr'] = "%dx%d" % click.get_terminal_size() @@ -106,8 +105,9 @@ class MeasurementProtocol(TelemetryBase): self['cd1'] = util.get_systype() self['cd2'] = "Python/%s %s" % (platform.python_version(), platform.platform()) - self['cd4'] = (1 if app.get_setting("enable_prompts") or - app.get_session_var("caller_id") else 0) + self['cd4'] = 1 if not util.is_ci() else 0 + if app.get_session_var("caller_id"): + self['cd5'] = str(app.get_session_var("caller_id")).lower() def _prefill_screen_name(self): self['cd3'] = " ".join([str(s).lower() for s in sys.argv[1:]]) @@ -227,9 +227,6 @@ def on_command(): if util.is_ci(): measure_ci() - if app.get_session_var("caller_id"): - measure_caller(app.get_session_var("caller_id")) - def measure_ci(): event = {"category": "CI", "action": "NoName", "label": None} @@ -251,14 +248,6 @@ def measure_ci(): on_event(**event) -def measure_caller(calller_id): - calller_id = str(calller_id)[:20].lower() - event = {"category": "Caller", "action": "Misc", "label": calller_id} - if calller_id in (["atom", "vim"] + ProjectGenerator.get_supported_ides()): - event['action'] = "IDE" - on_event(**event) - - def on_run_environment(options, targets): opts = ["%s=%s" % (opt, value) for opt, value in sorted(options.items())] targets = [t.title() for t in targets or ["run"]] diff --git a/platformio/util.py b/platformio/util.py index b08db611..dcbf298a 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -231,7 +231,7 @@ def get_projectpioenvs_dir(force=False): [InternetShortcut] URL=http://docs.platformio.org/en/stable/projectconf.html#envs-dir """) - except Exception as e: + except Exception as e: # pylint: disable=broad-except if not force: raise Exception(e) return path @@ -348,9 +348,10 @@ def _api_request_session(): return requests.Session() -def get_api_result(path, params=None, data=None, skipdns=False): +def get_api_result(path, # pylint: disable=too-many-branches + params=None, data=None, skipdns=False): import requests - import app + from platformio.app import get_setting result = None r = None @@ -361,7 +362,7 @@ def get_api_result(path, params=None, data=None, skipdns=False): url = "https://%s" % __apiip__ headers['host'] = __apiurl__[__apiurl__.index("://") + 3:] - if app.get_setting("disable_ssl"): + if get_setting("disable_ssl"): url = url.replace("https://", "http://") try: diff --git a/tests/conftest.py b/tests/conftest.py index 8483d8b9..a6cf052d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,7 +20,7 @@ from click.testing import CliRunner @pytest.fixture(scope="session") def platformio_setup(request): - pioenvvars = ("ENABLE_PROMPTS", "ENABLE_TELEMETRY") + pioenvvars = ("ENABLE_TELEMETRY", ) for v in pioenvvars: os.environ["PLATFORMIO_SETTING_%s" % v] = "No"