def prepend(self,
                provider: str,
                path: str,
                anchor: Optional[SearchPathQuery] = None) -> None:
        """
        Prepends to the search path.
        Note, this currently only takes effect if called before the ConfigRepository is instantiated.

        :param provider: who is providing this search path, can be Hydra,
               the @hydra.main() function, or individual plugins or libraries.
        :param path: path element, can be a file system path or a package path (For example pkg://hydra.conf)
        :param anchor: if string, acts as provider. if SearchPath can be used to match against provider and / or path
        """
        if anchor is None:
            self.config_search_path.insert(0,
                                           SearchPathElement(provider, path))
        else:
            if isinstance(anchor, str):
                anchor = SearchPathQuery(anchor, None)

            idx = self.find_first_match(anchor)
            if idx != -1:
                if idx > 0:
                    self.config_search_path.insert(
                        idx, SearchPathElement(provider, path))
                else:
                    self.prepend(provider, path, None)
            else:
                self.prepend(provider, path, None)
    def append(self,
               provider: str,
               path: str,
               anchor: Optional[SearchPathQuery] = None) -> None:
        if anchor is None:
            self.config_search_path.append(SearchPathElement(provider, path))
        else:
            if isinstance(anchor, str):
                anchor = SearchPathQuery(anchor, None)

            idx = self.find_last_match(anchor)
            if idx != -1:
                self.config_search_path.insert(
                    idx + 1, SearchPathElement(provider, path))
            else:
                self.append(provider, path, anchor=None)
Пример #3
0
def create_search_path(base_list: List[Tuple[str, str]]) -> ConfigSearchPathImpl:
    csp = ConfigSearchPathImpl()
    csp.config_search_path = [SearchPathElement(x[0], x[1]) for x in base_list]
    return csp