Example #1
0
def create_module_docs(config):
    """
    Create documentation for modules.
    """
    data = core_module_docstrings(format="md")
    # get screenshot data
    screenshots_data = {}
    samples = get_samples()
    for sample in samples:
        module = sample.split("-")[0]
        if module not in screenshots_data:
            screenshots_data[module] = []
        screenshots_data[module].append(sample)

    out = ["# Available modules"]
    # details
    for module in sorted(data):
        out.append(
            "\n## {name}\n\n{screenshots}\n{details}\n".format(
                name=module,
                screenshots=screenshots(config, screenshots_data, module),
                details="".join(data[module]).strip(),
            )
        )
    # write include file
    path = f"{config['docs_dir']}/user-guide/modules.md"
    print(f"Writing modules documentation to {path}...")
    Path(path).write_text("".join(out))
    return config
Example #2
0
def create_module_docs():
    """
    Create documentation for modules.
    """
    data = core_module_docstrings(format="rst")
    # get screenshot data
    screenshots_data = {}
    samples = get_samples()
    for sample in samples.keys():
        module = sample.split("-")[0]
        if module not in screenshots_data:
            screenshots_data[module] = []
        screenshots_data[module].append(sample)

    out = []
    # details
    for module in sorted(data.keys()):
        out.append("\n.. _module_%s:\n" % module)  # reference for linking
        out.append(
            "\n{name}\n{underline}\n\n{screenshots}{details}\n".format(
                name=module,
                screenshots=screenshots(screenshots_data, module),
                underline="-" * len(module),
                details="".join(markdown_2_rst(data[module])).strip(),
            )
        )
    # write include file
    with open("../doc/modules-info.inc", "w") as f:
        f.write("".join(out))
Example #3
0
def create_module_docs():
    """
    Create documentation for modules.
    """
    data = core_module_docstrings(format="rst")
    # get screenshot data
    screenshots_data = {}
    samples = get_samples()
    for sample in samples:
        module = sample.split("-")[0]
        if module not in screenshots_data:
            screenshots_data[module] = []
        screenshots_data[module].append(sample)

    out = []
    # details
    for module in sorted(data):
        out.append(f"\n.. _module_{module}:\n")  # reference for linking
        out.append(
            "\n{name}\n{underline}\n\n{screenshots}{details}\n".format(
                name=module,
                screenshots=screenshots(screenshots_data, module),
                underline="-" * len(module),
                details="".join(markdown_2_rst(data[module])).strip(),
            )
        )
    # write include file
    Path("../doc/modules-info.inc").write_text("".join(out))
Example #4
0
def create_module_docs():
    """
    Create documentation for modules.
    """
    data = core_module_docstrings(format='rst')
    # get screenshot data
    screenshots_data = {}
    samples = get_samples()
    for sample in samples.keys():
        module = sample.split('-')[0]
        if module not in screenshots_data:
            screenshots_data[module] = []
        screenshots_data[module].append(sample)

    out = []
    # details
    for module in sorted(data.keys()):
        out.append('\n.. _module_%s:\n' % module)  # reference for linking
        out.append(
            '\n{name}\n{underline}\n\n{screenshots}{details}\n'.format(
                name=module,
                screenshots=screenshots(screenshots_data, module),
                underline='-' * len(module),
                details=''.join(markdown_2_rst(data[module])).strip()
            )
        )
    # write include file
    with open('../doc/modules-info.inc', 'w') as f:
        f.write(''.join(out))
Example #5
0
def create_module_docs():
    """
    Create documentation for modules.
    """
    data = core_module_docstrings(format='rst')

    out = []
    # details
    for module in sorted(data.keys()):
        out.append('\n{name}\n{underline}\n\n{details}\n'.format(
            name=module,
            underline='-' * len(module),
            details=''.join(markdown_2_rst(data[module])).strip()))
    # write include file
    with open('../doc/modules-info.inc', 'w') as f:
        f.write(''.join(out))
