Skip to content

Commit

Permalink
doc: ai update config_file.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Louis Fuchs committed Apr 5, 2024
1 parent 4928d0c commit fc3cacc
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pyaptly/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@


def yaml_to_toml(yaml_path: Path, toml_path: Path, *, add_defaults: bool = False):
"""Convert pyaptly config files from yaml to toml.
"""
Convert pyaptly config files from YAML to TOML format.
Setting `add_defaults=True` will set common default during conversion.
The conversion process reads a configuration from the file located at `yaml_path`,
converts it to TOML format, and writes the result to the file specified by
`toml_path`. If `add_defaults` is set to True, common defaults are applied during
the conversion.
"""
with yaml_path.open("r", encoding="UTF-8") as yf:
with toml_path.open("wb") as tf:
Expand All @@ -19,8 +23,14 @@ def yaml_to_toml(yaml_path: Path, toml_path: Path, *, add_defaults: bool = False
tomli_w.dump(config, tf)


def add_default_to_config(config):
"""Set common default in config if the fields are missing."""
def add_default_to_config(config: dict):
"""
Set common defaults in `config` if the fields are missing.
This function checks for missing 'components' and 'distribution' fields under both
'mirror' and 'publish' sections of the configuration. If these fields are missing,
it sets them to 'main'.
"""
if "mirror" in config:
for mirror in config["mirror"].values():
if "components" not in mirror:
Expand Down

0 comments on commit fc3cacc

Please sign in to comment.