googlefonts/ufo2ft

DottedCircleFilter module misnamed?

madig opened this issue · 3 comments

madig commented

Doing

<key>com.github.googlei18n.ufo2ft.filters</key>
<array>
<dict>
<key>name</key>
<string>DottedCircleFilter</string>
<key>pre</key>
<true/>
</dict>
</array>
results in this error:

ERROR:ufo2ft.filters:Failed to load filter: {'name': 'DottedCircleFilter', 'pre': True}
Traceback (most recent call last):
  File "/home/nikolaus/googlesans-flex/venv/lib/python3.11/site-packages/ufo2ft/filters/__init__.py", line 64, in loadFilters
    filterClass = getFilterClass(filterDict["name"], namespace)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nikolaus/googlesans-flex/venv/lib/python3.11/site-packages/ufo2ft/filters/__init__.py", line 52, in getFilterClass
    return getattr(module, className)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'ufo2ft.filters.dottedCircleFilter' has no attribute 'DottedCircleFilterFilter'

I suppose the module is misnamed and should lose the Filter part?

you mean the class name is misnamed

# if filter name is 'Foo Bar', the module should be called 'fooBar'
filterName = filterName.replace(" ", "")
moduleName = filterName[0].lower() + filterName[1:]
module = importlib.import_module(".".join([pkg, moduleName]))
# if filter name is 'Foo Bar', the class should be called 'FooBarFilter'
className = filterName[0].upper() + filterName[1:] + "Filter"

the name in the lib's filter should be "DottedCircle" (or even "Dotted Circle" or "dottedCircle" would work).
We can fix that function to not append "Filter" suffix if it's already there if you like

this naming convention was to be able to map from Glyphs.app's sort of filters ("Remove Overlaps", "Transformations", etc.)

madig commented

Hm yes, at least avoiding stuff like FooFilterFilter would make sense.