Example #6
0
def check_docstrings():
    all_errors = []
    docstrings = core_module_docstrings()
    for module_name in sorted(docstrings.keys()):
        errors = []
        if module_name in IGNORE_MODULE:
            continue

        path = os.path.join(MODULE_PATH, "%s.py" % module_name)
        mod_config = get_module_attributes(path)

        params, obsolete = docstring_params(docstrings[module_name])

        if list(params.keys()) != list(sorted(params.keys())):
            keys = list(params.keys())
            msg = "config params not in alphabetical order should be\n{keys}"
            errors.append(msg.format(keys=_gen_diff(keys, sorted(keys))))
        if list(obsolete.keys()) != list(sorted(obsolete.keys())):
            keys = list(obsolete.keys())
            msg = "obsolete params not in alphabetical order should be\n{keys}"
            errors.append(msg.format(keys=_gen_diff(keys, sorted(keys))))

        # combine docstring parameters
        params.update(obsolete)

        # bad config params - these have reserved usage
        allowed_bad_config_params = [
            x[1] for x in IGNORE_ILLEGAL_CONFIG_OPTIONS if x[0] == module_name
        ]
        bad_config_params = set(ILLEGAL_CONFIG_OPTIONS) & set(params)
        bad_config_params -= set(allowed_bad_config_params)

        if bad_config_params:
            msg = "The following config parameters are reserved and"
            msg += "should not be used by modules:\n    {}"
            errors.append(msg.format(", ".join(bad_config_params)))

        # check attributes are in alphabetical order
        keys = list(mod_config.keys())
        for item in IGNORE_ITEM:
            if item[0] == module_name and item[1] in keys:
                keys.remove(item[1])
        for item in OBSOLETE_PARAM:
            if item[0] == module_name and item[1] in keys:
                keys.remove(item[1])
        if keys != sorted(keys):
            errors.append("Attributes not in alphabetical order, should be")
            errors.append(_gen_diff(keys, sorted(keys)))

        for param in sorted(mod_config.keys()):
            if (module_name, param) in IGNORE_ITEM:
                continue
            default = mod_config[param]
            if param not in params:
                msg = "{}: (default {!r}) not in module docstring"
                errors.append(msg.format(param, default))
                continue
            default_doc = params[param]
            if default_doc is None:
                msg = "`{}` default not in docstring add (default {!r})"
                errors.append(msg.format(param, default))
                del params[param]
                continue
            if default_doc[0] != default:
                msg = "`{}` (default {!r}) does not match docstring {!r}"
                errors.append(msg.format(param, default, default_doc[0]))
                del params[param]
                continue
            del params[param]

        for param in params:
            if (module_name, param) in IGNORE_ITEM:
                continue
            errors.append("{} in module docstring but not module".format(param))
        if errors:
            all_errors += ["=" * 30, module_name, "=" * 30] + errors + ["\n"]
    return all_errors
Example #7
0
def check_docstrings():
    all_errors = []
    docstrings = core_module_docstrings()
    for module_name in sorted(docstrings.keys()):
        errors = []
        if module_name in IGNORE_MODULE:
            continue

        path = os.path.join(MODULE_PATH, '%s.py' % module_name)
        mod_config = get_module_attributes(path)

        params, obsolete = docstring_params(docstrings[module_name])

        if list(params.keys()) != list(sorted(params.keys())):
            keys = list(sorted(params.keys()))
            msg = 'config params not in alphabetical order should be\n{keys}'
            errors.append(msg.format(keys=keys))
        if list(obsolete.keys()) != list(sorted(obsolete.keys())):
            keys = list(sorted(obsolete.keys()))
            msg = 'obsolete params not in alphabetical order should be\n{keys}'
            errors.append(msg.format(keys=keys))

        # combine docstring parameters
        params.update(obsolete)

        # bad config params - these have reserved usage
        allowed_bad_config_params = [
            x[1] for x in IGNORE_ILLEGAL_CONFIG_OPTIONS if x[0] == module_name
        ]
        bad_config_params = set(ILLEGAL_CONFIG_OPTIONS) & set(params)
        bad_config_params -= set(allowed_bad_config_params)

        if bad_config_params:
            msg = 'The following config parameters are reserved and'
            msg += 'should not be used by modules:\n    {}'
            errors.append(msg.format(', '.join(bad_config_params)))

        # check attributes are in alphabetical order
        keys = list(mod_config.keys())
        for item in IGNORE_ITEM:
            if item[0] == module_name and item[1] in keys:
                keys.remove(item[1])
        for item in OBSOLETE_PARAM:
            if item[0] == module_name and item[1] in keys:
                keys.remove(item[1])
        if keys != sorted(keys):
            errors.append('Attributes not in alphabetical order, should be')
            errors.append(sorted(mod_config.keys()))

        for param in sorted(mod_config.keys()):
            if (module_name, param) in IGNORE_ITEM:
                continue
            default = mod_config[param]
            if param not in params:
                msg = '{}: (default {!r}) not in module docstring'
                errors.append(msg.format(param, default))
                continue
            default_doc = params[param]
            if default_doc is None:
                msg = '`{}` default not in docstring add (default {!r})'
                errors.append(msg.format(param, default))
                del params[param]
                continue
            if default_doc[0] != default:
                msg = '`{}` (default {!r}) does not match docstring {!r}'
                errors.append(msg.format(param, default, default_doc[0]))
                del params[param]
                continue
            del params[param]

        for param in params:
            if (module_name, param) in IGNORE_ITEM:
                continue
            errors.append(
                '{} in module docstring but not module'.format(param))
        if errors:
            all_errors += ['=' * 30, module_name, '=' * 30] + errors + ['\n']
    return all_errors
