Tristan Van Berkom pushed to branch master at BuildStream / buildstream
Commits:
-
e61e6e50
by Tristan Van Berkom at 2018-12-07T07:57:13Z
-
504ecb3e
by Tristan Van Berkom at 2018-12-07T07:57:56Z
-
642ae4e8
by Tristan Van Berkom at 2018-12-07T07:57:56Z
-
2a0676c3
by Tristan Van Berkom at 2018-12-07T08:33:14Z
5 changed files:
- buildstream/_yaml.py
- buildstream/plugin.py
- tests/format/project.py
- + tests/format/project/empty-depends/manual.bst
- + tests/format/project/empty-depends/project.conf
Changes:
| ... | ... | @@ -352,6 +352,7 @@ _sentinel = object() |
| 352 | 352 |
# key (str): The key to get a value for in node
|
| 353 | 353 |
# indices (list of ints): Optionally decend into lists of lists
|
| 354 | 354 |
# default_value: Optionally return this value if the key is not found
|
| 355 |
+# allow_none: (bool): Allow None to be a valid value
|
|
| 355 | 356 |
#
|
| 356 | 357 |
# Returns:
|
| 357 | 358 |
# The value if found in node, otherwise default_value is returned
|
| ... | ... | @@ -362,7 +363,7 @@ _sentinel = object() |
| 362 | 363 |
# Note:
|
| 363 | 364 |
# Returned strings are stripped of leading and trailing whitespace
|
| 364 | 365 |
#
|
| 365 |
-def node_get(node, expected_type, key, indices=None, default_value=_sentinel):
|
|
| 366 |
+def node_get(node, expected_type, key, indices=None, *, default_value=_sentinel, allow_none=False):
|
|
| 366 | 367 |
value = node.get(key, default_value)
|
| 367 | 368 |
provenance = node_get_provenance(node)
|
| 368 | 369 |
if value is _sentinel:
|
| ... | ... | @@ -377,8 +378,8 @@ def node_get(node, expected_type, key, indices=None, default_value=_sentinel): |
| 377 | 378 |
value = value[index]
|
| 378 | 379 |
path += '[{:d}]'.format(index)
|
| 379 | 380 |
|
| 380 |
- # We want to allow None as a valid value for any type
|
|
| 381 |
- if value is None:
|
|
| 381 |
+ # Optionally allow None as a valid value for any type
|
|
| 382 |
+ if value is None and (allow_none or default_value is None):
|
|
| 382 | 383 |
return None
|
| 383 | 384 |
|
| 384 | 385 |
if not isinstance(value, expected_type):
|
| ... | ... | @@ -323,7 +323,7 @@ class Plugin(): |
| 323 | 323 |
provenance = _yaml.node_get_provenance(node, key=member_name)
|
| 324 | 324 |
return str(provenance)
|
| 325 | 325 |
|
| 326 |
- def node_get_member(self, node, expected_type, member_name, default=_yaml._sentinel):
|
|
| 326 |
+ def node_get_member(self, node, expected_type, member_name, default=_yaml._sentinel, *, allow_none=False):
|
|
| 327 | 327 |
"""Fetch the value of a node member, raising an error if the value is
|
| 328 | 328 |
missing or incorrectly typed.
|
| 329 | 329 |
|
| ... | ... | @@ -332,6 +332,7 @@ class Plugin(): |
| 332 | 332 |
expected_type (type): The expected type of the node member
|
| 333 | 333 |
member_name (str): The name of the member to fetch
|
| 334 | 334 |
default (expected_type): A value to return when *member_name* is not specified in *node*
|
| 335 |
+ allow_none (bool): Allow explicitly set None values in the YAML (*Since: 1.4*)
|
|
| 335 | 336 |
|
| 336 | 337 |
Returns:
|
| 337 | 338 |
The value of *member_name* in *node*, otherwise *default*
|
| ... | ... | @@ -352,7 +353,7 @@ class Plugin(): |
| 352 | 353 |
# Fetch an optional integer
|
| 353 | 354 |
level = self.node_get_member(node, int, 'level', -1)
|
| 354 | 355 |
"""
|
| 355 |
- return _yaml.node_get(node, expected_type, member_name, default_value=default)
|
|
| 356 |
+ return _yaml.node_get(node, expected_type, member_name, default_value=default, allow_none=allow_none)
|
|
| 356 | 357 |
|
| 357 | 358 |
def node_get_project_path(self, node, key, *,
|
| 358 | 359 |
check_is_file=False, check_is_dir=False):
|
| ... | ... | @@ -200,3 +200,10 @@ def test_element_path_project_path_contains_symlinks(cli, datafiles, tmpdir): |
| 200 | 200 |
f.write("kind: manual\n")
|
| 201 | 201 |
result = cli.run(project=linked_project, args=['show', 'element.bst'])
|
| 202 | 202 |
result.assert_success()
|
| 203 |
+ |
|
| 204 |
+ |
|
| 205 |
+@pytest.mark.datafiles(os.path.join(DATA_DIR))
|
|
| 206 |
+def test_empty_depends(cli, datafiles):
|
|
| 207 |
+ project = os.path.join(datafiles.dirname, datafiles.basename, "empty-depends")
|
|
| 208 |
+ result = cli.run(project=project, args=['show', 'manual.bst'])
|
|
| 209 |
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
|
| 1 |
+kind: manual
|
|
| 2 |
+ |
|
| 3 |
+depends:
|
| 1 |
+name: test
|
