Skip to content

Commit 4acbfbf

Browse files
[libc][docs] move docgen from json to yaml
That way it can more easily be integrated into hdrgen.
1 parent c047a5b commit 4acbfbf

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

libc/utils/docgen/docgen.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from argparse import ArgumentParser, Namespace
1111
from pathlib import Path
1212
from typing import Dict
13-
import json
1413
import os
1514
import sys
15+
import yaml
1616

1717
from header import Header
1818

@@ -23,14 +23,14 @@ class DocgenAPIFormatError(Exception):
2323

2424
def 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

9595
def 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

100100
def 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.
198198
def 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

libc/utils/docgen/header.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Header:
1414
Maintains implementation information about a standard header file:
1515
* where does its implementation dir live
1616
* where is its macros file
17-
* where is its docgen json file
17+
* where is its docgen yaml file
1818
1919
By convention, the macro-only part of a header file is in a header-specific
2020
file somewhere in the directory tree with root at
@@ -42,7 +42,7 @@ def __init__(self, header_name: str):
4242
self.stem = header_name.rstrip(".h")
4343
self.docgen_root = Path(__file__).parent
4444
self.libc_root = self.docgen_root.parent.parent
45-
self.docgen_json = self.docgen_root / Path(header_name).with_suffix(".json")
45+
self.docgen_yaml = self.docgen_root / Path(header_name).with_suffix(".yaml")
4646
self.fns_dir = Path(self.libc_root, "src", self.stem)
4747
self.macros_dir = Path(self.libc_root, "include", "llvm-libc-macros")
4848

0 commit comments

Comments
 (0)