Skip to content

Commit f4577af

Browse files
committed
black the bin directory too
1 parent b45a0e9 commit f4577af

File tree

2 files changed

+128
-113
lines changed

2 files changed

+128
-113
lines changed

bin/fonts-subset-support.py

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,71 +19,75 @@
1919
import sys
2020
from absl import flags, app
2121
from gftools.util import google_fonts as fonts
22-
from gfsubsets import (CodepointsInFont,
23-
CodepointsInSubset)
22+
from gfsubsets import CodepointsInFont, CodepointsInSubset
2423

2524
FLAGS = flags.FLAGS
26-
flags.DEFINE_integer('max_diff_cps', 5,
27-
'Maximum difference in number of codepoints allowed for'
28-
' a particular subset before which it is flagged.')
25+
flags.DEFINE_integer(
26+
"max_diff_cps",
27+
5,
28+
"Maximum difference in number of codepoints allowed for"
29+
" a particular subset before which it is flagged.",
30+
)
2931

3032

3133
def main(argv):
32-
if len(argv) != 2 or not os.path.isdir(argv[1]):
33-
sys.exit('Must have one argument, a directory containing font files.')
34+
if len(argv) != 2 or not os.path.isdir(argv[1]):
35+
sys.exit("Must have one argument, a directory containing font files.")
3436

35-
sys.stderr = open(os.devnull, 'w')
36-
dirpath = argv[1]
37-
result = True
38-
files = []
39-
for font in fonts.Metadata(dirpath).fonts:
40-
files.append(os.path.join(dirpath, font.filename))
41-
for subset in fonts.Metadata(dirpath).subsets:
42-
if subset == 'menu':
43-
continue
44-
(file1, file2, diff_size) = _LeastSimilarCoverage(files, subset)
45-
if diff_size > FLAGS.max_diff_cps:
46-
print('%s coverage for %s failed' % (dirpath, subset))
47-
print('Difference of codepoints between %s & %s is %d' % (
48-
file1, file2, diff_size))
49-
result = False
37+
sys.stderr = open(os.devnull, "w")
38+
dirpath = argv[1]
39+
result = True
40+
files = []
41+
for font in fonts.Metadata(dirpath).fonts:
42+
files.append(os.path.join(dirpath, font.filename))
43+
for subset in fonts.Metadata(dirpath).subsets:
44+
if subset == "menu":
45+
continue
46+
(file1, file2, diff_size) = _LeastSimilarCoverage(files, subset)
47+
if diff_size > FLAGS.max_diff_cps:
48+
print("%s coverage for %s failed" % (dirpath, subset))
49+
print(
50+
"Difference of codepoints between %s & %s is %d"
51+
% (file1, file2, diff_size)
52+
)
53+
result = False
5054

51-
if result:
52-
print('%s passed subset coverage' % (dirpath))
55+
if result:
56+
print("%s passed subset coverage" % (dirpath))
5357

5458

5559
def _LeastSimilarCoverage(files, subset):
56-
"""Returns pair of fonts having inconsistent coverage for a subset.
60+
"""Returns pair of fonts having inconsistent coverage for a subset.
5761
58-
Args:
59-
files: List of font files
60-
subset: Name of subset
61-
Returns:
62-
3 tuple of (file1, file2, number of codepoints difference)
63-
"""
64-
worst = (None, None, 0)
65-
subsetcps = CodepointsInSubset(subset, True)
66-
for pair in itertools.combinations(files, 2):
67-
inconsistency = _InconsistentSubsetSupport(pair[0], pair[1], subsetcps)
68-
if inconsistency > worst[2]:
69-
worst = (pair[0], pair[1], inconsistency)
70-
return worst
62+
Args:
63+
files: List of font files
64+
subset: Name of subset
65+
Returns:
66+
3 tuple of (file1, file2, number of codepoints difference)
67+
"""
68+
worst = (None, None, 0)
69+
subsetcps = CodepointsInSubset(subset, True)
70+
for pair in itertools.combinations(files, 2):
71+
inconsistency = _InconsistentSubsetSupport(pair[0], pair[1], subsetcps)
72+
if inconsistency > worst[2]:
73+
worst = (pair[0], pair[1], inconsistency)
74+
return worst
7175

