diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-04-07 00:51:34 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-04-07 00:51:34 +0900 |
commit | b21fc705ec6472187cb2320726a7f3e28019c9f2 (patch) | |
tree | 56fa3e9caeeb51bd1d55e500819add069462cb87 /buildstream/utils.py | |
parent | 1136eac663be9757c097426f96c6fca478a534c9 (diff) | |
download | buildstream-b21fc705ec6472187cb2320726a7f3e28019c9f2.tar.gz |
Untangling _yaml and utils modules.
These had a circular import, which is only supported > python 3.5
but undesirable anyway.
Diffstat (limited to 'buildstream/utils.py')
-rw-r--r-- | buildstream/utils.py | 60 |
1 files changed, 3 insertions, 57 deletions
diff --git a/buildstream/utils.py b/buildstream/utils.py index a4bd90be5..bb9e18444 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -29,9 +29,9 @@ import pickle import calendar import signal from contextlib import contextmanager -from collections import OrderedDict, ChainMap, deque -from . import _yaml +from collections import deque from . import ProgramNotFoundError +from . import _yaml def list_relative_paths(directory): @@ -518,65 +518,11 @@ def _relative_symlink_target(root, symlink, target): # (str): An sha256 hex digest of the given value # def _generate_key(value): - ordered = _node_sanitize(value) + ordered = _yaml.node_sanitize(value) string = pickle.dumps(ordered) return hashlib.sha256(string).hexdigest() -# _node_sanitize() -# -# Returnes an alphabetically ordered recursive copy -# of the source node with internal provenance information stripped. -# -# Only dicts are ordered, list elements are left in order. -# -def _node_sanitize(node): - - if isinstance(node, collections.Mapping): - - result = OrderedDict() - - for key in sorted(node): - if key == _yaml.PROVENANCE_KEY: - continue - result[key] = _node_sanitize(node[key]) - - return result - - elif isinstance(node, list): - return [_node_sanitize(elt) for elt in node] - - return node - - -def _node_chain_copy(source): - copy = collections.ChainMap({}, source) - for key, value in source.items(): - if isinstance(value, collections.Mapping): - copy[key] = _node_chain_copy(value) - elif isinstance(value, list): - copy[key] = _list_chain_copy(value) - elif isinstance(value, _yaml.Provenance): - copy[key] = value.clone() - - return copy - - -def _list_chain_copy(source): - copy = [] - for item in source: - if isinstance(item, collections.Mapping): - copy.append(_node_chain_copy(item)) - elif isinstance(item, list): - copy.append(_list_chain_copy(item)) - elif isinstance(item, _yaml.Provenance): - copy.append(item.clone()) - else: - copy.append(item) - - return copy - - # _set_deterministic_mtime() # # Set the mtime for every file in a directory tree to the same. |