summaryrefslogtreecommitdiff
path: root/docs/refman/generatorbase.py
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2021-06-25 19:48:43 +0200
committerDaniel Mensinger <daniel@mensinger-ka.de>2021-10-03 11:46:34 +0200
commitad65a699f93a7659739287882ca27c58c564670b (patch)
tree956660da72b5322e1860c27f159da5d0463d5aca /docs/refman/generatorbase.py
parent3feaea6b29197cd224fbce0ac65fd43d08c3beac (diff)
downloadmeson-ad65a699f93a7659739287882ca27c58c564670b.tar.gz
docs: Initial reference manual generator
Diffstat (limited to 'docs/refman/generatorbase.py')
-rw-r--r--docs/refman/generatorbase.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/docs/refman/generatorbase.py b/docs/refman/generatorbase.py
new file mode 100644
index 000000000..517c59262
--- /dev/null
+++ b/docs/refman/generatorbase.py
@@ -0,0 +1,67 @@
+# Copyright 2021 The Meson development team
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from abc import ABCMeta, abstractmethod
+import typing as T
+
+from .model import ReferenceManual, Function, Object, ObjectType, NamedObject
+
+_N = T.TypeVar('_N', bound=NamedObject)
+
+class GeneratorBase(metaclass=ABCMeta):
+ def __init__(self, manual: ReferenceManual) -> None:
+ self.manual = manual
+
+ @abstractmethod
+ def generate(self) -> None:
+ pass
+
+ @staticmethod
+ def brief(raw: _N) -> str:
+ desc_lines = raw.description.split('\n')
+ brief = desc_lines[0]
+ if '.' in brief and '[[' not in brief:
+ brief = brief[:brief.index('.')]
+ return brief.strip()
+
+ @staticmethod
+ def sorted_and_filtered(raw: T.List[_N]) -> T.List[_N]:
+ return sorted([x for x in raw if not x.hidden], key=lambda x: x.name)
+
+ @property
+ def functions(self) -> T.List[Function]:
+ return GeneratorBase.sorted_and_filtered(self.manual.functions)
+
+ @property
+ def objects(self) -> T.List[Object]:
+ return GeneratorBase.sorted_and_filtered(self.manual.objects)
+
+ @property
+ def elementary(self) -> T.List[Object]:
+ return [x for x in self.objects if x.obj_type == ObjectType.ELEMENTARY]
+
+ @property
+ def builtins(self) -> T.List[Object]:
+ return [x for x in self.objects if x.obj_type == ObjectType.BUILTIN]
+
+ @property
+ def returned(self) -> T.List[Object]:
+ return [x for x in self.objects if x.obj_type == ObjectType.RETURNED and x.defined_by_module is None]
+
+ @property
+ def modules(self) -> T.List[Object]:
+ return [x for x in self.objects if x.obj_type == ObjectType.MODULE]
+
+ def extract_returned_by_module(self, module: Object) -> T.List[Object]:
+ return [x for x in self.objects if x.obj_type == ObjectType.RETURNED and x.defined_by_module is module]