7276

7377
def _InconsistentSubsetSupport(file1, file2, subsetcps):
74-
"""Returns difference in number of codepoints supported.
78+
"""Returns difference in number of codepoints supported.
7579
76-
Args:
77-
file1: Name of font file
78-
file2: Name of font file
79-
subsetcps: Complete set of codepoints to be supported
80-
Returns:
81-
Difference in number of codepoints between file1 and file2.
82-
"""
83-
supportcps1 = len(subsetcps.intersection(CodepointsInFont(file1)))
84-
supportcps2 = len(subsetcps.intersection(CodepointsInFont(file2)))
85-
return abs(supportcps1 - supportcps2)
80+
Args:
81+
file1: Name of font file
82+
file2: Name of font file
83+
subsetcps: Complete set of codepoints to be supported
84+
Returns:
85+
Difference in number of codepoints between file1 and file2.
86+
"""
87+
supportcps1 = len(subsetcps.intersection(CodepointsInFont(file1)))
88+
supportcps2 = len(subsetcps.intersection(CodepointsInFont(file2)))
89+
return abs(supportcps1 - supportcps2)
8690

8791

88-
if __name__ == '__main__':
89-
app.run(main)
92+
if __name__ == "__main__":
93+
app.run(main)

bin/test_args.py

Lines changed: 73 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
#!/usr/bin/env python3
22
import sys
3+
34
target_modules = [
4-
"gftools-build-font2ttf",
5-
"gftools-fix-ascii-fontmetadata",
6-
"gftools-fix-familymetadata",
7-
"gftools-fix-fsselection",
8-
"gftools-fix-gasp",
9-
"gftools-fix-glyph-private-encoding",
10-
"gftools-fix-glyphs",
11-
"gftools-fix-nameids",
12-
# "gftools-fix-nonhinting", #this one do not even use argparse module
13-
"gftools-fix-ttfautohint",
14-
"gftools-fix-vendorid",
15-
"gftools-fix-vertical-metrics",
16-
"gftools-list-panose",
17-
"gftools-list-weightclass",
18-
"gftools-list-widthclass",
19-
"gftools-metadata-vs-api",
20-
"gftools-update-families"
5+
"gftools-build-font2ttf",
6+
"gftools-fix-ascii-fontmetadata",
7+
"gftools-fix-familymetadata",
8+
"gftools-fix-fsselection",
9+
"gftools-fix-gasp",
10+
"gftools-fix-glyph-private-encoding",
11+
"gftools-fix-glyphs",
12+
"gftools-fix-nameids",
13+
# "gftools-fix-nonhinting", #this one do not even use argparse module
14+
"gftools-fix-ttfautohint",
15+
"gftools-fix-vendorid",
16+
"gftools-fix-vertical-metrics",
17+
"gftools-list-panose",
18+
"gftools-list-weightclass",
19+
"gftools-list-widthclass",
20+
"gftools-metadata-vs-api",
21+
"gftools-update-families",
2122
]
2223

2324

2425
help_text = {}
2526
for module_name in target_modules:
26-
target = __import__(module_name)
27-
help_text[module_name] = target.parser.format_help()
27+
target = __import__(module_name)
28+
help_text[module_name] = target.parser.format_help()
2829

