diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-10-01 20:26:50 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-10-01 20:26:50 +0900 |
commit | cced3006a39fd8be6e4fa926e68666c672db3d6d (patch) | |
tree | 921dfa1ee686d25de288054bdcfa44c70ec0bcff | |
parent | 2d664a9a47c55f5adb8f7d9694fc4198067411ea (diff) | |
download | buildstream-cced3006a39fd8be6e4fa926e68666c672db3d6d.tar.gz |
Use _yaml.node_items() across the board, instead of casing _yaml.PROVENANCE_KEY
Consequently improved _yaml.node_sanitize() to omit a crazy lambda
which had no effect at all on the outcome of the function.
-rw-r--r-- | buildstream/_variables.py | 10 | ||||
-rw-r--r-- | buildstream/_yaml.py | 16 | ||||
-rw-r--r-- | buildstream/element.py | 7 | ||||
-rw-r--r-- | buildstream/project.py | 16 |
4 files changed, 15 insertions, 34 deletions
diff --git a/buildstream/_variables.py b/buildstream/_variables.py index 6d417f6f0..dfbd8ff04 100644 --- a/buildstream/_variables.py +++ b/buildstream/_variables.py @@ -125,9 +125,8 @@ class Variables(): def resolve_one(variables): unmatched = [] resolved = {} - for key, value in variables.items(): - if key == _yaml.PROVENANCE_KEY: - continue + + for key, value in _yaml.node_items(variables): # Ensure stringness of the value before substitution value = _yaml.node_get(variables, str, key) @@ -170,10 +169,7 @@ class Variables(): # def find_references(self, varname): fullname = '%{' + varname + '}' - for key, value in self.original.items(): - if key == _yaml.PROVENANCE_KEY: - continue - + for key, value in _yaml.node_items(self.original): if fullname in value: provenance = _yaml.node_get_provenance(self.original, key) yield (key, provenance) diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py index 0922bdbda..c408117b4 100644 --- a/buildstream/_yaml.py +++ b/buildstream/_yaml.py @@ -269,10 +269,7 @@ def node_decorate_dict(filename, target, source, toplevel): provenance = DictProvenance(filename, source, toplevel) target[PROVENANCE_KEY] = provenance - for key, value in source.items(): - if key == PROVENANCE_KEY: - continue - + for key, value in node_items(source): member = MemberProvenance(filename, source, key, toplevel) provenance.members[key] = member @@ -459,11 +456,7 @@ def composite_dict(target, source, policy=CompositePolicy.OVERWRITE, typesafe=Fa target_provenance = ensure_provenance(target) source_provenance = ensure_provenance(source) - for key, source_value in source.items(): - - # Handle the provenance keys specially - if key == PROVENANCE_KEY: - continue + for key, source_value in node_items(source): # Track the full path of keys, only for raising CompositeError if path: @@ -581,9 +574,8 @@ def node_sanitize(node): result = SanitizedDict() - for key in sorted(node, key=lambda s: (s == PROVENANCE_KEY, s)): - if key == PROVENANCE_KEY: - continue + key_list = [key for key, _ in node_items(node)] + for key in sorted(key_list): result[key] = node_sanitize(node[key]) return result diff --git a/buildstream/element.py b/buildstream/element.py index efb499be0..25b74d171 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -810,9 +810,10 @@ class Element(Plugin): workspaced = self._workspaced_artifact() # Whether this artifact's dependencies are tainted - workspaced_dependencies = any(val for key, val in - self._workspaced_dependencies_artifact().items() - if key != _yaml.PROVENANCE_KEY) + workspaced_dependencies = any( + val for key, val in + _yaml.node_items(self._workspaced_dependencies_artifact()) + ) # Other conditions should be or-ed self.__tainted = workspaced or workspaced_dependencies diff --git a/buildstream/project.py b/buildstream/project.py index dbb63cec6..1c81f442f 100644 --- a/buildstream/project.py +++ b/buildstream/project.py @@ -262,16 +262,12 @@ class Project(): # The source versions source_versions = _yaml.node_get(versions, Mapping, 'sources', default_value={}) - for key, _ in source_versions.items(): - if key == _yaml.PROVENANCE_KEY: - continue + for key, _ in _yaml.node_items(source_versions): self._source_format_versions[key] = _yaml.node_get(source_versions, int, key) # The element versions element_versions = _yaml.node_get(versions, Mapping, 'elements', default_value={}) - for key, _ in element_versions.items(): - if key == _yaml.PROVENANCE_KEY: - continue + for key, _ in _yaml.node_items(element_versions): self._element_format_versions[key] = _yaml.node_get(element_versions, int, key) # Load the plugin paths @@ -314,12 +310,8 @@ class Project(): # Yields: # A tuple in the following format: (element, source, path). def _workspaces(self): - for element in self.__workspaces: - if element == _yaml.PROVENANCE_KEY: - continue - for source in self.__workspaces[element]: - if source == _yaml.PROVENANCE_KEY: - continue + for element, _ in _yaml.node_items(self.__workspaces): + for source, _ in _yaml.node_items(self.__workspaces[element]): yield (element, int(source), self.__workspaces[element][source]) # _get_workspace() |