From e0f2bcdeaffc2cd13028c181e251be145d7d90ce Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 5 Mar 2015 14:48:56 +0200 Subject: [PATCH] Resolve #133: Disabled "prompts" automatically for *Continuous Integration* systems --- HISTORY.rst | 2 ++ docs/envvars.rst | 13 +++++++++++++ docs/installation.rst | 9 +++++---- docs/userguide/cmd_settings.rst | 4 +++- platformio/app.py | 4 ++++ tests/conftest.py | 22 +++++++++------------- tox.ini | 2 ++ 7 files changed, 38 insertions(+), 18 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index c092cfcf..39ae06f1 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -12,6 +12,8 @@ Release History * Added `Project Configuration `__ option named `envs_dir `__ +* Disabled "prompts" automatically for *Continuous Integration* systems + (`issue #103 `_) * Fixed firmware uploading for `atmelavr `__ boards which work within ``usbtiny`` protocol diff --git a/docs/envvars.rst b/docs/envvars.rst index 6caead8e..ec8fd586 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -18,6 +18,19 @@ General PlatformIO uses *General* environment variables for the common operations/commands. +.. _envvar_CI: + +CI +~~ + +PlatformIO handles ``CI`` variable which is setup by +`Continuous Integration `_ +(Travis, Circle and etc.) systems. +Currently, PlatformIO uses it to disable prompts. + +In other words, ``CI=true`` automatically setup +:ref:`PLATFORMIO_SETTING_ENABLE_PROMPTS=false `. + .. _envvar_PLATFORMIO_HOME_DIR: PLATFORMIO_HOME_DIR diff --git a/docs/installation.rst b/docs/installation.rst index 7f403690..d4a4b61a 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -32,11 +32,12 @@ application: .. warning:: If you are going to run *PlatformIO* from **subprocess**, you **MUST DISABLE** all prompts. It will allow you to avoid blocking. - There are 2 options: + There are a few options: - - using environment variable :ref:`PLATFORMIO_SETTING_ENABLE_PROMPTS=false ` - - disable global setting via :ref:`platformio setting enable_prompts false ` - command. + - using environment variable :ref:`PLATFORMIO_SETTING_ENABLE_PROMPTS=No ` + - disable global setting ``enable_prompts`` via :ref:`cmd_settings` command + - masking under Continuous Integration system via environment variable + :ref:`CI=true `. Please *choose one of* the following: diff --git a/docs/userguide/cmd_settings.rst b/docs/userguide/cmd_settings.rst index 4fabe52e..4fe14304 100644 --- a/docs/userguide/cmd_settings.rst +++ b/docs/userguide/cmd_settings.rst @@ -86,7 +86,9 @@ better. .. note:: - You can override these settings using :ref:`envvars`. + * The ``Yes`` value is equl to: ``True``, ``Y``, ``1``. + The value is not case sensetive. + * You can override these settings using :ref:`envvars`. Examples ~~~~~~~~ diff --git a/platformio/app.py b/platformio/app.py index 6be9665d..fe299d6a 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -101,6 +101,10 @@ def set_state_item(name, value): def get_setting(name): + # disable prompts for Continuous Integration systems + if name == "enable_prompts" and getenv("CI", "").lower() == "true": + return False + _env_name = "PLATFORMIO_SETTING_%s" % name.upper() if _env_name in environ: return sanitize_setting(name, getenv(_env_name)) diff --git a/tests/conftest.py b/tests/conftest.py index 5721f7c3..50170650 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,28 +1,24 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. +from os import environ + from click.testing import CliRunner import pytest -from platformio import app @pytest.fixture(scope="session") def platformio_setup(request): - prev_settings = dict( - enable_telemetry=None, - enable_prompts=None - ) - for key, value in prev_settings.iteritems(): - prev_settings[key] = app.get_setting(key) - # disable temporary - if prev_settings[key]: - app.set_setting(key, False) + pioenvvars = ("ENABLE_PROMPTS", "ENABLE_TELEMETRY") + for v in pioenvvars: + environ["PLATFORMIO_SETTING_%s" % v] = "No" def platformio_teardown(): - # restore settings - for key, value in prev_settings.iteritems(): - app.set_setting(key, value) + for v in pioenvvars: + _name = "PLATFORMIO_SETTING_%s" % v + if _name in environ: + del environ[_name] request.addfinalizer(platformio_teardown) diff --git a/tox.ini b/tox.ini index 8099fce0..3bc8d18e 100644 --- a/tox.ini +++ b/tox.ini @@ -38,6 +38,8 @@ basepython = py27: python2.7 usedevelop = True deps = pytest +setenv = + PLATFORMIO_SETTING_ENABLE_PROMPTS = False commands = {envpython} --version pip install --egg http://sourceforge.net/projects/scons/files/latest/download