From bbaa17ef7dcb25687f74ffe6a9ba0029a8438ae3 Mon Sep 17 00:00:00 2001 From: Sveinung Gundersen Date: Tue, 17 Oct 2023 06:31:36 +0200 Subject: [PATCH] Tmptmp --- docs/templates/pdocs/class.mako | 25 +++++------ scripts/generate_portray_docs_in_browser.py | 23 +++++++++- src/omnipy/util/mako_helpers.py | 48 +++++++++++++++++---- 3 files changed, 74 insertions(+), 22 deletions(-) diff --git a/docs/templates/pdocs/class.mako b/docs/templates/pdocs/class.mako index fddd60f2..9022acb6 100644 --- a/docs/templates/pdocs/class.mako +++ b/docs/templates/pdocs/class.mako @@ -68,19 +68,20 @@ ${cls.docstring} mro = cls.mro() subclasses = cls.subclasses() %> -% if mro: -${h4('Ancestors (in MRO)')} - % for c in mro: -* ${c.refname} - % endfor -% endif -% if subclasses: -${h4('Descendants')} - % for c in subclasses: -* ${c.refname} - % endfor -% endif +## % if mro: +## ${h4('Ancestors (in MRO)')} +## % for c in mro: +## * ${c.refname} +## % endfor +## % endif + +## % if subclasses: +## ${h4('Descendants')} +## % for c in subclasses: +## * ${c.refname} +## % endfor +## % endif % if class_vars_internal: ${h4('Class variables')} diff --git a/scripts/generate_portray_docs_in_browser.py b/scripts/generate_portray_docs_in_browser.py index 64416486..300291a2 100755 --- a/scripts/generate_portray_docs_in_browser.py +++ b/scripts/generate_portray_docs_in_browser.py @@ -1,5 +1,24 @@ #!/usr/bin/env python - +import pdocs.doc from portray import api as portray_api -portray_api.in_browser() \ No newline at end of file + +def _is_exported(ident_name): + return not ident_name.startswith("_") or ident_name in [ + '__enter__', + '__exit__', + '__cmp__', + '__eq__', + '__getattr__', + '__setattr__', + '__getitem_', + '__setitem__', + '__delitem__', + '__iter__', + '__call__' + ] + + +pdocs.doc._is_exported = _is_exported + +portray_api.in_browser() diff --git a/src/omnipy/util/mako_helpers.py b/src/omnipy/util/mako_helpers.py index a370c5ab..493e8416 100644 --- a/src/omnipy/util/mako_helpers.py +++ b/src/omnipy/util/mako_helpers.py @@ -18,17 +18,49 @@ def filter_external(members: List[Doc]): def filter_internal(members: List[Doc]): - return list(_ for _ in members if not externally_inherited(_)) + ret = {_.name: externally_inherited(_) for _ in members} + + ret = list(_ for _ in members if not externally_inherited(_)) + return ret + + + # def _fill_inheritance(self): + # """ + # Traverses this class's ancestor list and attempts to fill in + # missing documentation from its ancestor's documentation. + # + # The first pass connects variables, methods and functions with + # their inherited couterparts. (The templates will decide how to + # display docstrings.) The second pass attempts to add instance + # variables to this class that were only explicitly declared in + # a parent class. This second pass is necessary since instance + # variables are only discoverable by traversing the abstract + # syntax tree. + # """ + # mro = [self.module.find_ident(c.name) for c in self.module.mro(self) if c != self] + # mro = [c for c in mro if isinstance(c, Class)] +def internal(member: Doc): + module_name = "" - -def externally_inherited(member: Doc): if hasattr(member, 'inherits'): - if externally_inherited(member.inherits): + if internal(member.inherits): return True - elif not member.inherits.cls.module.name.startswith('omnipy'): - print(member.inherits.cls.module.name) - return True - return member.name not in vars(member.cls.cls) + else: + module_name = member.inherits.cls.module.name + elif hasattr(member.cls.cls, member.name): + member_obj = getattr(member.cls.cls, member.name) + if hasattr(member_obj, '__module__') and member_obj.__module__: + module_name = member_obj.__module__ + print(f'Without inherits: {member.name} from {module_name}') + else: + return False + + return module_name.startswith('omnipy') + + +def externally_inherited(member: Doc): + inherited = member.name not in vars(member.cls.cls) + return inherited and not internal(member) def merge_signature_with_docstring(func: Function,