def _build_custom_contracts():
    """
    Define some custom contracts if PyContracts is found
    """
    from contracts import new_contract

    @new_contract
    def cid_like(value):
        """
        Value is a ComponentID or a string
        """
        from glue.core import ComponentID
        return isinstance(value, (ComponentID, string_types))

    @new_contract
    def component_like(value):
        from glue.core import Component, ComponentLink
        return isinstance(value, (Component, ComponentLink,
                                  ndarray, list, Series))

    @new_contract
    def array_like(value):
        return isinstance(value, (ndarray, list))

    @new_contract
    def color(value):
        """
        A valid matplotlib color
        """
        from matplotlib.colors import colorConverter
        try:
            colorConverter.to_rgba(value)
        except __HOLE__:
            return False

    @new_contract
    def inst(value, *types):
        return isinstance(value, types)

    @new_contract
    def data_view(value):
        from glue.core import ComponentID

        if value is None:
            return
        if isinstance(value, ComponentID):
            return
        try:
            if not isinstance(value[0], ComponentID):
                return False
            s_[value[1:]]
        except:
            return False

    @new_contract
    def array_view(value):
        try:
            s_[value]
        except:
            return False

    @new_contract
    def callable(value):
        return hasattr(value, '__call__')
dataset/ETHPy150Open glue-viz/glue/glue/core/contracts.py/_build_custom_contracts