How to use the fontbakery.checkrunner.ERROR function in fontbakery

To help you get started, we’ve selected a few fontbakery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googlefonts / fontbakery / Lib / fontbakery / profiles / fontval.py View on Github external
"-report-in-font-dir", "-no-raster-tests"
    ]
    subprocess.check_output(fval_cmd, stderr=subprocess.STDOUT)
  except subprocess.CalledProcessError as e:
    filtered_msgs = ""
    for line in e.output.decode().split("\n"):
      disable_it = False
      for substring in disabled_fval_checks:
        if substring in line:
          disable_it = True
      if not disable_it:
        filtered_msgs += line + "\n"
    yield INFO, ("Microsoft Font Validator returned an error code."
                 " Output follows :\n\n{}\n").format(filtered_msgs)
  except (OSError, IOError) as error:
    yield ERROR, ("Mono runtime and/or "
                  "Microsoft Font Validator are not available!")
    raise error

  def report_message(msg, details):
    if details:
      if isinstance(details, list) and len(details) > 1:
        # We'll print lists with one item per line for
        # improved readability.
        if None in details:
          details.remove(None)

        # A designer will likely not need the full list
        # in order to fix a problem.
        # Showing only the 10 first ones is more than enough
        # and helps avoid flooding the report.
        if len(details) > 25:
github googlefonts / fontbakery / Lib / fontbakery / profiles / universal.py View on Github external
latest_str = line.split('LATEST')[1].strip()
      if '(latest)' in line:
        is_latest = True

    if not (is_latest or is_up_to_date(installed_str, latest_str)):
      failed = True
      yield FAIL, (f"Current Font Bakery version is {installed_str},"
                   f" while a newer {latest_str} is already available."
                    " Please upgrade it with 'pip install -U fontbakery'")
    yield INFO, pip_output.decode()
  except Exception:
    yield FAIL, ("Unable to detect what's the latest version of"
                 " FontBakery available. Maybe we're offline?"
                 " Please check Internet access and try again.")
  except subprocess.CalledProcessError as e:
    yield ERROR, ("Running 'pip search fontbakery' returned an error code."
                  " Output follows :\n\n{}\n").format(e.output.decode())

  if not failed:
    yield PASS, "Font Bakery is up-to-date"
github googlefonts / fontbakery / Lib / fontbakery / reporters / terminal.py View on Github external
print = partial(builtins.print, file=output)

    if not status.weight >= self._structure_threshold \
                                      or status in self._skip_status_report:
      return output.getvalue()

    if status == START:
      order = message
      print('Start ... running {} individual check executions.'.format(len(order)))

    if status == END:
      if self._print_progress:
        print(self._draw_progressbar())#.encode('utf-8'))
      print('')
      if self._cupcake and len(self._order) \
              and self._counter[ERROR.name] + self._counter[FAIL.name] == 0 \
              and self._counter[PASS.name] > 20:
        print(self.theme["cupcake"](CUPCAKE))
      print('DONE!')
    return output.getvalue()
github googlefonts / fontbakery / Lib / fontbakery / reporters / terminal.py View on Github external
, STARTCHECK
            , SKIP
            , PASS
            , FAIL
            , ENDCHECK
            , ENDSECTION
            , START
            , END
            , DEBUG
            , Status
            )

statuses = (
              INFO
            , WARN
            , ERROR
            , STARTSECTION
            , STARTCHECK
            , SKIP
            , PASS
            , FAIL
            , ENDCHECK
            , ENDSECTION
            , START
            , END
            , DEBUG
            )
# these are displayed in the result counters
check_statuses = [ERROR, FAIL, SKIP, PASS, WARN, INFO]
check_statuses.sort(key=lambda s:s.weight, reverse=True)
github googlefonts / fontbakery / Lib / fontbakery / commands / check_profile.py View on Github external
json.dump(sr.getdoc(), args.json, sort_keys=True, indent=4)
    print("A report in JSON format has been"
          " saved to '{}'".format(args.json.name))

  if args.ghmarkdown:
    args.ghmarkdown.write(mdr.get_markdown())
    print("A report in GitHub Markdown format which can be useful\n"
          " for posting issues on a GitHub issue tracker has been\n"
          " saved to '{}'".format(args.ghmarkdown.name))

  if args.html:
    args.html.write(hr.get_html())
    print(f"A report in HTML format has been saved to '{args.html.name}'")

  # Fail and error let the command fail
  return 1 if tr.worst_check_status in (ERROR, FAIL) else 0
github googlefonts / fontbakery / Lib / fontbakery / profiles / ufo_sources.py View on Github external
def com_daltonmaag_check_ufolint(font):
  """Run ufolint on UFO source directory."""
  import subprocess
  ufolint_cmd = ["ufolint", font]

  try:
    subprocess.check_output(ufolint_cmd, stderr=subprocess.STDOUT)
  except subprocess.CalledProcessError as e:
    yield FAIL, ("ufolint failed the UFO source. Output follows :"
                 "\n\n{}\n").format(e.output.decode())
  except OSError:
    yield ERROR, "ufolint is not available!"
  else:
    yield PASS, "ufolint passed the UFO source."
github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
def com_google_fonts_check_165(ttFont, familyname):
  """ Familyname must be unique according to namecheck.fontdata.com """
  FB_ISSUE_TRACKER = "https://github.com/googlefonts/fontbakery/issues"
  import requests
  url = f"http://namecheck.fontdata.com/?q={familyname}"
  try:
    response = requests.get(url, timeout=10)
    data = response.content.decode("utf-8")
    if "fonts by that exact name" in data:
      yield INFO, ("The family name '{}' seem to be already in use.\n"
                   "Please visit {} for more info.").format(familyname, url)
    else:
      yield PASS, "Font familyname seems to be unique."
  except:
    yield ERROR, ("Failed to access: '{}'.\n"
                  "Please report this issue at:\n{}").format(url,
                                                             FB_ISSUE_TRACKER)
github googlefonts / fontbakery / Lib / fontbakery / profiles / name.py View on Github external
def com_adobe_fonts_check_name_postscript_vs_cff(ttFont):
  """CFF table FontName must match name table ID 6 (PostScript name)."""
  cff_names = ttFont['CFF '].cff.fontNames
  if len(cff_names) != 1:
    yield ERROR, ("Unexpected number of font names in CFF table.")
    return

  passed = True
  cff_name = cff_names[0]
  for entry in ttFont['name'].names:
    if entry.nameID == NameID.POSTSCRIPT_NAME:
      postscript_name = entry.toUnicode()
      if postscript_name != cff_name:
        passed = False
        yield FAIL,\
              Message("mismatch",
                      f"Name table PostScript name '{postscript_name}' "
                      f"does not match CFF table FontName '{cff_name}'.")

  if passed:
    yield PASS, ("Name table PostScript name matches CFF table FontName.")