Python sphinx.ext.autosummary.get_documenter() Examples

The following are 11 code examples of sphinx.ext.autosummary.get_documenter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sphinx.ext.autosummary , or try the search function .
Example #1
Source File: conf.py    From python-zhmcclient with Apache License 2.0 5 votes vote down vote up
def _get_members(self, class_obj, member_type, include_in_public=None):
        """
        Return class members of the specified type.

        class_obj: Class object.

        member_type: Member type ('method' or 'attribute').

        include_in_public: set/list/tuple with member names that should be
          included in public members in addition to the public names (those
          starting without underscore).

        Returns:
          tuple(public_members, all_members): Names of the class members of
            the specified member type (public / all).
        """
        try:
            app = self.state.document.settings.env.app
        except AttributeError:
            app = None
        if not include_in_public:
            include_in_public = []
        all_members = []
        for member_name in dir(class_obj):
            try:
                documenter = get_documenter(
                    app,
                    safe_getattr(class_obj, member_name),
                    class_obj)
            except AttributeError:
                continue
            if documenter.objtype == member_type:
                all_members.append(member_name)
        public_members = [x for x in all_members
                  if x in include_in_public or not x.startswith('_')]
        return public_members, all_members 
Example #2
Source File: autoautosummary.py    From pyqgis with GNU General Public License v2.0 5 votes vote down vote up
def get_members(doc, obj, typ, include_public=None, signal=False, enum=False):
        try:
            if not include_public:
                include_public = []
            items = []

            for name in dir(obj):
                if name not in obj.__dict__.keys():
                    continue
                try:
                    chobj = safe_getattr(obj, name)
                    documenter = get_documenter(doc.settings.env.app, chobj, obj)
                    #cl = get_class_that_defined_method(chobj)
                    #print(name, chobj.__qualname__, type(chobj), issubclass(chobj, Enum), documenter.objtype)
                    if documenter.objtype == typ:
                        if typ == 'attribute':
                            if signal and type(chobj) != PyQt5.QtCore.pyqtSignal:
                                continue
                            if not signal and type(chobj) == PyQt5.QtCore.pyqtSignal:
                                continue
                        elif typ == 'class':
                            if enum and not issubclass(chobj, Enum):
                                continue
                            if not enum and issubclass(chobj, Enum):
                                continue
                        items.append(name)
                except AttributeError:
                    continue
            public = [x for x in items if x in include_public or not x.startswith('_')]
            return public, items
        except BaseException as e:
            print(str(e))
            raise e 
Example #3
Source File: conf.py    From nbodykit with GNU General Public License v3.0 5 votes vote down vote up
def get_members(clazz, obj, typ):
        names = set()
        items = []

        # the default dir
        for name in dir(obj):
            try:
                documenter = get_documenter(safe_getattr(obj, name), obj)
            except AttributeError:
                continue
            if documenter.objtype == typ and not name.startswith('_'):
                if name not in AutoCosmoSummary.exclude:
                    items.append((clazz,name))
                    names.add(name) # keep track of method/attribute conflicts

        # the delegate dro
        for n in obj.dro:
            for name in dir(n):
                try:
                    documenter = get_documenter(safe_getattr(n, name), n)
                except AttributeError:
                    continue

                # dont do conflicts
                if name not in names:
                    if documenter.objtype == typ and not name.startswith('_'):
                        if name not in AutoCosmoSummary.exclude:
                            x = "%s.%s" %(n.__module__, n.__name__)
                            items.append((x,name))
                            names.add(name)

        return ['~%s.%s' %item for item in sorted(items, key=lambda x: x[1])] 
Example #4
Source File: conf.py    From civis-python with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_members(obj, typ, public_only=True):
        items = []
        for name in dir(obj):
            if public_only and name.startswith('_'):
                continue
            try:
                documenter = get_documenter(None, safe_getattr(obj, name), obj)
            except AttributeError:
                continue
            if documenter.objtype == typ:
                items.append(name)
        return items 
Example #5
Source File: conf.py    From pyvista with MIT License 5 votes vote down vote up
def get_members(obj, typ, include_public=None):
        if not include_public:
            include_public = []
        items = []
        for name in sorted(obj.__dict__.keys()):#dir(obj):
            try:
                documenter = get_documenter(AutoAutoSummary.app, safe_getattr(obj, name), obj)
            except AttributeError:
                continue
            if documenter.objtype in typ:
                items.append(name)
        public = [x for x in items if x in include_public or not x.startswith('_')]
        return public, items 
Example #6
Source File: autosummary.py    From schedula with European Union Public License 1.1 5 votes vote down vote up
def get_members(app, obj, typ, include_public=(), imported=False):
    items = []
    for name in dir(obj):
        try:
            obj_name = safe_getattr(obj, name)
            try:
                documenter = get_documenter(app, obj_name, obj)
            except TypeError:
                documenter = get_documenter(obj_name, obj)

        except AttributeError:
            continue
        if documenter.objtype == typ:
            try:
                cond = imported or (obj_name.__module__ == obj.__name__)
            except AttributeError:
                cond = True

            if cond:
                items.append(name)
    skip = set(app.config.autosummary_skip_members)
    _n = '{}.%s'.format(obj.__name__)

    public = [
        x for x in items
        if (x in include_public or not x.startswith('_')) and _n % x not in skip
    ]
    return public, items 
