Remove `enable_prompts` setting. Now, all PlatformIO CLI is non-blocking!

This commit is contained in:
Ivan Kravets
2016-08-26 11:46:59 +03:00
parent de62e5082e
commit f9e8ea66ea
18 changed files with 91 additions and 130 deletions

View File

@ -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

View File

@ -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 <https://github.com/platformio/platformio/issues/542>`_)
@ -1126,8 +1127,7 @@ PlatformIO 0.0
~~~~~~~~~~~~~~~~~~
* Replaced "dark blue" by "cyan" colour for the texts (`issue #33 <https://github.com/platformio/platformio/issues/33>`_)
* Added new setting `enable_prompts <http://docs.platformio.org/en/latest/userguide/cmd_settings.html>`_
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 <https://github.com/platformio/platformio/issues/34>`_)
* Fixed compilation bug on *Windows* with installed *MSVC* (`issue #18 <https://github.com/platformio/platformio/issues/18>`_)

View File

@ -35,8 +35,8 @@ PlatformIO handles ``CI`` variable which is setup by
`Continuous Integration <http://en.wikipedia.org/wiki/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`.

View File

@ -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 <PLATFORMIO_SETTING_ENABLE_PROMPTS>`
- disable global setting ``enable_prompts`` via :ref:`cmd_settings` command
- masking under Continuous Integration system via environment variable
:envvar:`CI=true <CI>`.
Serial does not work with panStampAVR board
'''''''''''''''''''''''''''''''''''''''''''

View File

@ -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 <faq_troubleshooting_pioblocksprompt>` all prompts.
It will allow you to avoid blocking.
.. note::
**Linux OS**: Don't forget to install "udev" rules file
`99-platformio-udev.rules <https://github.com/platformio/platformio/blob/develop/scripts/99-platformio-udev.rules>`_ (an instruction is located in the file).

View File

@ -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)

View File

@ -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

View File

@ -14,7 +14,7 @@
import sys
VERSION = (3, 0, "0a10")
VERSION = (3, 0, "0a11")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@ -58,15 +58,6 @@ DEFAULT_SETTINGS = {
("Telemetry service <http://docs.platformio.org/en/stable/"
"userguide/cmd_settings.html?#enable-telemetry> (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"])

View File

@ -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")

View File

@ -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(

View File

@ -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))

View File

@ -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(

View File

@ -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)

View File

@ -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,

View File

@ -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"]]

View File

@ -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:

View File

@ -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"