Traceback with nested “UFO Filename” custom parameter
frankrolf opened this issue · 0 comments
frankrolf commented
I have a .glyphs source, in which the UFO Filename custom parameter is nested, like this:
name = "UFO Filename";
value = "master_0/Dummy-Roman_6ptRg.ufo";
This setup causes a Traceback:
Traceback (most recent call last):
File "bin/glyphs2ufo", line 8, in <module>
sys.exit(_glyphs2ufo_entry_point())
File "lib/python3.10/site-packages/glyphsLib/cli.py", line 276, in _glyphs2ufo_entry_point
return main(args)
File "lib/python3.10/site-packages/glyphsLib/cli.py", line 234, in main
return options.func(options)
File "lib/python3.10/site-packages/glyphsLib/cli.py", line 253, in glyphs2ufo
glyphsLib.build_masters(
File "lib/python3.10/site-packages/glyphsLib/__init__.py", line 152, in build_masters
source.font.save(ufo_path)
File "lib/python3.10/site-packages/ufoLib2/objects/font.py", line 592, in save
with UFOWriter(path, structure=structure, validate=validate) as writer:
File "lib/python3.10/site-packages/fontTools/ufoLib/__init__.py", line 948, in __init__
raise UFOLibError(
fontTools.ufoLib.errors.UFOLibError: Cannot write to 'master_0/Dummy-Roman_6ptRg.ufo': directory does not exist
I don’t know how you’d prefer to solve this, but I did this quick-and-dirty fix just before https://github.com/googlefonts/glyphsLib/blob/main/Lib/glyphsLib/__init__.py#L151:
ufo_path = os.path.join(master_dir, source.filename)
clean_ufo(ufo_path)
# nested dir:
ufo_subdirs = os.path.dirname(ufo_path)
if not os.path.exists(ufo_subdirs):
os.makedirs(ufo_subdirs)
source.font.save(ufo_path)
Possibly brittle, but fixes the problem on my end.