Commit ab484381 authored by Valentin David's avatar Valentin David Committed by Valentin David
Browse files

Fix broken indentation after tracking.

Issue was introduced by 171e803f (include directive) and the fix was
found courtesy of @Qinusty. This fixes also the include
feature. Because elements are to be serialized, the included fragments
need to use copy_tree when loaded.

Related to #470.
parent 01c4ac57
Loading
Loading
Loading
Loading
+21 −10
Original line number Original line Diff line number Diff line
@@ -25,10 +25,14 @@ class Includes:
    #    included (set): Fail for recursion if trying to load any files in this set
    #    included (set): Fail for recursion if trying to load any files in this set
    #    current_loader (Loader): Use alternative loader (for junction files)
    #    current_loader (Loader): Use alternative loader (for junction files)
    #    only_local (bool): Whether to ignore junction files
    #    only_local (bool): Whether to ignore junction files
    #    copy_tree (bool): Whether to make a copy, of tree in provenance. Should be
    #                      true if intended to be serialized.
    #
    def process(self, node, *,
    def process(self, node, *,
                included=set(),
                included=set(),
                current_loader=None,
                current_loader=None,
                only_local=False):
                only_local=False,
                copy_tree=False):
        if current_loader is None:
        if current_loader is None:
            current_loader = self._loader
            current_loader = self._loader


@@ -44,7 +48,8 @@ class Includes:
                if only_local and ':' in include:
                if only_local and ':' in include:
                    continue
                    continue
                include_node, file_path, sub_loader = self._include_file(include,
                include_node, file_path, sub_loader = self._include_file(include,
                                                                         current_loader)
                                                                         current_loader,
                                                                         copy_tree=copy_tree)
                if file_path in included:
                if file_path in included:
                    provenance = _yaml.node_get_provenance(node)
                    provenance = _yaml.node_get_provenance(node)
                    raise LoadError(LoadErrorReason.RECURSIVE_INCLUDE,
                    raise LoadError(LoadErrorReason.RECURSIVE_INCLUDE,
@@ -59,7 +64,8 @@ class Includes:
                    included.add(file_path)
                    included.add(file_path)
                    self.process(include_node, included=included,
                    self.process(include_node, included=included,
                                 current_loader=sub_loader,
                                 current_loader=sub_loader,
                                 only_local=only_local)
                                 only_local=only_local,
                                 copy_tree=copy_tree)
                finally:
                finally:
                    included.remove(file_path)
                    included.remove(file_path)


@@ -74,7 +80,8 @@ class Includes:
            self._process_value(value,
            self._process_value(value,
                                included=included,
                                included=included,
                                current_loader=current_loader,
                                current_loader=current_loader,
                                only_local=only_local)
                                only_local=only_local,
                                copy_tree=copy_tree)


    # _include_file()
    # _include_file()
    #
    #
@@ -84,7 +91,7 @@ class Includes:
    #    include (str): file path relative to loader's project directory.
    #    include (str): file path relative to loader's project directory.
    #                   Can be prefixed with junctio name.
    #                   Can be prefixed with junctio name.
    #    loader (Loader): Loader for the current project.
    #    loader (Loader): Loader for the current project.
    def _include_file(self, include, loader):
    def _include_file(self, include, loader, *, copy_tree=False):
        shortname = include
        shortname = include
        if ':' in include:
        if ':' in include:
            junction, include = include.split(':', 1)
            junction, include = include.split(':', 1)
@@ -95,11 +102,12 @@ class Includes:
        project = current_loader.project
        project = current_loader.project
        directory = project.directory
        directory = project.directory
        file_path = os.path.join(directory, include)
        file_path = os.path.join(directory, include)
        key = (current_loader, file_path)
        key = (current_loader, file_path, copy_tree)
        if file_path not in self._loaded:
        if file_path not in self._loaded:
            self._loaded[key] = _yaml.load(os.path.join(directory, include),
            self._loaded[key] = _yaml.load(os.path.join(directory, include),
                                           shortname=shortname,
                                           shortname=shortname,
                                           project=project)
                                           project=project,
                                           copy_tree=copy_tree)
        return self._loaded[key], file_path, current_loader
        return self._loaded[key], file_path, current_loader


    # _process_value()
    # _process_value()
@@ -114,15 +122,18 @@ class Includes:
    def _process_value(self, value, *,
    def _process_value(self, value, *,
                       included=set(),
                       included=set(),
                       current_loader=None,
                       current_loader=None,
                       only_local=False):
                       only_local=False,
                       copy_tree=False):
        if isinstance(value, Mapping):
        if isinstance(value, Mapping):
            self.process(value,
            self.process(value,
                         included=included,
                         included=included,
                         current_loader=current_loader,
                         current_loader=current_loader,
                         only_local=only_local)
                         only_local=only_local,
                         copy_tree=copy_tree)
        elif isinstance(value, list):
        elif isinstance(value, list):
            for v in value:
            for v in value:
                self._process_value(v,
                self._process_value(v,
                                    included=included,
                                    included=included,
                                    current_loader=current_loader,
                                    current_loader=current_loader,
                                    only_local=only_local)
                                    only_local=only_local,
                                    copy_tree=copy_tree)
+1 −1
Original line number Original line Diff line number Diff line
@@ -251,7 +251,7 @@ class Loader():
        else:
        else:
            self.project.ensure_fully_loaded()
            self.project.ensure_fully_loaded()


            self._includes.process(node)
            self._includes.process(node, copy_tree=True)


            self._options.process_node(node)
            self._options.process_node(node)


+2 −2
Original line number Original line Diff line number Diff line
@@ -422,7 +422,7 @@ class Project():
        self._project_includes = Includes(self.loader)
        self._project_includes = Includes(self.loader)


        project_conf_first_pass = _yaml.node_copy(self._project_conf)
        project_conf_first_pass = _yaml.node_copy(self._project_conf)
        self._project_includes.process(project_conf_first_pass, only_local=True)
        self._project_includes.process(project_conf_first_pass, only_local=True, copy_tree=False)
        config_no_include = _yaml.node_copy(self._default_config_node)
        config_no_include = _yaml.node_copy(self._default_config_node)
        _yaml.composite(config_no_include, project_conf_first_pass)
        _yaml.composite(config_no_include, project_conf_first_pass)


@@ -446,7 +446,7 @@ class Project():
    #
    #
    def _load_second_pass(self):
    def _load_second_pass(self):
        project_conf_second_pass = _yaml.node_copy(self._project_conf)
        project_conf_second_pass = _yaml.node_copy(self._project_conf)
        self._project_includes.process(project_conf_second_pass)
        self._project_includes.process(project_conf_second_pass, copy_tree=False)
        config = _yaml.node_copy(self._default_config_node)
        config = _yaml.node_copy(self._default_config_node)
        _yaml.composite(config, project_conf_second_pass)
        _yaml.composite(config, project_conf_second_pass)


+1 −1
Original line number Original line Diff line number Diff line
@@ -794,7 +794,7 @@ class Source(Plugin):
                # Save the ref in the originating file
                # Save the ref in the originating file
                #
                #
                try:
                try:
                    _yaml.dump(_yaml.node_sanitize(provenance.toplevel), provenance.filename.name)
                    _yaml.dump(provenance.toplevel, provenance.filename.name)
                except OSError as e:
                except OSError as e:
                    raise SourceError("{}: Error saving source reference to '{}': {}"
                    raise SourceError("{}: Error saving source reference to '{}': {}"
                                      .format(self, provenance.filename.name, e),
                                      .format(self, provenance.filename.name, e),