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

glyph_data has contradictory types #1019

Closed
simoncozens opened this issue Aug 15, 2024 · 4 comments · Fixed by #1020
Closed

glyph_data has contradictory types #1019

simoncozens opened this issue Aug 15, 2024 · 4 comments · Fixed by #1020

Comments

@simoncozens
Copy link
Collaborator

glyphsLib.builder.to_ufos takes a glyph_data parameter which is (a) passed to preflight_glyphs, and (b) passed to UFOBuilder.

In preflight_glyphs, glyph_data is interpreted as:

glyph_data: an optional GlyphData object associating various properties to
glyph names (e.g. category) that overrides the default one

So it's a GlyphData object. However, in UFOBuilder, it is described as

glyph_data -- A list of GlyphData.

What does that mean?

if glyph_data:
from io import BytesIO
glyphdata_files = []
for path in glyph_data:
with open(path, "rb") as fp:
glyphdata_files.append(BytesIO(fp.read()))
self.glyphdata = glyphdata.GlyphData.from_files(*glyphdata_files)

Oh, it's a list of paths.

It's historically been a list of paths, but now if you pass a list of paths, preflight_glyphs crashes because it's expecting a GlyphData object:

  File "/Users/simon/work/noto/math/venv/lib/python3.12/site-packages/glyphsLib/builder/transformations/propagate_anchors.py", line 67, in propagate_all_anchors_impl
    anchors = anchors_traversing_components(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/work/noto/math/venv/lib/python3.12/site-packages/glyphsLib/builder/transformations/propagate_anchors.py", line 157, in anchors_traversing_components
    if layer.anchors and _get_category(glyph, glyph_data) == "Mark":
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/work/noto/math/venv/lib/python3.12/site-packages/glyphsLib/builder/transformations/propagate_anchors.py", line 113, in _get_category
    or glyphdata.get_glyph(
       ^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/work/noto/math/venv/lib/python3.12/site-packages/glyphsLib/glyphdata.py", line 121, in get_glyph
    attributes = _lookup_attributes(glyph_name, data)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/work/noto/math/venv/lib/python3.12/site-packages/glyphsLib/glyphdata.py", line 164, in _lookup_attributes
    data.names.get(glyph_name)
    ^^^^^^^^^^
AttributeError: 'list' object has no attribute 'names'
@anthrotype
Copy link
Member

ouch, my bad.
I think we should avoid re-parsing it twice; if it's a list of str, interpret as paths as before, if it's already a GlyphData object, use as is

@anthrotype
Copy link
Member

@simoncozens let me know if you are working on a fix already, so we don't duplicate work

@simoncozens
Copy link
Collaborator Author

Not planning to work on in for the forseeable.

@anthrotype
Copy link
Member

ok i'll fix that thanks

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

Successfully merging a pull request may close this issue.

2 participants