Skip to content

Commit

Permalink
Merge pull request #825 from googlefonts/evan-mod
Browse files Browse the repository at this point in the history
tags: do not include scores for meta categories
  • Loading branch information
m4rc1e authored Feb 7, 2024
2 parents e627020 + 7df3edb commit 0177e82
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
2 changes: 0 additions & 2 deletions Lib/gftools/fontsetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def getter(obj, path):
return obj
key = path[0]
if hasmethod(obj, key):
import pdb
pdb.set_trace()
return getattr(obj, key)(*path[1])
if isinstance(key, str) and hasattr(obj, key):
return getter(getattr(obj, key), path[1:])
Expand Down
60 changes: 36 additions & 24 deletions Lib/gftools/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import requests
from io import StringIO
from functools import lru_cache
from difflib import Differ


class SheetStructureChange(Exception):
Expand Down Expand Up @@ -41,7 +42,7 @@ class GFTags(object):
],
"Slab": ["Geometric", "Humanist", "Clarendon"],
"Script": ["Formal", "Informal", "Handwritten", "Upright Script"],
"Display": [
"Theme": [
"Blackletter",
"Wacky",
"Blobby",
Expand Down Expand Up @@ -145,14 +146,25 @@ def _parse_csv(self):
continue
family = self.data[i][0]
value = int(self.data[i][j])
group = self.data[0][j]
category = self.data[0][j]
# If no tag exists for a value, it means a value has been assigned
# to the whole group such as Sans, Sans Serif etc
tag = self.data[1][j] or group
# to the whole group such as Sans, Sans Serif etc. We don't want to
# include these since we can deduce it ourselves according to Evan.
sub_category = self.data[1][j]
if sub_category == "":
continue
if category not in self.CATEGORIES:
raise ValueError(
f"'{category}' not in known categories, '{self.CATEGORIES.keys()}'"
)
if sub_category not in self.CATEGORIES[category]:
raise ValueError(
f"'{sub_category}' not in known sub categories, '{self.CATEGORIES[category]}'"
)
res.append(
{
"Family": family,
"Group/Tag": f"/{group}/{tag}",
"Group/Tag": f"/{category}/{sub_category}",
"Weight": value,
}
)
Expand Down Expand Up @@ -215,21 +227,21 @@ def check_structure(self):
"Script",
"Script",
"",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Display",
"Size/Large",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"Theme",
"",
"Arabic",
"Arabic",
Expand Down Expand Up @@ -413,23 +425,23 @@ def check_structure(self):
"Artistic",
]
if self.data[0] != columns_0:
differences = "\n".join(Differ().compare(columns_0, self.data[0]))
raise SheetStructureChange(
"Sheet's first row of columns has changed. If intentional, "
"please update columns_0 variable."
f"please update columns_0 variable.\n**Changes**:\n{differences}"
)
if self.data[1] != columns_1:
differences = "\n".join(Differ().compare(columns_1, self.data[1]))
raise SheetStructureChange(
"Sheet's second row of columns have changed. If intentional, "
"please update columns_1 variable."
"please update columns_1 variable.\n**Changes**:\n{differences}"
)

# Check a few families
munged_data = self._parse_csv()
test_tags = [
# row 0
{"Family": "ABeeZee", "Group/Tag": "/Sans/Geometric", "Weight": 10},
# row 131
{"Family": "Akaya Kanadaka", "Group/Tag": "/Serif/Serif", "Weight": 10},
# row 330
{"Family": "Bonbon", "Group/Tag": "/Script/Handwritten", "Weight": 100},
# row 577
Expand Down

0 comments on commit 0177e82

Please sign in to comment.