Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/buildstream/node.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ cdef class ScalarNode(Node):
cpdef bint as_bool(self) except *:
"""Get the value of the node as a boolean.

.. note:: BuildStream treats the values 'True' and 'true' as True,
and the values 'False' and 'false' as False. Any other
.. note:: BuildStream treats the values 'True', 'true' and '1' as True,
and the values 'False', 'false' and '0' as False. Any other
string values (such as the valid YAML 'TRUE' or 'FALSE'
will be considered as an error)

Expand All @@ -322,15 +322,15 @@ cdef class ScalarNode(Node):
return self.value

# Don't coerce strings to booleans, this makes "False" strings evaluate to True
if self.value in ('True', 'true'):
if self.value in ('True', 'true', '1'):
return True
elif self.value in ('False', 'false'):
elif self.value in ('False', 'false', '0'):
return False
else:
provenance = self.get_provenance()
path = provenance._toplevel._find(self)[-1]
raise LoadError("{}: Value of '{}' is not of the expected type '{}'"
.format(provenance, path, bool.__name__, self.value),
raise LoadError("{}: Value of '{}' is not of the expected type 'boolean'"
.format(provenance, path),
LoadErrorReason.INVALID_DATA)

cpdef object as_enum(self, object constraint):
Expand Down
6 changes: 5 additions & 1 deletion tests/format/option-exports/element.bst
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
kind: manual
kind: config

config:
animal: "%{exported-enum}"
sleepy: "%{exported-bool}"
26 changes: 26 additions & 0 deletions tests/format/option-exports/plugins/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from buildstream import Element, FastEnum


class AnimalEnum(FastEnum):
PONY = "pony"
HORSY = "horsy"
ZEBRY = "zebry"


class Config(Element):
BST_MIN_VERSION = "2.0"

def configure(self, node):
self.animal = node.get_enum("animal", AnimalEnum)
self.sleepy = node.get_bool("sleepy")

def preflight(self):
pass

def get_unique_key(self):
return {}


# Plugin entry point
def setup():
return Config
6 changes: 6 additions & 0 deletions tests/format/option-exports/project.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: test
min-version: 2.0

plugins:
- origin: local
path: plugins
elements:
- config

options:

bool_export:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/pullbuildtrees.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_pullbuildtrees(cli2, tmpdir, datafiles):

# Ensure that only valid pull-buildtrees boolean options make it through the loading
# process.
@pytest.mark.parametrize("value,success", [(True, True), (False, True), ("pony", False), ("1", False)])
@pytest.mark.parametrize("value,success", [(True, True), (False, True), ("pony", False), ("2", False), ("1", True)])
@pytest.mark.datafiles(DATA_DIR)
def test_invalid_cache_pullbuildtrees(cli, datafiles, value, success):
project = str(datafiles)
Expand Down
Loading