def build_masters(<EOL>filename,<EOL>master_dir,<EOL>designspace_instance_dir=None,<EOL>designspace_path=None,<EOL>family_name=None,<EOL>propagate_anchors=True,<EOL>minimize_glyphs_diffs=False,<EOL>normalize_ufos=False,<EOL>create_background_layers=False,<EOL>generate_GDEF=True,<EOL>store_editor_state=True,<EOL>):
font = GSFont(filename)<EOL>if not os.path.isdir(master_dir):<EOL><INDENT>os.mkdir(master_dir)<EOL><DEDENT>if designspace_instance_dir is None:<EOL><INDENT>instance_dir = None<EOL><DEDENT>else:<EOL><INDENT>instance_dir = os.path.relpath(designspace_instance_dir, master_dir)<EOL><DEDENT>designspace = to_designspace(<EOL>font,<EOL>family_name=family_name,<EOL>propagate_anchors=propagate_anchors,<EOL>instance_dir=instance_dir,<EOL>minimize_glyphs_diffs=minimize_glyphs_diffs,<EOL>generate_GDEF=generate_GDEF,<EOL>store_editor_state=store_editor_state,<EOL>)<EOL>ufos = {}<EOL>for source in designspace.sources:<EOL><INDENT>if source.filename in ufos:<EOL><INDENT>assert source.font is ufos[source.filename]<EOL>continue<EOL><DEDENT>if create_background_layers:<EOL><INDENT>ufo_create_background_layer_for_all_glyphs(source.font)<EOL><DEDENT>ufo_path = os.path.join(master_dir, source.filename)<EOL>clean_ufo(ufo_path)<EOL>source.font.save(ufo_path)<EOL>if normalize_ufos:<EOL><INDENT>import ufonormalizer<EOL>ufonormalizer.normalizeUFO(ufo_path, writeModTimes=False)<EOL><DEDENT>ufos[source.filename] = source.font<EOL><DEDENT>if not designspace_path:<EOL><INDENT>designspace_path = os.path.join(master_dir, designspace.filename)<EOL><DEDENT>designspace.write(designspace_path)<EOL>return Masters(ufos, designspace_path)<EOL>
Write and return UFOs from the masters and the designspace defined in a
    .glyphs file.

    Args:
        master_dir: Directory where masters are written.
        designspace_instance_dir: If provided, a designspace document will be
            written alongside the master UFOs though no instances will be built.
        family_name: If provided, the master UFOs will be given this name and
            only instances with this name will be included in the designspace.

    Returns:
        A named tuple of master UFOs (`ufos`) and the path to the designspace
        file (`designspace_path`).