loadFonts / logger issue with 1.13.2
I encountered an issue with ufoOperator when I started using a virtual environment and installed the package via pip. Previously, the script ran without problems outside the venv. It appears I was using ufoProcessor 1.13.1. With version 1.13.2, I'm not exactly sure what the problem is, but I received errors concerning loadFonts and logger. The problem disappeared after I downgraded back to version 1.13.1.
Here's an example of the error I was getting.
File "/Users/Ryan/Documents/Git/private/[redacted]/make_superiors.py", line 92, in make_one_glyph
interp_g = ds.makeOneGlyph(g_name, location, decomposeComponents=True, useVarlib=False, roundGeometry=False, clip=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Ryan/Documents/Git/private/[redacted]/.venv/lib/python3.11/site-packages/ufoProcessor/ufoOperator.py", line 115, in wrapper
result = function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Ryan/Documents/Git/private/[redacted]/.venv/lib/python3.11/site-packages/ufoProcessor/ufoOperator.py", line 1589, in makeOneGlyph
self.loadFonts()
File "/Users/Ryan/Documents/Git/private/[redacted]/.venv/lib/python3.11/site-packages/ufoProcessor/ufoOperator.py", line 409, in loadFonts
self.logger.info("## loadFonts")
^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'info'
Hm. It doesn't have a logger when it expects one. In your code, could it be the debug attribute is set to True some point after initialisation?
A logger is created when debug is set at initialisation of the UFOProcessor. If debug is False, there is no logger. In a scripted context the UFOProcessor could be created by DSE or something else. So we can't set debug. What to do.
I suppose loadFonts is a good place to check if we have a logger after all and initialise one. Because not much can happen without the fonts.
https://github.com/LettError/ufoProcessor/tree/issue_68
Alternatively, ds.debug could get a setter method which then can start the logger if there isn't one.
As a workaround, before this gets to a RF near you, if this is a scripted context, you can call ds.startLog() before calling ds.makeOneGlyph()
Alternative workaround, DSE could start the logger on a UFOProcessor that gets handed to a script.
Thanks for looking at this! Woops, it looks like I did have a debug = True line in the code. I forget why I decided to add it there at one point.
A simplified version of the code I was running:
from ufoProcessor.ufoOperator import UFOOperator
from fontParts.world import OpenFont, RFont, RGlyph
def make_one_glyph(ds, g_name, location):
g = RGlyph()
ds.debug = True # Maybe it wasn't working at some point and then I decided to add this line?
interp_g = ds.makeOneGlyph(g_name, location, decomposeComponents=True, useVarlib=False, roundGeometry=False, clip=False)
if interp_g:
g.fromMathGlyph(interp_g, filterRedundantPoints=True)
g.width = interp_g.width
return g
ds_paths = ['/path/to.designspace']
for ds_path in ds_paths:
ds = UFOOperator(ufoVersion=3, useVarlib=False)
ds.read(ds_path)
# Good time to load fonts?
ds.loadFonts()
for source in ds.sources:
source_f = OpenFont(source.path, showInterface=False)
location = source.getFullDesignLocation(ds)
g = make_one_glyph(ds, "H", location)
This script works with the new release.
Thank you!
Thanks for the test!