UFO profile can now be simplified
@@ -5,74 +5,17 @@ from fontbakery.callable import FontBakeryExpectedValue as ExpectedValue
from fontbakery.status import ERROR, FAIL, PASS, WARN
from fontbakery.section import Section
from fontbakery.message import Message
-from fontbakery.profile import Profile
+from fontbakery.fonts_profile import profile_factory
-class UFOProfile(Profile):
- def setup_argparse(self, argument_parser):
- """Set up custom arguments needed for this profile."""
- import glob
- import logging
- import argparse
-
- def get_fonts(pattern):
-
- fonts_to_check = []
- # use glob.glob to accept *.ufo
-
- for fullpath in glob.glob(pattern):
- fullpath_absolute = os.path.abspath(fullpath)
- if fullpath_absolute.lower().endswith(".ufo") and os.path.isdir(
- fullpath_absolute):
- fonts_to_check.append(fullpath)
- else:
- logging.warning(("Skipping '{}' as it does not seem to be"
- " valid UFO source directory.").format(fullpath))
- return fonts_to_check
-
- class MergeAction(argparse.Action):
-
- def __call__(self, parser, namespace, values, option_string=None):
- target = [item for l in values for item in l]
- setattr(namespace, self.dest, target)
-
- argument_parser.add_argument(
- 'fonts',
- # To allow optional commands like "-L" to work without other input
- # files:
- nargs='*',
- type=get_fonts,
- action=MergeAction,
- help='font file path(s) to check.'
- ' Wildcards like *.ufo are allowed.')
-
- return ('fonts',)
-
-
-fonts_expected_value = ExpectedValue(
- 'fonts'
- , default=[]
- , description='A list of the ufo file paths to check.'
- , validator=lambda fonts: (True, None) if len(fonts) \
- else (False, 'Value is empty.')
-)
-
-# ----------------------------------------------------------------------------
-# This variable serves as an exportable anchor point, see e.g. the
-# Lib/fontbakery/commands/check_ufo_sources.py script.
-profile = UFOProfile(
- default_section=Section('Default'),
- iterargs={'font': 'fonts'},
- derived_iterables={'ufo_fonts': ('ufo_font', True)},
- expected_values={fonts_expected_value.name: fonts_expected_value})
-# ----------------------------------------------------------------------------
+profile = profile_factory(default_section=Section("UFO Sources"))
@condition
-def ufo_font(font):
+def ufo_font(ufo):
try:
import defcon
- return defcon.Font(font)
+ return defcon.Font(ufo)
except:
return None
@@ -80,10 +23,10 @@ def ufo_font(font):
id = 'com.daltonmaag/check/ufolint',
proposal = 'https://github.com/googlefonts/fontbakery/pull/1736'
)
-def com_daltonmaag_check_ufolint(font):
+def com_daltonmaag_check_ufolint(ufo):
"""Run ufolint on UFO source directory."""
import subprocess
- ufolint_cmd = ["ufolint", font]
+ ufolint_cmd = ["ufolint", ufo]
try:
subprocess.check_output(ufolint_cmd, stderr=subprocess.STDOUT)
@@ -196,3 +139,6 @@ def com_daltonmaag_check_unnecessary_fields(ufo_font):
# postscriptFamilyBlues, postscriptFamilyOtherBlues,
# postscriptStemSnapH, postscriptStemSnapV -- not sure if checking for that
# is useful.
+
+profile.auto_register(globals())
+