Example #8
0
def check_docstrings():
    all_errors = []
    docstrings = core_module_docstrings()
    for module_name in sorted(docstrings.keys()):
        errors = []
        if module_name in IGNORE_MODULE:
            continue

        path = MODULE_PATH / f"{module_name}.py"
        mod_config = get_module_attributes(path)

        params, obsolete = docstring_params(docstrings[module_name])

        if list(params.keys()) != list(sorted(params.keys())):
            keys = list(params.keys())
            msg = "config params not in alphabetical order should be\n{keys}"
            errors.append(msg.format(keys=_gen_diff(keys, sorted(keys))))
        if list(obsolete.keys()) != list(sorted(obsolete.keys())):
            keys = list(obsolete.keys())
            msg = "obsolete params not in alphabetical order should be\n{keys}"
            errors.append(msg.format(keys=_gen_diff(keys, sorted(keys))))

        # combine docstring parameters
        params.update(obsolete)

        # bad config params - these have reserved usage
        allowed_bad_config_params = [
            x[1] for x in IGNORE_ILLEGAL_CONFIG_OPTIONS if x[0] == module_name
        ]
        bad_config_params = set(ILLEGAL_CONFIG_OPTIONS) & set(params)
        bad_config_params -= set(allowed_bad_config_params)

        if bad_config_params:
            msg = "The following config parameters are reserved and"
            msg += "should not be used by modules:\n    {}"
            errors.append(msg.format(", ".join(bad_config_params)))

        # check attributes are in alphabetical order
        keys = list(mod_config.keys())
        for item in IGNORE_ITEM:
            if item[0] == module_name and item[1] in keys:
                keys.remove(item[1])
        for item in OBSOLETE_PARAM:
            if item[0] == module_name and item[1] in keys:
                keys.remove(item[1])
        if keys != sorted(keys):
            errors.append("Attributes not in alphabetical order, should be")
            errors.append(_gen_diff(keys, sorted(keys)))

        for param in sorted(mod_config.keys()):
            if (module_name, param) in IGNORE_ITEM:
                continue
            default = mod_config[param]
            if param not in params:
                msg = "{}: (default {!r}) not in module docstring"
                errors.append(msg.format(param, default))
                continue
            default_doc = params[param]
            if default_doc is None:
                msg = "`{}` default not in docstring add (default {!r})"
                errors.append(msg.format(param, default))
                del params[param]
                continue
            if default_doc[0] != default:
                msg = "`{}` (default {!r}) does not match docstring {!r}"
                errors.append(msg.format(param, default, default_doc[0]))
                del params[param]
                continue
            del params[param]

        for param in params:
            if (module_name, param) in IGNORE_ITEM:
                continue
            errors.append(f"{param} in module docstring but not module")
        if errors:
            all_errors += ["=" * 30, module_name, "=" * 30] + errors + ["\n"]
    return all_errors
