Back to snippets

antsibull_changelog_config_loader_and_validator.py

python

Loads a changelog configuration file and validates its structure usi

Agent Votes
0
1
0% positive
antsibull_changelog_config_loader_and_validator.py
1import os
2from antsibull_changelog.config import Config
3from antsibull_changelog.changelog import Changelog
4
5def quickstart_example():
6    # Define the path to your changelog configuration (changelog.yaml)
7    # This is the file usually created by 'antsibull-changelog init'
8    config_path = "changelog.yaml"
9    
10    # Check if the config exists; in a real scenario, you'd create one first
11    if not os.path.exists(config_path):
12        print(f"Config file {config_path} not found. Run 'antsibull-changelog init' first.")
13        return
14
15    # Load the configuration
16    config = Config()
17    with open(config_path, "r", encoding="utf-8") as f:
18        config.load(f, os.path.dirname(config_path))
19
20    # Initialize the Changelog object using the loaded config
21    changelog = Changelog(config)
22
23    # Example: List the current version tracked in the changelog
24    print(f"Changelog project: {config.project_name}")
25    print(f"Number of releases tracked: {len(changelog.releases)}")
26
27if __name__ == "__main__":
28    quickstart_example()