Skip to content

Commit

Permalink
Merge pull request #658 from googlefonts/use-missingcomponenterror
Browse files Browse the repository at this point in the history
Better error message when component is missing
  • Loading branch information
madig authored Jan 27, 2021
2 parents 8422053 + 2c96b47 commit cb42505
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 28 deletions.
9 changes: 8 additions & 1 deletion Lib/glyphsLib/builder/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import logging

from fontTools.pens.basePen import MissingComponentError
from fontTools.pens.recordingPen import DecomposingRecordingPen
from glyphsLib.classes import GSBackgroundLayer
from glyphsLib.types import Transform
Expand Down Expand Up @@ -109,7 +110,13 @@ def to_ufo_components_background_decompose(self, ufo_glyph, layer):

rpen = DecomposingRecordingPen(glyphSet=layers)
for component in layer.components:
component.draw(rpen)
try:
component.draw(rpen)
except MissingComponentError as e:
raise MissingComponentError(
f"Glyph '{ufo_glyph.name}', background layer: component "
f"'{component.name}' points to a non-existent glyph."
) from e
rpen.replay(ufo_glyph.getPen())


Expand Down
68 changes: 49 additions & 19 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,55 @@
#
# pip-compile requirements-dev.in
#
appdirs==1.4.4 # via fs
attrs==20.3.0 # via pytest
coverage==5.3 # via -r requirements-dev.in
defcon==0.7.2 # via -r requirements-dev.in
fonttools[ufo,unicode]==4.17.1 # via defcon
fs==2.4.11 # via fonttools
iniconfig==1.1.1 # via pytest
lxml==4.6.2 # via xmldiff
packaging==20.7 # via pytest
pluggy==0.13.1 # via pytest
py==1.9.0 # via pytest
pyparsing==2.4.7 # via packaging
pytest-randomly==3.5.0 # via -r requirements-dev.in
pytest==6.1.2 # via -r requirements-dev.in, pytest-randomly
pytz==2020.4 # via fs
six==1.15.0 # via fs, xmldiff
toml==0.10.2 # via pytest
ufonormalizer==0.4.2 # via -r requirements-dev.in
xmldiff==2.4 # via -r requirements-dev.in

appdirs==1.4.4
# via fs
atomicwrites==1.4.0
# via pytest
attrs==20.3.0
# via pytest
colorama==0.4.4
# via pytest
coverage==5.4
# via -r requirements-dev.in
defcon==0.7.2
# via -r requirements-dev.in
fonttools[ufo,unicode]==4.19.0
# via defcon
fs==2.4.12
# via fonttools
iniconfig==1.1.1
# via pytest
lxml==4.6.2
# via xmldiff
packaging==20.8
# via pytest
pluggy==0.13.1
# via pytest
py==1.10.0
# via pytest
pyparsing==2.4.7
# via packaging
pytest-randomly==3.5.0
# via -r requirements-dev.in
pytest==6.2.2
# via
# -r requirements-dev.in
# pytest-randomly
pytz==2020.5
# via fs
six==1.15.0
# via
# fs
# xmldiff
toml==0.10.2
# via pytest
ufonormalizer==0.5.3
# via -r requirements-dev.in
unicodedata2==13.0.0.post2
# via fonttools
xmldiff==2.4
# via -r requirements-dev.in

# The following packages are considered to be unsafe in a requirements file:
# setuptools
26 changes: 19 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@
#
# pip-compile setup.py
#
appdirs==1.4.4 # via fs
attrs==20.3.0 # via ufolib2
fonttools[ufo,unicode]==4.17.1 # via glyphsLib (setup.py), ufolib2
fs==2.4.11 # via fonttools
pytz==2020.4 # via fs
six==1.15.0 # via fs
ufolib2==0.10.0 # via glyphsLib (setup.py)

appdirs==1.4.4
# via fs
attrs==20.3.0
# via ufolib2
fonttools[ufo,unicode]==4.19.0
# via
# glyphsLib (setup.py)
# ufolib2
fs==2.4.12
# via fonttools
pytz==2020.5
# via fs
six==1.15.0
# via fs
ufolib2==0.11.1
# via glyphsLib (setup.py)
unicodedata2==13.0.0.post2
# via fonttools

# The following packages are considered to be unsafe in a requirements file:
# setuptools
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install_requires =
# Synchronize with requirements.in until
# https://github.com/jazzband/pip-tools/issues/1047 is implemented.
ufoLib2 >= 0.6.2
fonttools[ufo,unicode] >= 4.6.0
fonttools[ufo,unicode] >= 4.19.0
importlib_resources; python_version < '3.7'

[options.extras_require]
Expand Down
14 changes: 14 additions & 0 deletions tests/builder/components_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import pytest
from fontTools.pens.basePen import MissingComponentError

import glyphsLib
from glyphsLib import to_designspace
from glyphsLib.classes import GSComponent


def test_background_component_decompose(datadir):
Expand Down Expand Up @@ -35,3 +39,13 @@ def test_background_component_decompose(datadir):
ufo_bd.layers["Apr 27 20, 17:59.background"]["B"].contours
== ufo_bd["A"].contours
)


def test_background_component_decompose_missing(datadir):
font = glyphsLib.GSFont(str(datadir.join("Recursion.glyphs")))

layer = font.glyphs["B"].layers["DB4D7D04-C02D-48DE-811E-03AA03052DD2"].background
layer.components.append(GSComponent("xxx"))

with pytest.raises(MissingComponentError):
to_designspace(font)

0 comments on commit cb42505

Please sign in to comment.