code: def main(args=None):
      """Build variable fonts from a designspace file and masters"""
      from argparse import ArgumentParser
      from fontTools import configLogger
  
      parser = ArgumentParser(prog="varLib", description=main.__doc__)
      parser.add_argument("designspace")
      output_group = parser.add_mutually_exclusive_group()
      output_group.add_argument(
          "-o",
          metavar="OUTPUTFILE",
          dest="outfile",
          default=None,
          help="output file",
      )
      output_group.add_argument(
          "-d",
          "--output-dir",
          metavar="OUTPUTDIR",
          default=None,
          help="output dir (default: same as input designspace file)",
      )
      parser.add_argument(
          "-x",
          metavar="TAG",
          dest="exclude",
          action="append",
          default=[],
          help="exclude table",
      )
      parser.add_argument(
          "--disable-iup",
          dest="optimize",
          action="store_false",
          help="do not perform IUP optimization",
      )
      parser.add_argument(
          "--no-colr-layer-reuse",
          dest="colr_layer_reuse",
          action="store_false",
          help="do not rebuild variable COLR table to optimize COLR layer reuse",
      )
      parser.add_argument(
          "--drop-implied-oncurves",
          action="store_true",
          help=(
              "drop on-curve points that can be implied when exactly in the middle of "
              "two off-curve points (only applies to TrueType fonts)"
          ),
      )
      parser.add_argument(
          "--master-finder",
          default="master_ttf_interpolatable/{stem}.ttf",
          help=(
              "templated string used for finding binary font "
              "files given the source file names defined in the "
              "designspace document. The following special strings "
              "are defined: {fullname} is the absolute source file "
              "name; {basename} is the file name without its "
              "directory; {stem} is the basename without the file "
              "extension; {ext} is the source file extension; "
              "{dirname} is the directory of the absolute file "
              'name. The default value is "%(default)s".'
          ),
      )
      parser.add_argument(
          "--variable-fonts",
          default=".*",
          metavar="VF_NAME",
          help=(
              "Filter the list of variable fonts produced from the input "
              "Designspace v5 file. By default all listed variable fonts are "
              "generated. To generate a specific variable font (or variable fonts) "
              'that match a given "name" attribute, you can pass as argument '
              "the full name or a regular expression. E.g.: --variable-fonts "
              '"MyFontVF_WeightOnly"; or --variable-fonts "MyFontVFItalic_.*".'
          ),
      )
      logging_group = parser.add_mutually_exclusive_group(
          required=False
      )
      logging_group.add_argument(
          "-v",
          "--verbose",
          action="store_true",
          help="Run more verbosely.",
      )
      logging_group.add_argument(
          "-q",
          "--quiet",
          action="store_true",
          help="Turn verbosity off.",
      )
      options = parser.parse_args(args)
  
      configLogger(
          level=(
              "DEBUG"
              if options.verbose
              else "ERROR"
              if options.quiet
              else "INFO"
          )
      )
  
      designspace_filename = options.designspace
      designspace = DesignSpaceDocument.fromfile(designspace_filename)
  
      vf_descriptors = designspace.getVariableFonts()
      if not vf_descriptors:
          parser.error(
              f"No variable fonts in given designspace {designspace.path!r}"
          )
  
      vfs_to_build = []
      for vf in vf_descriptors:
          # Skip variable fonts that do not match the user's inclusion regex if given.
          if not fullmatch(options.variable_fonts, vf.name):
              continue
          vfs_to_build.append(vf)
  
      if not vfs_to_build:
          parser.error(
              f"No variable fonts matching {options.variable_fonts!r}"
          )
  
      if options.outfile is not None and len(vfs_to_build) > 1:
          parser.error(
              "can't specify -o because there are multiple VFs to build; "
              "use --output-dir, or select a single VF with --variable-fonts"
          )
  
      output_dir = options.output_dir
      if output_dir is None:
          output_dir = os.path.dirname(designspace_filename)
  
      vf_name_to_output_path = {}
      if len(vfs_to_build) == 1 and options.outfile is not None:
          vf_name_to_output_path[vfs_to_build[0].name] = options.outfile
      else:
          for vf in vfs_to_build:
              filename = (
                  vf.filename
                  if vf.filename is not None
                  else vf.name + ".{ext}"
              )
              vf_name_to_output_path[vf.name] = os.path.join(
                  output_dir, filename
              )
  
      finder = MasterFinder(options.master_finder)
  
      vfs = build_many(
          designspace,
          finder,
          exclude=options.exclude,
          optimize=options.optimize,
          colr_layer_reuse=options.colr_layer_reuse,
          drop_implied_oncurves=options.drop_implied_oncurves,
      )
  
      for vf_name, vf in vfs.items():
          ext = "otf" if vf.sfntVersion == "OTTO" else "ttf"
          output_path = vf_name_to_output_path[vf_name].format(ext=ext)
          output_dir = os.path.dirname(output_path)
          if output_dir:
              os.makedirs(output_dir, exist_ok=True)
          log.info("Saving variation font %s", output_path)
          vf.save(output_path)
  
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 26 for calling a global function with example usage: main(args) without return types