import inspect

from .random import random
from .circular import circular
from .force_directed import fruchterman_reingold


_layout_map = {
    'random': random,
    'circular': circular,
    'force_directed': fruchterman_reingold,
    'spring_layout': fruchterman_reingold
}

AVAILABLE_LAYOUTS = _layout_map.keys()


def get_layout(name, *args, **kwargs):
    """
    Retrieve a graph layout

    Some graph layouts accept extra options. Please refer to their
    documentation for more information.

    Parameters
    ----------
    name : string
        The name of the layout. The variable `AVAILABLE_LAYOUTS`
        contains all available layouts.
    *args
        Positional arguments which are passed to the layout.
    **kwargs
        Keyword arguments which are passed to the layout.

    Returns
    -------
    layout : callable
        The callable generator which will calculate the graph layout
    """
    if name not in _layout_map:
        raise KeyError(
            "Graph layout '{}' not found. Should be one of {}".format(
                name, ", ".join(AVAILABLE_LAYOUTS)
            )
        )

    layout = _layout_map[name]

    if inspect.isclass(layout):
        layout = layout(*args, **kwargs)

    return layout

import inspect

from .random import random
from .circular import circular
from .force_directed import fruchterman_reingold


_layout_map = {
    'random': random,
    'circular': circular,
    'force_directed': fruchterman_reingold,
    'spring_layout': fruchterman_reingold
}

AVAILABLE_LAYOUTS = tuple(_layout_map.keys())


def get_layout(name, *args, **kwargs):
    """
    Retrieve a graph layout

    Some graph layouts accept extra options. Please refer to their
    documentation for more information.

    Parameters
    ----------
    name : string
        The name of the layout. The variable `AVAILABLE_LAYOUTS`
        contains all available layouts.
    *args
        Positional arguments which are passed to the layout.
    **kwargs
        Keyword arguments which are passed to the layout.

    Returns
    -------
    layout : callable
        The callable generator which will calculate the graph layout
    """
    if name not in _layout_map:
        raise KeyError(
            "Graph layout '{}' not found. Should be one of {}".format(
                name, ", ".join(AVAILABLE_LAYOUTS)
            )
        )

    layout = _layout_map[name]

    if inspect.isclass(layout):
        layout = layout(*args, **kwargs)

    return layout

Make sure AVAILABLE_LAYOUTS is a tuple
Make sure AVAILABLE_LAYOUTS is a tuple

The .keys() function is a generator in Python 3.
