From ba93dd20ca7f987ed6f23d525963329b77dc5813 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Thu, 7 Oct 2021 19:46:06 +0200 Subject: [PATCH] docs: Added pickle RefMan loader --- docs/refman/loaderpickle.py | 22 ++++++++++++++++++++++ docs/refman/main.py | 7 +++++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 docs/refman/loaderpickle.py diff --git a/docs/refman/loaderpickle.py b/docs/refman/loaderpickle.py new file mode 100644 index 000000000..722fedf05 --- /dev/null +++ b/docs/refman/loaderpickle.py @@ -0,0 +1,22 @@ +# SPDX-License-Identifer: Apache-2.0 +# Copyright 2021 The Meson development team + +from pathlib import Path +import pickle + +from .loaderbase import LoaderBase +from .model import ReferenceManual + +class LoaderPickle(LoaderBase): + def __init__(self, in_file: Path) -> None: + super().__init__() + self.in_file = in_file + + def load_impl(self) -> ReferenceManual: + res = pickle.loads(self.in_file.read_bytes()) + assert isinstance(res, ReferenceManual) + return res + + # Assume that the pickled data is OK and skip validation + def load(self) -> ReferenceManual: + return self.load_impl() diff --git a/docs/refman/main.py b/docs/refman/main.py index 913a0f375..fdc045bd2 100644 --- a/docs/refman/main.py +++ b/docs/refman/main.py @@ -19,6 +19,7 @@ import typing as T from mesonbuild import mlog from .loaderbase import LoaderBase +from .loaderpickle import LoaderPickle from .loaderyaml import LoaderYAML from .generatorbase import GeneratorBase @@ -30,10 +31,11 @@ meson_root = Path(__file__).absolute().parents[2] def main() -> int: parser = argparse.ArgumentParser(description='Meson reference manual generator') - parser.add_argument('-l', '--loader', type=str, default='yaml', choices=['yaml'], help='Information loader backend') + parser.add_argument('-l', '--loader', type=str, default='yaml', choices=['yaml', 'pickle'], help='Information loader backend') parser.add_argument('-g', '--generator', type=str, choices=['print', 'pickle', 'md'], required=True, help='Generator backend') parser.add_argument('-s', '--sitemap', type=Path, default=meson_root / 'docs' / 'sitemap.txt', help='Path to the input sitemap.txt') parser.add_argument('-o', '--out', type=Path, required=True, help='Output directory for generated files') + parser.add_argument('-i', '--input', type=Path, default=meson_root / 'docs' / 'yaml', help='Input path for the selected loader') parser.add_argument('--link-defs', type=Path, help='Output file for the MD generator link definition file') parser.add_argument('--depfile', type=Path, default=None, help='Set to generate a depfile') parser.add_argument('--force-color', action='store_true', help='Force enable colors') @@ -44,7 +46,8 @@ def main() -> int: mlog.colorize_console = lambda: True loaders: T.Dict[str, T.Callable[[], LoaderBase]] = { - 'yaml': lambda: LoaderYAML(meson_root / 'docs' / 'yaml'), + 'yaml': lambda: LoaderYAML(args.input), + 'pickle': lambda: LoaderPickle(args.input), } loader = loaders[args.loader]()