Support a TOML configuration file
The new config file currently only configures the same options that were already available through environment variables. However I have ideas for additional features that would be much nicer to support using a structured configuration format like TOML rather than environment variables, so config files exist now! The previous environment variables are still supported and will be used if you don't have a config file. I plan to keep supporting the MPD_HOST and MPD_PORT environment variables forever since they're shared with other MPD clients such as mpc, but I may eventually drop the environment variables specific to mpd-now-playable in a future release.
This commit is contained in:
parent
796e3df87d
commit
dc037a0a4b
12 changed files with 305 additions and 33 deletions
28
src/mpd_now_playable/config/schema.py
Normal file
28
src/mpd_now_playable/config/schema.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from json import dump
|
||||
from pathlib import Path
|
||||
from pprint import pp
|
||||
from typing import Any, Mapping
|
||||
|
||||
from apischema.json_schema import JsonSchemaVersion, deserialization_schema
|
||||
|
||||
from .model import Config
|
||||
|
||||
|
||||
def generate() -> Mapping[str, Any]:
|
||||
return deserialization_schema(Config, version=JsonSchemaVersion.DRAFT_7)
|
||||
|
||||
|
||||
def write() -> None:
|
||||
schema = dict(generate())
|
||||
schema["$id"] = Config.schema.human_repr()
|
||||
|
||||
schema_file = Path(__file__).parent / Config.schema.name
|
||||
print(f"Writing this schema to {schema_file}")
|
||||
pp(schema)
|
||||
with open(schema_file, "w") as fp:
|
||||
dump(schema, fp, indent="\t", sort_keys=True)
|
||||
fp.write("\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
write()
|
||||
Loading…
Add table
Add a link
Reference in a new issue