Example #7
Source File: conf.py    From whatstk with GNU General Public License v3.0 5 votes vote down vote up
def get_members(obj, typ, include_public=None):
        if not include_public:
            include_public = []
        items = []
        for name in dir(obj):
            try:
                documenter = get_documenter(safe_getattr(obj, name), obj)
            except AttributeError:
                continue
            if documenter.objtype == typ:
                items.append(name)
        public = [x for x in items if x in include_public or not x.startswith('_')]
        return public, items 
Example #8
Source File: conf.py    From pywbem with GNU Lesser General Public License v2.1 5 votes vote down vote up
def _get_members(self, class_obj, member_type, include_in_public=None):
        """
        Return class members of the specified type.

        class_obj: Class object.

        member_type: Member type ('method' or 'attribute').

        include_in_public: set/list/tuple with member names that should be
          included in public members in addition to the public names (those
          starting without underscore).

        Returns:
          tuple(public_members, all_members): Names of the class members of
            the specified member type (public / all).
        """
        try:
            app = self.state.document.settings.env.app
        except AttributeError:
            app = None
        if not include_in_public:
            include_in_public = []
        all_members = []
        for member_name in dir(class_obj):
            try:
                documenter = get_documenter(
                    app,
                    safe_getattr(class_obj, member_name),
                    class_obj)
            except AttributeError:
                continue
            if documenter.objtype == member_type:
                all_members.append(member_name)
        public_members = [x for x in all_members
                  if x in include_in_public or not x.startswith('_')]
        return public_members, all_members 
Example #9
Source File: autoautosummary.py    From biskit with GNU General Public License v3.0 5 votes vote down vote up
def get_members(obj, typ, include_public=None):
        if not include_public:
            include_public = []
        items = []
        for name in dir(obj):
            try:
                documenter = get_documenter(safe_getattr(obj, name), obj)
            except AttributeError:
                continue
            if documenter.objtype == typ:
                items.append(name)
        public = [x for x in items if x in include_public or not x.startswith('_')]
        return public, items 
Example #10
Source File: conf.py    From pyvips with MIT License 4 votes vote down vote up
def setup(app):
    app.connect('autodoc-skip-member', skip_deprecated)
    try:
        from sphinx.ext.autosummary import Autosummary
        from sphinx.ext.autosummary import get_documenter
        from docutils.parsers.rst import directives
        from sphinx.util.inspect import safe_getattr

        class AutoAutoSummary(Autosummary):

            option_spec = {
                'methods': directives.unchanged,
                'attributes': directives.unchanged
            }

            required_arguments = 1

            @staticmethod
            def get_members(obj, typ, include_public=None):
                if not include_public:
                    include_public = []
                items = []
                for name in dir(obj):
                    try:
                        documenter = get_documenter(safe_getattr(obj, name),
                                                    obj)
                    except AttributeError:
                        continue
                    if documenter.objtype == typ:
                        items.append(name)
                public = [x for x in items
                          if x in include_public or not x.startswith('_')]
                return public, items

            def run(self):
                clazz = str(self.arguments[0])
                try:
                    (module_name, class_name) = clazz.rsplit('.', 1)
                    m = __import__(module_name, globals(), locals(),
                                   [class_name])
                    c = getattr(m, class_name)
                    if 'methods' in self.options:
                        _, methods = self.get_members(c,
                                                      'method', ['__init__'])

                        self.content = ["~%s.%s" % (clazz, method)
                                        for method in methods
                                        if not method.startswith('_')]
                    if 'attributes' in self.options:
                        _, attribs = self.get_members(c, 'attribute')
                        self.content = ["~%s.%s" % (clazz, attrib)
                                        for attrib in attribs
                                        if not attrib.startswith('_')]
                finally:
                    return super(AutoAutoSummary, self).run()

        app.add_directive('autoautosummary', AutoAutoSummary)
    except BaseException as e:
        raise e 
Example #11
Source File: directives.py    From gnomad_methods with MIT License 4 votes vote down vote up
def run(self):
        module_name = str(self.arguments[0])
        module = importlib.import_module(module_name)

        analyzer = ModuleAnalyzer.for_module(module_name)
        attr_docs = analyzer.find_attr_docs()

        with open(module.__file__) as module_file:
            symbols = symtable.symtable(module_file.read(), module.__file__, "exec")

        members = []

        for name in dir(module):
            member = getattr(module, name)

            # Ignore private members
            if name.startswith("_"):
                continue

            # Ignore imported modules
            if isinstance(member, types.ModuleType):
                continue

            # Ignore members imported from other modules
            member_module_name = getattr(member, "__module__", None)
            if member_module_name is None:
                try:
                    if symbols.lookup(name).is_imported():
                        continue
                except KeyError:
                    continue
            else:
                if member_module_name != module_name:
                    continue

            documenter = get_documenter(self.env.app, member, module)

            # Ignore data items that do not have docstrings
            if documenter.objtype == "data" and ("", name) not in attr_docs:
                continue

            members.append(name)

        # Sort members in the order they appear in source code
        tagorder = analyzer.tagorder
        members.sort(key=lambda name: tagorder.get(name, len(tagorder)))

        self.content = [f"{module_name}.{member}" for member in members]

        return super().run()