code: def build(
      designspace,
      master_finder=lambda s: s,
      exclude=[],
      optimize=True,
      colr_layer_reuse=True,
      drop_implied_oncurves=False,
  ):
      """
      Build variation font from a designspace file.
  
      If master_finder is set, it should be a callable that takes master
      filename as found in designspace file and map it to master font
      binary as to be opened (eg. .ttf or .otf).
      """
      if hasattr(
          designspace, "sources"
      ):  # Assume a DesignspaceDocument
          pass
      else:  # Assume a file path
          designspace = DesignSpaceDocument.fromfile(designspace)
  
      ds = load_designspace(designspace)
      log.info("Building variable font")
  
      log.info("Loading master fonts")
      master_fonts = load_masters(designspace, master_finder)
  
      # TODO: 'master_ttfs' is unused except for return value, remove later
      master_ttfs = []
      for master in master_fonts:
          try:
              master_ttfs.append(master.reader.file.name)
          except AttributeError:
              master_ttfs.append(None)  # in-memory fonts have no path
  
      if drop_implied_oncurves and "glyf" in master_fonts[ds.base_idx]:
          drop_count = drop_implied_oncurve_points(*master_fonts)
          log.info(
              "Dropped %s on-curve points from simple glyphs in the 'glyf' table",
              drop_count,
          )
  
      # Copy the base master to work from it
      vf = deepcopy(master_fonts[ds.base_idx])
  
      if "DSIG" in vf:
          del vf["DSIG"]
  
      # TODO append masters as named-instances as well; needs .designspace change.
      fvar = _add_fvar(vf, ds.axes, ds.instances)
      if "STAT" not in exclude:
          _add_stat(vf)
  
      # Map from axis names to axis tags...
      normalized_master_locs = [
          {ds.axes[k].tag: v for k, v in loc.items()}
          for loc in ds.normalized_master_locs
      ]
      # From here on, we use fvar axes only
      axisTags = [axis.axisTag for axis in fvar.axes]
  
      # Assume single-model for now.
      model = models.VariationModel(
          normalized_master_locs, axisOrder=axisTags
      )
      assert 0 == model.mapping[ds.base_idx]
  
      log.info("Building variations tables")
      if "avar" not in exclude:
          _add_avar(vf, ds.axes, ds.axisMappings, axisTags)
      if "BASE" not in exclude and "BASE" in vf:
          _add_BASE(vf, model, master_fonts, axisTags)
      if "MVAR" not in exclude:
          _add_MVAR(vf, model, master_fonts, axisTags)
      if "HVAR" not in exclude:
          _add_HVAR(vf, model, master_fonts, axisTags)
      if "VVAR" not in exclude and "vmtx" in vf:
          _add_VVAR(vf, model, master_fonts, axisTags)
      if "GDEF" not in exclude or "GPOS" not in exclude:
          _merge_OTL(vf, model, master_fonts, axisTags)
      if "gvar" not in exclude and "glyf" in vf:
          _add_gvar(vf, model, master_fonts, optimize=optimize)
      if "cvar" not in exclude and "glyf" in vf:
          _merge_TTHinting(vf, model, master_fonts)
      if "GSUB" not in exclude and ds.rules:
          featureTags = _feature_variations_tags(ds)
          _add_GSUB_feature_variations(
              vf,
              ds.axes,
              ds.internal_axis_supports,
              ds.rules,
              featureTags,
          )
      if "CFF2" not in exclude and ("CFF " in vf or "CFF2" in vf):
          _add_CFF2(vf, model, master_fonts)
          if "post" in vf:
              # set 'post' to format 2 to keep the glyph names dropped from CFF2
              post = vf["post"]
              if post.formatType != 2.0:
                  post.formatType = 2.0
                  post.extraNames = []
                  post.mapping = {}
      if (
          "COLR" not in exclude
          and "COLR" in vf
          and vf["COLR"].version > 0
      ):
          _add_COLR(vf, model, master_fonts, axisTags, colr_layer_reuse)
  
      set_default_weight_width_slant(
          vf,
          location={
              axis.axisTag: axis.defaultValue
              for axis in vf["fvar"].axes
          },
      )
  
      for tag in exclude:
          if tag in vf:
              del vf[tag]
  
      # TODO: Only return vf for 4.0+, the rest is unused.
      return vf, model, master_ttfs
  
imports: from typing import List
  from fontTools.misc.vector import Vector
  from fontTools.misc.roundTools import noRound, otRound
  from fontTools.misc.fixedTools import floatToFixed
  from fontTools.misc.textTools import Tag, tostr
  from fontTools.ttLib import TTFont, newTable
  from fontTools.ttLib.tables._f_v_a_r import Axis, NamedInstance
  from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates, dropImpliedOnCurvePoints
  from fontTools.ttLib.tables.ttProgram import Program
  from fontTools.ttLib.tables.TupleVariation import TupleVariation
  from fontTools.ttLib.tables import otTables
  from fontTools.ttLib.tables.otBase import OTTableWriter
  from fontTools.varLib import builder, models, varStore
  from fontTools.varLib.merger import VariationMerger, COLRVariationMerger
  from fontTools.varLib.mvar import MVAR_ENTRIES
  from fontTools.varLib.iup import iup_delta_optimize
  from fontTools.varLib.featureVars import addFeatureVariations
  from fontTools.designspaceLib import DesignSpaceDocument, InstanceDescriptor
  from fontTools.designspaceLib.split import splitInterpolable, splitVariableFonts
  from fontTools.varLib.stat import buildVFStatTable
  from fontTools.colorLib.builder import buildColrV1
  from fontTools.colorLib.unbuilder import unbuildColrV1
  from functools import partial
  from collections import OrderedDict, defaultdict, namedtuple
  import os.path
  import logging
  from copy import deepcopy
  from pprint import pformat
  from re import fullmatch
  from .errors import VarLibError, VarLibValidationError
label_desc: Use image node_id 21 for calling a global function with example usage: build(designspace, master_finder, exclude, optimize, colr_layer_reuse, drop_implied_oncurves) and returns: vf,  model,  master_ttfs