Exemple #1
0
def write_datatype_table(table_type='all', **kwargs):
    r"""Write a table containing entries from the descriptions of datatypes.

    Args:
        table_type (str, optional): Type of table that should be created for the
            class. Defaults to 'all'. Supported values include:

            * 'all': Create each type of table.
            * 'simple': Create a table of standard JSON datatypes.
            * 'container': Create a table of container datatypes.
            * 'yggdrasil': Create a table of yggdrasil specific datatypes.

        **kwargs: Additional keyword arguments are passed to dict2table and
            write_table.

    Returns:
        str, list: Name of file or files created.

    Raises:
        ValueError: If table_type is not one of the supported values.

    """
    from yggdrasil.metaschema.datatypes import _type_registry
    table_type_list = ['simple', 'container', 'yggdrasil']
    if table_type == 'all':
        fname = kwargs.get("fname", None)
        fname_base = kwargs.get("fname_base", None)
        assert ((fname is None) and (fname_base is None))
        out = []
        for k in table_type_list:
            out.append(write_datatype_table(table_type=k, **kwargs))
        return out
    elif table_type not in table_type_list:
        raise ValueError("Unsupported table_type: '%s'" % table_type)
    fname_format = 'datatype_table_%s.rst'
    kwargs.setdefault('fname_base', fname_format % (table_type))
    target_types = []
    args = {}
    if table_type == 'simple':
        for k, v in _type_registry.items():
            if v._replaces_existing and (not hasattr(v, '_container_type')):
                target_types.append(k)
    elif table_type == 'container':
        for k, v in _type_registry.items():
            if v._replaces_existing and hasattr(v, '_container_type'):
                target_types.append(k)
    elif table_type == 'yggdrasil':
        for k, v in _type_registry.items():
            if not v._replaces_existing:
                target_types.append(k)
    for k in target_types:
        v = _type_registry[k]
        args[k] = {
            'description': v.description,
            'required properties': v.definition_properties
        }
    kwargs.setdefault('key_column_name', 'type')
    kwargs.setdefault('list_columns', 'required properties')
    lines = dict2table(args, **kwargs)
    return write_table(lines, **kwargs)
Exemple #2
0
def write_datatype_mapping_table(**kwargs):
    r"""Write a table containing mapping of datatypes between different
    languages.

    Args:
        **kwargs: Additional keyword arguments are passed to dict2table and
            write_table.

    Returns:
        str, list: Name of file or files created.

    """
    from yggdrasil import tools, components
    from yggdrasil.metaschema.datatypes import _type_registry
    kwargs.setdefault('fname_base', 'datatype_mapping_table.rst')
    args = {}
    for k, v in _type_registry.items():
        if v.cross_language_support:
            args[k] = {
                'notes':
                get_docs_section(
                    v.__doc__,
                    keys=['Developer Notes:', 'Development Notes:'],
                    join_lines=True)
            }
    for lang in tools.get_supported_lang():
        if lang in ['lpy', 'make', 'cmake', 'executable']:
            continue
        if lang == 'cpp':
            lang = 'c++'
        ldrv = components.import_component('model', lang)
        if not ldrv.full_language:
            continue
        for k in args.keys():
            entry = ldrv.type_map.get(k, '')
            if entry:
                args[k][lang] = '``%s``' % entry
            else:
                args[k][lang] = ''
    kwargs.setdefault('key_column_name', 'schema')
    kwargs.setdefault('val_column_name', 'notes')
    kwargs.setdefault('prune_empty_columns', False)
    kwargs.setdefault('last_column', 'notes')
    # kwargs.setdefault('column_order', ['schema', 'notes'])
    kwargs.setdefault('wrapped_columns', {'notes': 40})
    lines = dict2table(args, **kwargs)
    return write_table(lines, **kwargs)