Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadFonts / logger issue with 1.13.2 #68

Open
ryanbugden opened this issue Dec 6, 2024 · 9 comments
Open

loadFonts / logger issue with 1.13.2 #68

ryanbugden opened this issue Dec 6, 2024 · 9 comments

Comments

@ryanbugden
Copy link

ryanbugden commented Dec 6, 2024

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'
@LettError
Copy link
Owner

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.

@LettError
Copy link
Owner

@LettError
Copy link
Owner

Alternatively, ds.debug could get a setter method which then can start the logger if there isn't one.

@LettError
Copy link
Owner

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()

@LettError
Copy link
Owner

Alternative workaround, DSE could start the logger on a UFOProcessor that gets handed to a script.

@ryanbugden
Copy link
Author

ryanbugden commented Dec 7, 2024

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)

@LettError
Copy link
Owner

This script works with the new release.

@ryanbugden
Copy link
Author

Thank you!

@LettError
Copy link
Owner

Thanks for the test!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants