docs: def _construct_production_name(glyph_name, data=None):
      """Return the production name for a glyph name from the GlyphData.xml
      database according to the AGL specification.
  
      This should be run only if there is no official entry with a production
      name in it.
  
      Handles single glyphs (e.g. "brevecomb") and ligatures (e.g.
      "brevecomb_acutecomb"). Returns None when a valid and semantically
      meaningful production name can't be constructed or when the AGL
      specification would be violated, get_glyph() will use the bare glyph
      name then.
  
      Note:
      - Glyph name is the full name, e.g. "brevecomb_acutecomb.case".
      - Base name is the base part, e.g. "brevecomb_acutecomb"
      - Suffix is e.g. "case".
      """
  
      # At this point, we have already checked the data for the full glyph name, so
      # directly go to the base name here (e.g. when looking at "fi.alt").
      base_name, dot, suffix = glyph_name.partition(".")
      glyphinfo = _lookup_attributes(base_name, data)
      if glyphinfo and glyphinfo.get("production"):
          # Found the base glyph.
          return glyphinfo["production"] + dot + suffix
  
      if glyph_name in fontTools.agl.AGL2UV or base_name in fontTools.agl.AGL2UV:
          # Glyph name is actually an AGLFN name.
          return glyph_name
  
      if "_" not in base_name:
          # Nothing found so far and the glyph name isn't a ligature ("_"
          # somewhere in it). The name does not carry any discernable Unicode
          # semantics, so just return something sanitized.
          return _agl_compliant_name(glyph_name)
  
      # So we have a ligature that is not mapped in the data. Split it up and
      # look up the individual parts.
      base_name_parts = base_name.split("_")
  
      # If all parts are in the AGLFN list, the glyph name is our production
      # name already.
      if all(part in fontTools.agl.AGL2UV for part in base_name_parts):
          return _agl_compliant_name(glyph_name)
  
      # Turn all parts of the ligature into production names.
      _character_outside_BMP = False
      production_names = []
      for part in base_name_parts:
          if part in fontTools.agl.AGL2UV:
              # A name present in the AGLFN is a production name already.
              production_names.append(part)
          else:
              part_entry = data.names.get(part) or {}
              part_production_name = part_entry.get("production")
              if part_production_name:
                  production_names.append(part_production_name)
  
                  # Take note if there are any characters outside the Unicode
                  # BMP, e.g. "u10FFF" or "u10FFFF". Do not catch e.g. "u013B"
                  # though.
                  if len(part_production_name) > 5 and _is_unicode_u_value(
                      part_production_name
                  ):
                      _character_outside_BMP = True
              else:
                  # We hit a part that does not seem to be a valid glyph name known to us,
                  # so the entire glyph name can't carry Unicode meaning. Return it
                  # sanitized.
                  return _agl_compliant_name(glyph_name)
  
      # Some names Glyphs uses resolve to other names that are not uniXXXX names and may
      # contain dots (e.g. idotaccent -> i.loclTRK). If there is any name with a "." in
      # it before the last element, punt. We'd have to introduce a "." into the ligature
      # midway, which is invalid according to the AGL. Example: "a_i.loclTRK" is valid,
      # but "a_i.loclTRK_a" isn't.
      if any("." in part for part in production_names[:-1]):
          return _agl_compliant_name(glyph_name)
  
      # If any production name starts with a "uni" and there are none of the
      # "uXXXXX" format, try to turn all parts into "uni" names and concatenate
      # them.
      if not _character_outside_BMP and any(
          part.startswith("uni") for part in production_names
      ):
          uni_names = []
  
          for part in production_names:
              if part.startswith("uni"):
                  uni_names.append(part[3:])
              elif len(part) == 5 and _is_unicode_u_value(part):
                  uni_names.append(part[1:])
              elif part in fontTools.agl.AGL2UV:
                  uni_names.append("{:04X}".format(fontTools.agl.AGL2UV[part]))
              else:
                  return None
  
          final_production_name = "uni" + "".join(uni_names) + dot + suffix
      else:
          final_production_name = "_".join(production_names) + dot + suffix
  
      return _agl_compliant_name(final_production_name)