2930
# We need to extend this list with our
3031
# minimal common interface for all scripts:
@@ -35,58 +36,68 @@
3536
# We probably want to reduce this list to the bare minimum
3637
# and maybe make some of these mandatory.
3738
optional_args = [
38-
"[-v]",
39-
"[--autofix]",
40-
"[--csv]",
41-
"[--verbose]",
42-
"[-a ASCENTS]",
43-
"[-ah ASCENTS_HHEA]",
44-
"[-at ASCENTS_TYPO]",
45-
"[-aw ASCENTS_WIN]",
46-
"[-d DESCENTS]",
47-
"[-dh DESCENTS_HHEA]",
48-
"[-dt DESCENTS_TYPO]",
49-
"[-dw DESCENTS_WIN]",
50-
"[-l LINEGAPS]",
51-
"[-lh LINEGAPS_HHEA]",
52-
"[-lt LINEGAPS_TYPO]",
53-
"[--api API]",
54-
"[--cache CACHE]",
55-
"[--set SET]",
56-
"[--platform PLATFORM]",
57-
"[--id ID]",
58-
"[--ignore-copy-existing-ttf]",
59-
"[--with-otf]",
60-
"[-e EXISTING]"
39+
"[-v]",
40+
"[--autofix]",
41+
"[--csv]",
42+
"[--verbose]",
43+
"[-a ASCENTS]",
44+
"[-ah ASCENTS_HHEA]",
45+
"[-at ASCENTS_TYPO]",
46+
"[-aw ASCENTS_WIN]",
47+
"[-d DESCENTS]",
48+
"[-dh DESCENTS_HHEA]",
49+
"[-dt DESCENTS_TYPO]",
50+
"[-dw DESCENTS_WIN]",
51+
"[-l LINEGAPS]",
52+
"[-lh LINEGAPS_HHEA]",
53+
"[-lt LINEGAPS_TYPO]",
54+
"[--api API]",
55+
"[--cache CACHE]",
56+
"[--set SET]",
57+
"[--platform PLATFORM]",
58+
"[--id ID]",
59+
"[--ignore-copy-existing-ttf]",
60+
"[--with-otf]",
61+
"[-e EXISTING]",
6162
]
6263

6364
failed = False
6465
for arg in mandatory_args:
65-
missing = []
66-
for module_name in help_text.keys():
67-
if arg not in help_text[module_name]:
68-
missing.append(module_name)
66+
missing = []
67+
for module_name in help_text.keys():
68+
if arg not in help_text[module_name]:
69+
missing.append(module_name)
6970

70-
if missing != []:
71-
failed = True
72-
print (("ERROR: These modules lack the {} command line argument:"
73-
"\nERROR:\t{}\n").format(arg, '\nERROR:\t'.join(missing)))
71+
if missing != []:
72+
failed = True
73+
print(
74+
(
75+
"ERROR: These modules lack the {} command line argument:"
76+
"\nERROR:\t{}\n"
77+
).format(arg, "\nERROR:\t".join(missing))
78+
)
7479

7580
import re
81+
7682
for module_name in help_text.keys():
77-
text = help_text[module_name]
78-
args = re.findall('(\[\-[^\[]*\])', text)
79-
# print (args)
80-
# print ("INFO: {}: {}".format(module_name, text))
81-
for arg in args:
82-
if arg not in optional_args + mandatory_args:
83-
print (("WARNING: Module {} has cmdline argument {}"
84-
" which is not in the list of optional ones."
85-
"").format(module_name, arg))
83+
text = help_text[module_name]
84+
args = re.findall("(\[\-[^\[]*\])", text)
85+
# print (args)
86+
# print ("INFO: {}: {}".format(module_name, text))
87+
for arg in args:
88+
if arg not in optional_args + mandatory_args:
89+
print(
90+
(
91+
"WARNING: Module {} has cmdline argument {}"
92+
" which is not in the list of optional ones."
93+
""
94+
).format(module_name, arg)
95+
)
8696

8797
# TODO: we also need to verify positional attributes like font and ttfont
8898

8999
if failed:
90-
sys.exit("Some errors were detected in the command-line"
91-
" arguments of the Font Bakery scripts.")
92-
100+
sys.exit(
101+
"Some errors were detected in the command-line"
102+
" arguments of the Font Bakery scripts."
103+
)

0 commit comments

Comments
 (0)