Exemplo n.º 1
0
    def make_rst(self):
        module = importlib.import_module(self.arguments[0])

        BaseClass = None
        if ':baseclass:' in self.arguments:
            BaseClass = import_class(*self.arguments[
                self.arguments.index(':baseclass:') + 1].rsplit('.', 1))

        for item in dir(module):
            obj = import_class(self.arguments[0], item)
            if not inspect.isclass(obj) or (BaseClass and
                not issubclass(obj, BaseClass)):
                continue

            context = {
                'module': self.arguments[0],
                'class_name': item,
                'no_config': ':no-config:' in self.arguments,
                'no_commands': ':no-commands:' in self.arguments,
            }
            rst = qtile_module_template.render(**context)
            for line in rst.splitlines():
                if not line.strip():
                    continue
                yield line
Exemplo n.º 2
0
 def make_rst(self):
     module, class_name = self.arguments[0].rsplit('.', 1)
     obj = import_class(module, class_name)
     for method in sorted(obj.hooks):
         rst = qtile_hooks_template.render(method=method)
         for line in rst.splitlines():
             yield line
Exemplo n.º 3
0
    def make_rst(self):
        module, class_name = self.arguments[0].rsplit('.', 1)
        arguments = self.arguments[1:]
        obj = import_class(module, class_name)
        is_configurable = ':no-config:' not in arguments
        is_commandable = ':no-commands:' not in arguments
        arguments = [
            i for i in arguments if i not in (':no-config:', ':no-commands:')
        ]

        # build up a dict of defaults using reverse MRO
        defaults = {}
        for klass in reversed(obj.mro()):
            if not issubclass(klass, configurable.Configurable):
                continue
            if not hasattr(klass, "defaults"):
                continue
            klass_defaults = getattr(klass, "defaults")
            defaults.update({d[0]: d[1:] for d in klass_defaults})
        # turn the dict into a list of ("value", "default", "description") tuples
        defaults = [(k, sphinx_escape(v[0]), sphinx_escape(v[1]))
                    for k, v in sorted(defaults.items())]
        if len(defaults) == 0:
            is_configurable = False

        context = {
            'module':
            module,
            'class_name':
            class_name,
            'class_underline':
            "=" * len(class_name),
            'obj':
            obj,
            'defaults':
            defaults,
            'configurable':
            is_configurable and issubclass(obj, configurable.Configurable),
            'commandable':
            is_commandable and issubclass(obj, command.base.CommandObject),
            'is_widget':
            issubclass(obj, widget.base._Widget),
            'extra_arguments':
            arguments,
        }
        if context['commandable']:
            context['commands'] = [
                attr for attr in dir(obj) if attr.startswith('cmd_')
            ]

        rst = qtile_class_template.render(**context)
        for line in rst.splitlines():
            yield line