37 def from_toml_file(cls, cfg_file: pathlib.Path, use_cache: bool) -> "FaviconConfig":
38 """Create a config object from a TOML file, the ``use_cache`` argument
39 specifies whether a cache should be used.
40 """
41
42 cached = TOML_CACHE_CFG.get(str(cfg_file))
43 if use_cache and cached:
44 return cached
45
46 with cfg_file.open("rb") as f:
47 data = f.read()
48
49 cfg = msgspec.toml.decode(data, type=_FaviconConfig)
50 schema = cfg.favicons.cfg_schema
51 if schema != CONFIG_SCHEMA:
52 raise ValueError(
53 f"config schema version {CONFIG_SCHEMA} is needed, version {schema} is given in {cfg_file}"
54 )
55
56 cfg = cfg.favicons
57 if use_cache and cached:
58 TOML_CACHE_CFG[str(cfg_file.resolve())] = cfg
59
60 return cfg
61
62