code: def ufo2glyphs(options):
      
      import fontTools.designspaceLib
      import defcon
  
      sources = options.designspace_file_or_UFOs
      designspace_file = None
      if (
          len(sources) == 1
          and sources[0].endswith(".designspace")
          and os.path.isfile(sources[0])
      ):
          designspace_file = sources[0]
          designspace = fontTools.designspaceLib.DesignSpaceDocument()
          designspace.read(designspace_file)
          object_to_read = designspace
      elif all(source.endswith(".ufo") and os.path.isdir(source) for source in sources):
          ufos = [defcon.Font(source) for source in sources]
          ufos.sort(
              key=lambda ufo: [  # Order the masters by weight and width
                  ufo.info.openTypeOS2WeightClass or 400,
                  ufo.info.openTypeOS2WidthClass or 5,
              ]
          )
          object_to_read = ufos
      else:
          print(
              "Please specify just one designspace file *or* one or more "
              "UFOs. They must end in '.designspace' or '.ufo', respectively.",
              file=sys.stderr,
          )
          return 1
  
      font = glyphsLib.to_glyphs(
          object_to_read, minimize_ufo_diffs=options.no_preserve_glyphsapp_metadata
      )
  
      # Make the Glyphs file more suitable for roundtrip:
      font.customParameters["Disable Last Change"] = options.enable_last_change
      font.disablesAutomaticAlignment = options.enable_automatic_alignment
  
      if options.output_path:
          font.save(options.output_path)
      else:
          if designspace_file:
              filename_to_write = os.path.splitext(designspace_file)[0] + ".glyphs"
          else:
              filename_to_write = os.path.join(
                  os.path.dirname(sources[0]),
                  font.familyName.replace(" ", "") + ".glyphs",
              )
          font.save(filename_to_write)
docs: Convert one designspace file or one or more UFOs to a Glyphs.app source file.