def loadFeatureWriterFromString(spec):
    """ Take a string specifying a feature writer class to load (either a
    built-in writer or one defined in an external, user-defined module),
    initialize it with given options and return the writer object.

    The string must conform to the following notation:
    - an optional python module, followed by '::'
    - a required class name; the class must have a method call 'write'
      with the same signature as the BaseFeatureWriter.
    - an optional list of keyword-only arguments enclosed by parentheses

    Raises ValueError if the string doesn't conform to this specification;
    TypeError if imported name is not a feature writer class; and
    ImportError if the user-defined module cannot be imported.

    Examples:

    >>> loadFeatureWriterFromString("KernFeatureWriter")
    <ufo2ft.featureWriters.kernFeatureWriter.KernFeatureWriter object at ...>
    >>> w = loadFeatureWriterFromString("KernFeatureWriter(ignoreMarks=False)")
    >>> w.options.ignoreMarks
    False
    >>> w = loadFeatureWriterFromString("MarkFeatureWriter(features=['mkmk'])")
    >>> w.features == frozenset(['mkmk'])
    True
    >>> loadFeatureWriterFromString("ufo2ft.featureWriters::KernFeatureWriter")
    <ufo2ft.featureWriters.kernFeatureWriter.KernFeatureWriter object at ...>
    """
    spec = spec.strip()
    m = _featureWriterSpecRE.match(spec)
    if not m or (m.end() - m.start()) != len(spec):
        raise ValueError(spec)
    moduleName = m.group(1) or "ufo2ft.featureWriters"
    className = m.group(2)
    kwargs = m.group(3)

    module = importlib.import_module(moduleName)
    klass = getattr(module, className)
    if not isValidFeatureWriter(klass):
        raise TypeError(klass)
    try:
        options = _kwargsEval(kwargs) if kwargs else {}
    except SyntaxError:
        raise ValueError("options have incorrect format: %r" % kwargs)
    return klass(**options)