def main():
    path = "/tmp/docs.json"
    source_path = join(os.curdir, 'provy', 'more')

    if not exists(dirname(path)):
        os.makedirs(dirname(path))

    root_namespace = 'provy.more'

    roles_to_document = {
        'Role': RoleDoc(Role, 'Role', 'provy.core.roles', Role.__doc__)
    }

    for root, dirs, files in os.walk(source_path):
        for file_name in files:
            if file_name == "__init__.py":
                continue
            if not fnmatch.fnmatch(file_name, '*.py'):
                continue

            module_path = '%s.%s.%s' % (root_namespace,
                                        get_namespace_for(root),
                                        splitext(file_name)[0])

            module = import_module(module_path)

            for name, member in inspect.getmembers(module):
                if not inspect.isclass(member) or not issubclass(member, Role):
                    continue
                if member.__module__ != module_path:
                    continue

                if not member.__doc__:
                    print "Warning: Role %s.%s does not have docstring." % (member.__module__, name)

                roles_to_document[module_path] = RoleDoc(member,
                                                         name,
                                                         member.__module__,
                                                         member.__doc__)

    tree = {}

    for full_name, role_doc in roles_to_document.iteritems():
        role = role_doc.role
        name = role_doc.name
        current = tree
        module = __import__(role.__module__)
        for part in role.__module__.split('.'):
            if hasattr(module, part):
                module = getattr(module, part)
            if not part in current:
                if not module.__doc__:
                    print module.__name__ % "Warning: Module %s does not have docstring."

                current[part] = {
                    '__name__': module.__name__,
                    '__doc__': module.__doc__ and module.__doc__.strip() or None
                }
            if part == role.__module__.split('.')[-1]:
                current[part][role_doc.name] = role_doc.to_dict()
            current = current[part]

    contents = dumps(tree, sort_keys=True, separators=(',', ':'))
    with open(path, 'w') as f:
        f.write(contents)
dataset/ETHPy150Open python-provy/provy/docs.py/main/swapped operands of `%`