Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: ai update config_file.py #104

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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