Export subsetted font with manual Classes/Features

I’m attempting to use Keep Glyphs for exporting a script subsets from a glyph file.
Since wildcard now supports script=None, exporting a script subset has become much easier, but this causes a problem with Features.

I’m wondering if Keep Glyphs could also:

  1. Disable classes that lack any of their specified glyphs in the parameters.

For instance, if I have a class @GreekLowercase, but none of the class glyphs are present in my “Keep Glyphs” CP, it would be useful to automatically disable it at export, to avoid errors like:

Unknown glyph "alpha"
Found in class 'GreekLowercase', line 1
  1. In OT Features not generated automatically, remove a substitution line if any of the involved glyphs/classes are not included in the export.

Actually, it works for features generated automatically, but if I have a manually written .ss01 like:

sub a by a.ss01
sub alpha by alpha.ss01

It would be nice to have an internal script that goes through the code of the feature, checks each line to ensure all glyphs are present in the subsetted font, and if not, removes this line at export.

I understand it’s likely more complex, but here is a very draft code :

# MenuTitle: Update Classes and OpenType Feature based on Exported Glyphs
# -*- coding: utf-8 -*-

print(f"Update Classes\n{'-'*30}")

# Create a list of glyph names that are not exported
glyph_not_exported = [glyph.name for glyph in Font.glyphs if not glyph.export]

# Iterate over each class in the font
for classe in Font.classes:
    # Split the class code into a list of glyphs
    classe_glyphs = classe.code.split()

    # Prepare a new list for glyphs that will remain in the class
    updated_classe_glyphs = []

    # Check each glyph in the class
    for glyph in classe_glyphs:
        # If the glyph is not in the non-exported list, add it to the updated list
        if glyph not in glyph_not_exported:
            updated_classe_glyphs.append(glyph)

    # Check if there are any glyphs left in the class after removal
    if updated_classe_glyphs:
        updated_classe_code = ' '.join(updated_classe_glyphs)
        print(f"{classe.name} Class 🔄 : {updated_classe_code}")
        # classe.code = updated_classe_code
    else:
        print(f"{classe.name} Class 🚫")
        # classe.active = False


print("\nUpdate OpenType Features\n" + '-'*30)

for feature in Font.features:
    # Split the feature code into lines and prepare a list for lines to be removed
    code_lines = feature.code.splitlines()
    lines_to_remove = []

    # Iterate over each line and check for glyphs that should not be exported
    for line in code_lines:
        # Remove semicolons and split line into parts
        line_parts = [part.replace(";", "") for part in line.split()]

        # Check if any non-exported glyph is in the line parts
        if any(glyph in line_parts for glyph in glyph_not_exported):
            lines_to_remove.append(line)

    # Update the feature code by removing the identified lines
    if lines_to_remove:
        print(f"{feature.name} has been updated. The following lines have been removed:")
        for line in lines_to_remove:
            print(f"\t{line}")

        # Remove identified lines from the code
        new_code = '\n'.join(set(code_lines) - set(lines_to_remove))
        # Update the feature code
        # feature.code = new_code