Пример #1
0
    def load_config(self,
                    config_path: str,
                    package_override: Optional[str] = None) -> ConfigResult:
        name = self._normalize_file_name(config_path)

        if name not in self.configs:
            raise ConfigLoadError("Config not found : " + config_path)

        res_header: Dict[str, Optional[str]] = {"package": None}
        if name in self.headers:
            header = self.headers[name]
            res_header[
                "package"] = header["package"] if "package" in header else None

        cfg = OmegaConf.create(self.configs[name])
        return ConfigResult(
            config=cfg,
            path=f"{self.scheme()}://{self.path}",
            provider=self.provider,
            header=res_header,
        )
Пример #2
0
 def load_config(
     self, config_path: str, package_override: Optional[str] = None
 ) -> ConfigResult:
     normalized_config_path = self._normalize_file_name(config_path)
     full_path = os.path.realpath(os.path.join(self.path, normalized_config_path))
     if not os.path.exists(full_path):
         raise ConfigLoadError(f"FileConfigSource: Config not found : {full_path}")
     with open(full_path) as f:
         header_text = f.read(512)
         header = ConfigSource._get_header_dict(header_text)
         self._update_package_in_header(
             header, normalized_config_path, package_override
         )
         f.seek(0)
         cfg = OmegaConf.load(f)
         return ConfigResult(
             config=self._embed_config(cfg, header["package"]),
             path=f"{self.scheme()}://{self.path}",
             provider=self.provider,
             header=header,
         )
 def _read_config(self, res: Any) -> ConfigResult:
     try:
         if sys.version_info[0:2] >= (3, 8) and isinstance(
                 res, zipfile.Path):
             # zipfile does not support encoding, read() calls returns bytes.
             f = res.open()
         else:
             f = res.open(encoding="utf-8")
         header_text = f.read(512)
         if isinstance(header_text, bytes):
             # if header is bytes, utf-8 decode (zipfile path)
             header_text = header_text.decode("utf-8")
         header = ConfigSource._get_header_dict(header_text)
         f.seek(0)
         cfg = OmegaConf.load(f)
         return ConfigResult(
             config=cfg,
             path=f"{self.scheme()}://{self.path}",
             provider=self.provider,
             header=header,
         )
     finally:
         f.close()
Пример #4
0
 def load_config(self, config_path: str) -> ConfigResult:
     return ConfigResult(
         config=ConfigStore.instance().load(config_path=config_path),
         path=f"{self.scheme()}://{self.path}",
         provider=self.provider,
     )