Skip to content

Commit e0f2bcd

Browse files
committed
Resolve #133: Disabled "prompts" automatically for *Continuous Integration* systems
1 parent ae92cde commit e0f2bcd

File tree

7 files changed

+38
-18
lines changed

7 files changed

+38
-18
lines changed

HISTORY.rst

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Release History
1212
* Added
1313
`Project Configuration <http://docs.platformio.org/en/latest/projectconf.html>`__
1414
option named `envs_dir <http://docs.platformio.org/en/latest/projectconf.html#envs-dir>`__
15+
* Disabled "prompts" automatically for *Continuous Integration* systems
16+
(`issue #103 <https://github.com/ivankravets/platformio/issues/103>`_)
1517
* Fixed firmware uploading for
1618
`atmelavr <http://docs.platformio.org/en/latest/platforms/atmelavr.html#boards>`__
1719
boards which work within ``usbtiny`` protocol

docs/envvars.rst

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ General
1818
PlatformIO uses *General* environment variables for the common
1919
operations/commands.
2020

21+
.. _envvar_CI:
22+
23+
CI
24+
~~
25+
26+
PlatformIO handles ``CI`` variable which is setup by
27+
`Continuous Integration <http://en.wikipedia.org/wiki/Continuous_integration>`_
28+
(Travis, Circle and etc.) systems.
29+
Currently, PlatformIO uses it to disable prompts.
30+
31+
In other words, ``CI=true`` automatically setup
32+
:ref:`PLATFORMIO_SETTING_ENABLE_PROMPTS=false <envvar_PLATFORMIO_SETTING_ENABLE_PROMPTS>`.
33+
2134
.. _envvar_PLATFORMIO_HOME_DIR:
2235

2336
PLATFORMIO_HOME_DIR

docs/installation.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ application:
3232
.. warning::
3333
If you are going to run *PlatformIO* from **subprocess**, you **MUST
3434
DISABLE** all prompts. It will allow you to avoid blocking.
35-
There are 2 options:
35+
There are a few options:
3636

37-
- using environment variable :ref:`PLATFORMIO_SETTING_ENABLE_PROMPTS=false <envvar_PLATFORMIO_SETTING_ENABLE_PROMPTS>`
38-
- disable global setting via :ref:`platformio setting enable_prompts false <cmd_settings>`
39-
command.
37+
- using environment variable :ref:`PLATFORMIO_SETTING_ENABLE_PROMPTS=No <envvar_PLATFORMIO_SETTING_ENABLE_PROMPTS>`
38+
- disable global setting ``enable_prompts`` via :ref:`cmd_settings` command
39+
- masking under Continuous Integration system via environment variable
40+
:ref:`CI=true <envvar_CI>`.
4041

4142
Please *choose one of* the following:
4243

docs/userguide/cmd_settings.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ better.
8686

8787

8888
.. note::
89-
You can override these settings using :ref:`envvars`.
89+
* The ``Yes`` value is equl to: ``True``, ``Y``, ``1``.
90+
The value is not case sensetive.
91+
* You can override these settings using :ref:`envvars`.
9092

9193
Examples
9294
~~~~~~~~

platformio/app.py

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ def set_state_item(name, value):
101101

102102

103103
def get_setting(name):
104+
# disable prompts for Continuous Integration systems
105+
if name == "enable_prompts" and getenv("CI", "").lower() == "true":
106+
return False
107+
104108
_env_name = "PLATFORMIO_SETTING_%s" % name.upper()
105109
if _env_name in environ:
106110
return sanitize_setting(name, getenv(_env_name))

tests/conftest.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
# Copyright (C) Ivan Kravets <[email protected]>
22
# See LICENSE for details.
33

4+
from os import environ
5+
46
from click.testing import CliRunner
57

68
import pytest
7-
from platformio import app
89

910

1011
@pytest.fixture(scope="session")
1112
def platformio_setup(request):
12-
prev_settings = dict(
13-
enable_telemetry=None,
14-
enable_prompts=None
15-
)
16-
for key, value in prev_settings.iteritems():
17-
prev_settings[key] = app.get_setting(key)
18-
# disable temporary
19-
if prev_settings[key]:
20-
app.set_setting(key, False)
13+
pioenvvars = ("ENABLE_PROMPTS", "ENABLE_TELEMETRY")
14+
for v in pioenvvars:
15+
environ["PLATFORMIO_SETTING_%s" % v] = "No"
2116

2217
def platformio_teardown():
23-
# restore settings
24-
for key, value in prev_settings.iteritems():
25-
app.set_setting(key, value)
18+
for v in pioenvvars:
19+
_name = "PLATFORMIO_SETTING_%s" % v
20+
if _name in environ:
21+
del environ[_name]
2622

2723
request.addfinalizer(platformio_teardown)
2824

tox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ basepython =
3838
py27: python2.7
3939
usedevelop = True
4040
deps = pytest
41+
setenv =
42+
PLATFORMIO_SETTING_ENABLE_PROMPTS = False
4143
commands =
4244
{envpython} --version
4345
pip install --egg http://sourceforge.net/projects/scons/files/latest/download

0 commit comments

Comments
 (0)