diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-07-09 14:28:47 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-15 14:14:03 +0000 |
commit | 0e27a4b08ef0d7e23fc4d6b63f73f6ad7cee24cb (patch) | |
tree | 1ed44d99bf0aacaa27a218d070cfc06567c5b62c /src | |
parent | c056a77b6bacad6f2edfbc5b6f0b65412a77f4ff (diff) | |
download | buildstream-0e27a4b08ef0d7e23fc4d6b63f73f6ad7cee24cb.tar.gz |
_yaml: Mark attributes in ProvenanceInformation as Buildstream-private
Users should not need to get access to any of those, and should only
need access to the ProvenanceInformation to print it.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildstream/_projectrefs.py | 2 | ||||
-rw-r--r-- | src/buildstream/_yaml.pxd | 15 | ||||
-rw-r--r-- | src/buildstream/_yaml.pyx | 42 | ||||
-rw-r--r-- | src/buildstream/element.py | 2 | ||||
-rw-r--r-- | src/buildstream/source.py | 22 |
5 files changed, 43 insertions, 40 deletions
diff --git a/src/buildstream/_projectrefs.py b/src/buildstream/_projectrefs.py index 10dd000b2..152c9fc13 100644 --- a/src/buildstream/_projectrefs.py +++ b/src/buildstream/_projectrefs.py @@ -64,7 +64,7 @@ class ProjectRefs(): try: self._toplevel_node = _yaml.load(self._fullpath, shortname=self._base_name, copy_tree=True) provenance = self._toplevel_node.get_provenance() - self._toplevel_save = provenance.toplevel + self._toplevel_save = provenance._toplevel # Process any project options immediately options.process_node(self._toplevel_node) diff --git a/src/buildstream/_yaml.pxd b/src/buildstream/_yaml.pxd index 9c67f1ad2..47bd38946 100644 --- a/src/buildstream/_yaml.pxd +++ b/src/buildstream/_yaml.pxd @@ -84,9 +84,12 @@ cdef class SequenceNode(Node): cdef class ProvenanceInformation: - cdef public Node node - cdef str displayname - cdef public str filename, shortname - cdef public int col, line - cdef public object project, toplevel - cdef public bint is_synthetic + cdef readonly Node _node + cdef readonly Node _toplevel + cdef readonly _project + cdef readonly bint _is_synthetic + cdef readonly str _filename + cdef readonly str _displayname + cdef readonly str _shortname + cdef readonly int _col + cdef readonly int _line diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx index 13b9d8459..db080289b 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -175,7 +175,7 @@ cdef class ScalarNode(Node): return False else: provenance = self.get_provenance() - path = provenance.toplevel._find(self)[-1] + path = provenance._toplevel._find(self)[-1] raise LoadError(LoadErrorReason.INVALID_DATA, "{}: Value of '{}' is not of the expected type '{}'" .format(provenance, path, bool.__name__, self.value)) @@ -185,7 +185,7 @@ cdef class ScalarNode(Node): return int(self.value) except ValueError: provenance = self.get_provenance() - path = provenance.toplevel._find(self)[-1] + path = provenance._toplevel._find(self)[-1] raise LoadError(LoadErrorReason.INVALID_DATA, "{}: Value of '{}' is not of the expected type '{}'" .format(provenance, path, int.__name__)) @@ -772,33 +772,33 @@ cdef class ProvenanceInformation: def __init__(self, Node nodeish): cdef FileInfo fileinfo - self.node = nodeish + self._node = nodeish if (nodeish is None) or (nodeish.file_index == _SYNTHETIC_FILE_INDEX): - self.filename = "" - self.shortname = "" - self.displayname = "" - self.line = 1 - self.col = 0 - self.toplevel = None - self.project = None + self._filename = "" + self._shortname = "" + self._displayname = "" + self._line = 1 + self._col = 0 + self._toplevel = None + self._project = None else: fileinfo = <FileInfo> _FILE_LIST[nodeish.file_index] - self.filename = fileinfo.filename - self.shortname = fileinfo.shortname - self.displayname = fileinfo.displayname + self._filename = fileinfo.filename + self._shortname = fileinfo.shortname + self._displayname = fileinfo.displayname # We add 1 here to convert from computerish to humanish - self.line = nodeish.line + 1 - self.col = nodeish.column - self.toplevel = fileinfo.toplevel - self.project = fileinfo.project - self.is_synthetic = (self.filename == '') or (self.col < 0) + self._line = nodeish.line + 1 + self._col = nodeish.column + self._toplevel = fileinfo.toplevel + self._project = fileinfo.project + self._is_synthetic = (self._filename == '') or (self._col < 0) # Convert a Provenance to a string for error reporting def __str__(self): - if self.is_synthetic: - return "{} [synthetic node]".format(self.displayname) + if self._is_synthetic: + return "{} [synthetic node]".format(self._displayname) else: - return "{} [line {:d} column {:d}]".format(self.displayname, self.line, self.col) + return "{} [line {:d} column {:d}]".format(self._displayname, self._line, self._col) # These exceptions are intended to be caught entirely within diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 446b20352..0cd3fcbe1 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -2606,7 +2606,7 @@ class Element(Plugin): continue provenance = node.get_provenance() - if not provenance.is_synthetic: + if not provenance._is_synthetic: raise LoadError(LoadErrorReason.PROTECTED_VARIABLE_REDEFINED, "{}: invalid redefinition of protected variable '{}'" .format(provenance, var)) diff --git a/src/buildstream/source.py b/src/buildstream/source.py index 5125169e8..f63142b3c 100644 --- a/src/buildstream/source.py +++ b/src/buildstream/source.py @@ -868,20 +868,20 @@ class Source(Plugin): node = toplevel_refs.lookup_ref(project.name, element_name, element_idx, write=True) if project is toplevel and not node: - node = provenance.node + node = provenance._node # Ensure the node is not from a junction - if not toplevel.ref_storage == ProjectRefStorage.PROJECT_REFS and provenance.project is not toplevel: - if provenance.project is project: + if not toplevel.ref_storage == ProjectRefStorage.PROJECT_REFS and provenance._project is not toplevel: + if provenance._project is project: self.warn("{}: Not persisting new reference in junctioned project".format(self)) - elif provenance.project is None: - assert provenance.filename == "" - assert provenance.shortname == "" + elif provenance._project is None: + assert provenance._filename == "" + assert provenance._shortname == "" raise SourceError("{}: Error saving source reference to synthetic node." .format(self)) else: raise SourceError("{}: Cannot track source in a fragment from a junction" - .format(provenance.shortname), + .format(provenance._shortname), reason="tracking-junction-fragment") # @@ -959,7 +959,7 @@ class Source(Plugin): else: provenance = node.get_node(key).get_provenance() - toplevel_node = provenance.toplevel + toplevel_node = provenance._toplevel # Get the path to whatever changed if action == 'add': @@ -969,10 +969,10 @@ class Source(Plugin): # We want the path to the node containing the key, not to the key path = full_path[:-1] - roundtrip_file = roundtrip_cache.get(provenance.filename) + roundtrip_file = roundtrip_cache.get(provenance._filename) if not roundtrip_file: - roundtrip_file = roundtrip_cache[provenance.filename] = _yaml.roundtrip_load( - provenance.filename, + roundtrip_file = roundtrip_cache[provenance._filename] = _yaml.roundtrip_load( + provenance._filename, allow_missing=True ) |