1010from argparse import ArgumentParser , Namespace
1111from pathlib import Path
1212from typing import Dict
13- import json
1413import os
1514import sys
15+ import yaml
1616
1717from header import Header
1818
@@ -23,14 +23,14 @@ class DocgenAPIFormatError(Exception):
2323
2424def check_api (header : Header , api : Dict ):
2525 """
26- Checks that docgen json files are properly formatted. If there are any
26+ Checks that docgen yaml files are properly formatted. If there are any
2727 fatal formatting errors, raises exceptions with error messages useful for
2828 fixing formatting. Warnings are printed to stderr on non-fatal formatting
2929 errors. The code that runs after ``check_api(api)`` is called expects that
30- ``check_api`` executed without raising formatting exceptions so the json
30+ ``check_api`` executed without raising formatting exceptions so the yaml
3131 matches the formatting specified here.
3232
33- The json file may contain:
33+ The yaml file may contain:
3434 * an optional macros object
3535 * an optional functions object
3636
@@ -49,7 +49,7 @@ def check_api(header: Header, api: Dict):
4949 this should be a C standard section number. For the ``"posix-definition"`` property,
5050 this should be a link to the definition.
5151
52- :param api: docgen json file contents parsed into a dict
52+ :param api: docgen yaml file contents parsed into a dict
5353 """
5454 errors = []
5555 # We require entries to have at least one of these.
@@ -93,8 +93,8 @@ def check_api(header: Header, api: Dict):
9393
9494
9595def load_api (header : Header ) -> Dict :
96- api = header .docgen_json .read_text (encoding = "utf-8" )
97- return json . loads (api )
96+ api = header .docgen_yaml .read_text (encoding = "utf-8" )
97+ return yaml . safe_load (api )
9898
9999
100100def print_tbl_dir (name ):
@@ -192,12 +192,12 @@ def print_impl_status_rst(header: Header, api: Dict):
192192 print_functions_rst (header , api ["functions" ])
193193
194194
195- # This code implicitly relies on docgen.py being in the same dir as the json
195+ # This code implicitly relies on docgen.py being in the same dir as the yaml
196196# files and is likely to need to be fixed when re-integrating docgen into
197197# hdrgen.
198198def get_choices () -> list :
199199 choices = []
200- for path in Path (__file__ ).parent .rglob ("*.json " ):
200+ for path in Path (__file__ ).parent .rglob ("*.yaml " ):
201201 fname = path .with_suffix (".h" ).name
202202 if path .parent != Path (__file__ ).parent :
203203 fname = path .parent .name + os .sep + fname
0 commit comments