diff --git a/Lib/fontTools/varLib/interpolatable.py b/Lib/fontTools/varLib/interpolatable.py index 4e8b96252..8ab119c5c 100644 --- a/Lib/fontTools/varLib/interpolatable.py +++ b/Lib/fontTools/varLib/interpolatable.py @@ -161,7 +161,7 @@ def test(glyphsets, glyphs=None, names=None, ignore_missing=False): for glyphset, name in zip(glyphsets, names): glyph = glyphset[glyph_name] - + if glyph is None: if not ignore_missing: add_problem(glyph_name, {"type": "missing", "master": name}) @@ -248,12 +248,14 @@ def test(glyphsets, glyphs=None, names=None, ignore_missing=False): _rot_list([complex(*pt) for pt, bl in mirrored], i) ) - # m0idx should be the index of the first non-None item in allNodeTypes, + # m0idx should be the index of the first non-None item in allNodeTypes, # else give it the first index of None, which is likely 0 - m0idx = allNodeTypes.index(next((x for x in allNodeTypes if x is not None), None)) + m0idx = allNodeTypes.index( + next((x for x in allNodeTypes if x is not None), None) + ) # m0 is the first non-None item in allNodeTypes, or the first item if all are None m0 = allNodeTypes[m0idx] - for i, m1 in enumerate(allNodeTypes[m0idx+1:]): + for i, m1 in enumerate(allNodeTypes[m0idx + 1 :]): if m1 is None: continue if len(m0) != len(m1): @@ -301,12 +303,14 @@ def test(glyphsets, glyphs=None, names=None, ignore_missing=False): ) continue - # m0idx should be the index of the first non-None item in allVectors, + # m0idx should be the index of the first non-None item in allVectors, # else give it the first index of None, which is likely 0 - m0idx = allVectors.index(next((x for x in allVectors if x is not None), None)) + m0idx = allVectors.index( + next((x for x in allVectors if x is not None), None) + ) # m0 is the first non-None item in allVectors, or the first item if all are None m0 = allVectors[m0idx] - for i, m1 in enumerate(allVectors[m0idx+1:]): + for i, m1 in enumerate(allVectors[m0idx + 1 :]): if m1 is None: continue if len(m0) != len(m1): @@ -333,13 +337,15 @@ def test(glyphsets, glyphs=None, names=None, ignore_missing=False): }, ) break - - # m0idx should be the index of the first non-None item in allContourIsomorphisms, + + # m0idx should be the index of the first non-None item in allContourIsomorphisms, # else give it the first index of None, which is likely 0 - m0idx = allContourIsomorphisms.index(next((x for x in allContourIsomorphisms if x is not None), None)) + m0idx = allContourIsomorphisms.index( + next((x for x in allContourIsomorphisms if x is not None), None) + ) # m0 is the first non-None item in allContourIsomorphisms, or the first item if all are None m0 = allContourIsomorphisms[m0idx] - for i, m1 in enumerate(allContourIsomorphisms[m0idx+1:]): + for i, m1 in enumerate(allContourIsomorphisms[m0idx + 1 :]): if m1 is None: continue if len(m0) != len(m1): @@ -397,7 +403,11 @@ def main(args=None): help="Will not report glyphs missing from sparse masters as errors", ) parser.add_argument( - "inputs", metavar="FILE", type=str, nargs="+", help="Input a single DesignSpace/Glyphs file, or multiple TTF/UFO files" + "inputs", + metavar="FILE", + type=str, + nargs="+", + help="Input a single DesignSpace/Glyphs file, or multiple TTF/UFO files", ) args = parser.parse_args(args) @@ -477,11 +487,11 @@ def main(args=None): glyphset = font.getGlyphSet() else: glyphset = font - glyphsets.append({k:glyphset[k] for k in glyphset.keys()}) - + glyphsets.append({k: glyphset[k] for k in glyphset.keys()}) + if not glyphs: glyphs = set([gn for glyphset in glyphsets for gn in glyphset.keys()]) - + for glyphset in glyphsets: glyphSetGlyphNames = set(glyphset.keys()) diff = glyphs - glyphSetGlyphNames @@ -489,8 +499,10 @@ def main(args=None): for gn in diff: glyphset[gn] = None - problems = test(glyphsets, glyphs=glyphs, names=names, ignore_missing=args.ignore_missing) - + problems = test( + glyphsets, glyphs=glyphs, names=names, ignore_missing=args.ignore_missing + ) + if not args.quiet: if args.json: import json diff --git a/Tests/varLib/interpolatable_test.py b/Tests/varLib/interpolatable_test.py index ec33a158e..a20aee10a 100644 --- a/Tests/varLib/interpolatable_test.py +++ b/Tests/varLib/interpolatable_test.py @@ -105,7 +105,7 @@ class InterpolatableTest(unittest.TestCase): def test_glyphsapp(self): glyphsapp_path = self.get_test_input("InterpolateLayout.glyphs") self.assertIsNone(interpolatable_main([glyphsapp_path])) - + def test_VF(self): suffix = ".ttf" ttx_dir = self.get_test_input("master_ttx_varfont_ttf") @@ -116,10 +116,10 @@ class InterpolatableTest(unittest.TestCase): self.compile_font(path, suffix, self.tempdir) ttf_paths = self.get_file_list(self.tempdir, suffix) - + problems = interpolatable_main(["--quiet"] + ttf_paths) self.assertIsNone(problems) - + def test_sparse_interpolatable_ttfs(self): suffix = ".ttf" ttx_dir = self.get_test_input("master_ttx_interpolatable_ttf") @@ -130,64 +130,127 @@ class InterpolatableTest(unittest.TestCase): self.compile_font(path, suffix, self.tempdir) ttf_paths = self.get_file_list(self.tempdir, suffix) - + # without --ignore-missing problems = interpolatable_main(["--quiet"] + ttf_paths) - self.assertEqual(problems['a'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - self.assertEqual(problems['s'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - self.assertEqual(problems['edotabove'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - self.assertEqual(problems['dotabovecomb'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - + self.assertEqual( + problems["a"], + [{"type": "missing", "master": "SparseMasters-Medium"}] + ) + self.assertEqual( + problems["s"], + [{"type": "missing", "master": "SparseMasters-Medium"}] + ) + self.assertEqual( + problems["edotabove"], + [{"type": "missing", "master": "SparseMasters-Medium"}], + ) + self.assertEqual( + problems["dotabovecomb"], + [{"type": "missing", "master": "SparseMasters-Medium"}], + ) + # normal order, with --ignore-missing self.assertIsNone(interpolatable_main(["--ignore-missing"] + ttf_paths)) # purposely putting the sparse master (medium) first - self.assertIsNone(interpolatable_main(["--ignore-missing"] + [ttf_paths[1]] + [ttf_paths[0]] + [ttf_paths[2]])) + self.assertIsNone( + interpolatable_main( + ["--ignore-missing"] + [ttf_paths[1]] + [ttf_paths[0]] + [ttf_paths[2]] + ) + ) # purposely putting the sparse master (medium) last - self.assertIsNone(interpolatable_main(["--ignore-missing"] + [ttf_paths[0]] + [ttf_paths[2]] + [ttf_paths[1]])) + self.assertIsNone( + interpolatable_main( + ["--ignore-missing"] + [ttf_paths[0]] + [ttf_paths[2]] + [ttf_paths[1]] + ) + ) def test_sparse_interpolatable_ufos(self): ttx_dir = self.get_test_input("master_ufo") ufo_paths = self.get_file_list(ttx_dir, ".ufo", "SparseMasters-") - + # without --ignore-missing problems = interpolatable_main(["--quiet"] + ufo_paths) - self.assertEqual(problems['a'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - self.assertEqual(problems['s'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - self.assertEqual(problems['edotabove'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - self.assertEqual(problems['dotabovecomb'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - + self.assertEqual( + problems["a"], + [{"type": "missing", "master": "SparseMasters-Medium"}] + ) + self.assertEqual( + problems["s"], + [{"type": "missing", "master": "SparseMasters-Medium"}] + ) + self.assertEqual( + problems["edotabove"], + [{"type": "missing", "master": "SparseMasters-Medium"}], + ) + self.assertEqual( + problems["dotabovecomb"], + [{"type": "missing", "master": "SparseMasters-Medium"}], + ) + # normal order, with --ignore-missing self.assertIsNone(interpolatable_main(["--ignore-missing"] + ufo_paths)) # purposely putting the sparse master (medium) first - self.assertIsNone(interpolatable_main(["--ignore-missing"] + [ufo_paths[1]] + [ufo_paths[0]] + [ufo_paths[2]])) + self.assertIsNone( + interpolatable_main( + ["--ignore-missing"] + [ufo_paths[1]] + [ufo_paths[0]] + [ufo_paths[2]] + ) + ) # purposely putting the sparse master (medium) last - self.assertIsNone(interpolatable_main(["--ignore-missing"] + [ufo_paths[0]] + [ufo_paths[2]] + [ufo_paths[1]])) + self.assertIsNone( + interpolatable_main( + ["--ignore-missing"] + [ufo_paths[0]] + [ufo_paths[2]] + [ufo_paths[1]] + ) + ) def test_sparse_designspace(self): designspace_path = self.get_test_input("SparseMasters_ufo.designspace") - + problems = interpolatable_main(["--quiet", designspace_path]) - self.assertEqual(problems['a'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - self.assertEqual(problems['s'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - self.assertEqual(problems['edotabove'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - self.assertEqual(problems['dotabovecomb'], [{'type': 'missing', 'master': 'SparseMasters-Medium'}]) - + self.assertEqual( + problems["a"], + [{"type": "missing", "master": "SparseMasters-Medium"}] + ) + self.assertEqual( + problems["s"], + [{"type": "missing", "master": "SparseMasters-Medium"}] + ) + self.assertEqual( + problems["edotabove"], + [{"type": "missing", "master": "SparseMasters-Medium"}], + ) + self.assertEqual( + problems["dotabovecomb"], + [{"type": "missing", "master": "SparseMasters-Medium"}], + ) + # normal order, with --ignore-missing self.assertIsNone(interpolatable_main(["--ignore-missing", designspace_path])) def test_sparse_designspace(self): glyphsapp_path = self.get_test_input("SparseMasters.glyphs") - + problems = interpolatable_main(["--quiet", glyphsapp_path]) - self.assertEqual(problems['a'], [{'type': 'missing', 'master': 'Sparse Masters-Medium'}]) - self.assertEqual(problems['s'], [{'type': 'missing', 'master': 'Sparse Masters-Medium'}]) - self.assertEqual(problems['edotabove'], [{'type': 'missing', 'master': 'Sparse Masters-Medium'}]) - self.assertEqual(problems['dotabovecomb'], [{'type': 'missing', 'master': 'Sparse Masters-Medium'}]) - + self.assertEqual( + problems["a"], + [{"type": "missing", "master": "Sparse Masters-Medium"}] + ) + self.assertEqual( + problems["s"], + [{"type": "missing", "master": "Sparse Masters-Medium"}] + ) + self.assertEqual( + problems["edotabove"], + [{"type": "missing", "master": "Sparse Masters-Medium"}], + ) + self.assertEqual( + problems["dotabovecomb"], + [{"type": "missing", "master": "Sparse Masters-Medium"}], + ) + # normal order, with --ignore-missing self.assertIsNone(interpolatable_main(["--ignore-missing", glyphsapp_path])) - def test_interpolatable_varComposite(self): input_path = self.get_test_input( "..", "..", "ttLib", "data", "varc-ac00-ac01.ttf"