Example #9
0
def check_docstrings():
    all_errors = []
    docstrings = core_module_docstrings()
    for module_name in sorted(docstrings.keys()):
        errors = []
        if module_name in IGNORE_MODULE:
            continue
        name = 'py3status.modules.{}'.format(module_name)
        try:
            py_mod = __import__(name)
            pass
        except ImportError as e:
            msg = 'Cannot import module `{}` {}'
            errors.append(msg.format(module_name, e))
            continue
        except Exception as e:
            msg = 'Cannot import module `{}` {}'
            errors.append(msg.format(module_name, e))
            continue

        try:
            py_mod = __import__(name)
            py3_mod = getattr(py_mod.modules, module_name).Py3status
        except AttributeError as e:
            msg = 'Module `{}` pas no Py3status class'
            errors.append(msg.format(module_name))
            continue
        mod_config = OrderedDict()
        for attribute_name in sorted(dir(py3_mod)):
            if attribute_name.startswith('_'):
                continue
            attribute = getattr(py3_mod, attribute_name)
            if repr(attribute).startswith('<'):
                continue
            if isinstance(attribute, str):
                try:
                    attribute = attribute.decode('utf-8')
                except AttributeError:
                    # python3
                    pass
            mod_config[attribute_name] = attribute
        params, obsolete = docstring_params(docstrings[module_name])

        if list(params.keys()) != list(sorted(params.keys())):
            keys = list(sorted(params.keys()))
            msg = 'config params not in alphabetical order should be\n{keys}'
            errors.append(msg.format(keys=keys))
        if list(obsolete.keys()) != list(sorted(obsolete.keys())):
            keys = list(sorted(obsolete.keys()))
            msg = 'obsolete params not in alphabetical order should be\n{keys}'
            errors.append(msg.format(keys=keys))

        # combine docstring parameters
        params.update(obsolete)

        for param in sorted(mod_config.keys()):
            if (module_name, param) in IGNORE_ITEM:
                continue
            default = mod_config[param]
            if param not in params:
                msg = '{}: (default {!r}) not in module docstring'
                errors.append(msg.format(param, default))
                continue
            default_doc = params[param]
            if default_doc is None:
                msg = '`{}` default not in docstring add (default {!r})'
                errors.append(msg.format(param, default))
                del params[param]
                continue
            if default_doc[0] != default:
                msg = '`{}` (default {!r}) does not match docstring {!r}'
                errors.append(msg.format(param, default, default_doc[0]))
                del params[param]
                continue
            del params[param]

        for param in params:
            if (module_name, param) in IGNORE_ITEM:
                continue
            errors.append('{} in module docstring but not module'.format(param))
        if errors:
            all_errors += ['=' * 30, module_name, '=' * 30] + errors + ['\n']
    return all_errors
Example #10
0
def check_docstrings():
    all_errors = []
    docstrings = core_module_docstrings()
    for module_name in sorted(docstrings.keys()):
        errors = []
        if module_name in IGNORE_MODULE:
            continue

        path = os.path.join(MODULE_PATH, '%s.py' % module_name)
        mod_config = get_module_attributes(path)

        params, obsolete = docstring_params(docstrings[module_name])

        if list(params.keys()) != list(sorted(params.keys())):
            keys = list(sorted(params.keys()))
            msg = 'config params not in alphabetical order should be\n{keys}'
            errors.append(msg.format(keys=keys))
        if list(obsolete.keys()) != list(sorted(obsolete.keys())):
            keys = list(sorted(obsolete.keys()))
            msg = 'obsolete params not in alphabetical order should be\n{keys}'
            errors.append(msg.format(keys=keys))

        # combine docstring parameters
        params.update(obsolete)

        # check attributes are in alphabetical order
        keys = list(mod_config.keys())
        for item in IGNORE_ITEM:
            if item[0] == module_name and item[1] in keys:
                keys.remove(item[1])
        for item in OBSOLETE_PARAM:
            if item[0] == module_name and item[1] in keys:
                keys.remove(item[1])
        if keys != sorted(keys):
            errors.append('Attributes not in alphabetical order, should be')
            errors.append(sorted(mod_config.keys()))

        for param in sorted(mod_config.keys()):
            if (module_name, param) in IGNORE_ITEM:
                continue
            default = mod_config[param]
            if param not in params:
                msg = '{}: (default {!r}) not in module docstring'
                errors.append(msg.format(param, default))
                continue
            default_doc = params[param]
            if default_doc is None:
                msg = '`{}` default not in docstring add (default {!r})'
                errors.append(msg.format(param, default))
                del params[param]
                continue
            if default_doc[0] != default:
                msg = '`{}` (default {!r}) does not match docstring {!r}'
                errors.append(msg.format(param, default, default_doc[0]))
                del params[param]
                continue
            del params[param]

        for param in params:
            if (module_name, param) in IGNORE_ITEM:
                continue
            errors.append('{} in module docstring but not module'.format(param))
        if errors:
            all_errors += ['=' * 30, module_name, '=' * 30] + errors + ['\n']
    return all_errors