コード例 #1
0
ファイル: fix.py プロジェクト: chrissimpkins/gftools
def fix_family(fonts, include_source_fixes=False):
    """Fix all fonts in a family"""
    validate_family(fonts)
    family_name = font_familyname(fonts[0])

    for font in fonts:
        fix_font(font, include_source_fixes=include_source_fixes)

    if include_source_fixes:
        try:
            if Google_Fonts_has_family(family_name):
                inherit_vertical_metrics(fonts)
            else:
                log.warning(f"{family_name} is not on Google Fonts. Skipping "
                            "regression fixes")
        except FileNotFoundError:
            log.warning(
                f"Google Fonts api key not found so we can't regression "
                "fix fonts. See Repo readme to add keys.")
        fix_vertical_metrics(fonts)
コード例 #2
0
ファイル: gftools-qa.py プロジェクト: graphicore/gftools
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    font_group = parser.add_argument_group(title="Fonts to qa")
    font_input_group = font_group.add_mutually_exclusive_group(required=True)
    font_input_group.add_argument("-f",
                                  "--fonts",
                                  nargs="+",
                                  help="Paths to fonts")
    font_input_group.add_argument("-pr",
                                  "--pull-request",
                                  help="Get fonts from a Github pull request")
    font_input_group.add_argument("-gh",
                                  "--github-dir",
                                  help="Get fonts from a Github directory")
    font_input_group.add_argument("-gf",
                                  "--googlefonts",
                                  help="Get fonts from Google Fonts")

    font_before_group = parser.add_argument_group(title="Fonts before input")
    font_before_input_group = font_before_group.add_mutually_exclusive_group(
        required=False)
    font_before_input_group.add_argument("-fb",
                                         "--fonts-before",
                                         nargs="+",
                                         help="Paths to previous fonts")
    font_before_input_group.add_argument(
        "-prb",
        "--pull-request-before",
        help="Get previous fonts from a Github pull request")
    font_before_input_group.add_argument(
        "-ghb",
        "--github-dir-before",
        help="Get previous fonts from a Github dir")
    font_before_input_group.add_argument(
        "-gfb",
        "--googlefonts-before",
        action="store_true",
        help="Get previous fonts from Google Fonts",
    )

    check_group = parser.add_argument_group(title="QA checks")
    check_group.add_argument(
        "-a",
        "--auto-qa",
        action="store_true",
        help=
        "Check fonts against against the same fonts hosted on Google Fonts",
    )
    check_group.add_argument("--diffenator",
                             action="store_true",
                             help="Run Fontdiffenator")
    check_group.add_argument("--diffbrowsers",
                             action="store_true",
                             help="Run Diffbrowsers")
    check_group.add_argument("--fontbakery",
                             action="store_true",
                             help="Run FontBakery")
    check_group.add_argument(
        "--plot-glyphs",
        action="store_true",
        help="Gen images of full charset, useful for new familes",
    )
    check_group.add_argument(
        "--browser-previews",
        action="store_true",
        help="Gen images on diff browsers, useful for new families",
    )
    check_group.add_argument("-dm",
                             "--diff-mode",
                             choices=("weak", "normal", "strict"),
                             default="normal")
    parser.add_argument("-re", "--filter-fonts", help="Filter fonts by regex")
    parser.add_argument("-o",
                        "--out",
                        default="out",
                        help="Output path for check results")
    parser.add_argument(
        "-ogh",
        "--out-github",
        action="store_true",
        help=("Post report data to either the pull request as a comment "
              "open a new issue. This can only be used if fonts have been "
              "fetched from either a pull request or github dir."),
    )
    parser.add_argument(
        "--out-url",
        help=(
            "Post report data to a github pr. This can be used with any font "
            "fetching method."))
    parser.add_argument("--version", action="version", version=__version__)
    args = parser.parse_args()
    if args.out_github and not any([args.pull_request, args.github_dir]):
        raise Exception(
            "Cannot upload results to a github issue or pr. "
            "Font input must either a github dir or a pull request")
    if not any([
            args.auto_qa, args.fontbakery, args.plot_glyphs, args.diffbrowsers,
            args.diffenator, args.browser_previews
    ]):
        raise Exception("Terminating. No checks selected. Run gftools qa "
                        "--help to see all possible commands.")

    # Retrieve fonts and store in out dir
    mkdir(args.out)
    fonts_dir = os.path.join(args.out, "fonts")
    mkdir(fonts_dir)
    if args.fonts:
        [shutil.copy(f, fonts_dir) for f in args.fonts]
        fonts = args.fonts
    elif args.pull_request:
        fonts = download_files_in_github_pr(
            args.pull_request,
            fonts_dir,
            ignore_static_dir=False,
        )
        if not fonts:
            logger.info("No fonts found in pull request. Skipping")
            return
    elif args.github_dir:
        fonts = download_files_in_github_dir(args.github_dir, fonts_dir)
        if not fonts:
            logger.info("No fonts found in github dir. Skipping")
            return
    elif args.googlefonts:
        fonts = download_family_from_Google_Fonts(args.googlefonts, fonts_dir)

    if args.filter_fonts:
        re_filter = re.compile(args.filter_fonts)
        fonts = [f for f in fonts if re_filter.search(f)]

    ttfonts = [
        TTFont(f) for f in fonts
        if f.endswith((".ttf", ".otf")) and "static" not in f
    ]
    family_name = family_name_from_fonts(ttfonts)
    family_on_gf = Google_Fonts_has_family(family_name)

    # Retrieve fonts_before and store in out dir
    fonts_before = None
    if any([args.fonts_before, args.pull_request_before, args.github_dir_before]) or \
           (args.googlefonts_before and family_on_gf):
        fonts_before_dir = os.path.join(args.out, "fonts_before")
        mkdir(fonts_before_dir, overwrite=False)
    if args.fonts_before:
        [shutil.copy(f, fonts_before_dir) for f in args.fonts_before]
        fonts_before = args.fonts_before
    elif args.pull_request_before:
        fonts_before = download_files_in_github_pr(args.pull_request_before,
                                                   fonts_before_dir,
                                                   ignore_static_dir=False)
    elif args.github_dir_before:
        fonts_before = download_files_in_github_dir(args.github_dir_before,
                                                    fonts_before_dir)
    elif args.googlefonts_before and family_on_gf:
        fonts_before = download_family_from_Google_Fonts(
            family_name, fonts_before_dir)

    if fonts_before:
        ttfonts_before = [
            TTFont(f) for f in fonts_before
            if f.endswith((".ttf", ".otf")) and "static" not in f
        ]
        qa = FontQA(ttfonts, ttfonts_before, args.out)
    else:
        qa = FontQA(ttfonts, out=args.out)

    if args.auto_qa and family_on_gf:
        qa.googlefonts_upgrade()
    elif args.auto_qa and not family_on_gf:
        qa.googlefonts_new()
    if args.plot_glyphs:
        qa.plot_glyphs()
    if args.browser_previews:
        qa.browser_previews()
    if args.fontbakery:
        qa.fontbakery()
    if args.diffenator:
        qa.diffenator()
    if args.diffbrowsers:
        qa.diffbrowsers()

    if args.out_url:
        qa.post_to_github(args.out_url)
    elif args.out_github and args.pull_request:
        qa.post_to_github(args.pull_request)
    elif args.out_github and args.github_dir:
        qa.post_to_github(args.github_dir)
コード例 #3
0
ファイル: gftools-qa.py プロジェクト: bghryct/Gelasio
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("fonts", nargs="+")
    before_group = parser.add_argument_group(title="Fonts before input")
    before_input_group = before_group.add_mutually_exclusive_group(
        required=False)
    before_input_group.add_argument('-fb',
                                    '--fonts-before',
                                    nargs="+",
                                    help="Fonts before paths")
    before_input_group.add_argument(
        '-gf',
        '--from-googlefonts',
        action='store_true',
        help="Diff against GoogleFonts instead of fonts_before")
    parser.add_argument("-o", "--out", default="out")
    parser.add_argument("-a",
                        "--auto-qa",
                        action="store_true",
                        help="Determine which QA tools to run for fonts")
    parser.add_argument("--diffenator",
                        action="store_true",
                        help="Run Fontdiffenator")
    parser.add_argument("--diffbrowsers",
                        action="store_true",
                        help="Run diffbrowsers")
    parser.add_argument("--fontbakery",
                        action="store_true",
                        help="Run FontBakery")
    parser.add_argument(
        "--plot-glyphs",
        action="store_true",
        help="Gen images of full charset, useful for new familes")
    parser.add_argument(
        "--browser-previews",
        action="store_true",
        help="Gen images on diff platforms, useful for new families")
    parser.add_argument("-dm",
                        "--diff-mode",
                        choices=("weak", "normal", "strict"),
                        default="normal")
    parser.add_argument("-l",
                        "--gfr-is-local",
                        action="store_true",
                        default=False)
    parser.add_argument("-rd",
                        "--render-diffs",
                        action="store_true",
                        default=False)
    args = parser.parse_args()

    mkdir(args.out, overwrite=False)

    fonts_to_check = args.fonts
    fonts_previous = any([args.fonts_before, args.from_googlefonts])

    if args.gfr_is_local:
        gfr_url = "http://0.0.0.0:5000"
    else:
        # This instance of GFR can only view waterfalls and all glyphs views.
        # To view font diffs in a browser, run GFR locally. This script gens
        # font diffs using diffenator's to_gifs method, which relies on the
        # free rendering stack.
        gfr_url = "http://35.188.158.120/"

    bstack_credentials = get_bstack_credentials()

    fonts_to_check_ttfonts = [TTFont(f) for f in fonts_to_check]
    family_name = family_name_from_fonts(fonts_to_check_ttfonts)

    if fonts_previous:
        if args.from_googlefonts:
            fonts_before = download_family_from_Google_Fonts(
                family_name, tempfile.mkdtemp())
        else:
            fonts_before = args.fonts_before

    # auto-qa
    family_on_gf = Google_Fonts_has_family(family_name)
    if args.auto_qa and family_on_gf:
        logging.info("Family exists on GF. Running regression checks")
        fonts_before = download_family_from_Google_Fonts(
            family_name, tempfile.mkdtemp())

        fb_out_dir = os.path.join(args.out, "Fontbakery")
        mkdir(fb_out_dir)
        run_fontbakery(fonts_to_check, fb_out_dir)

        diff_out_dir = os.path.join(args.out, "Diffenator")
        mkdir(diff_out_dir)
        run_diffenator(fonts_before,
                       fonts_to_check,
                       diff_out_dir,
                       thresholds=DIFFENATOR_THRESHOLDS[args.diff_mode])

        if not bstack_credentials:
            logger.warning(("Skipping Diffbrowsers. No browserstack "
                            "credentials found. See diffbrowsers readme"))
        else:
            browser_out_dir = os.path.join(args.out, "Diffbrowsers")
            mkdir(browser_out_dir)
            run_diffbrowsers(fonts_before,
                             fonts_to_check,
                             browser_out_dir,
                             bstack_credentials,
                             args.gfr_is_local,
                             gfr_url=gfr_url)
        return
    elif args.auto_qa and not family_on_gf:
        logging.info(("Family does not exist on GF. Running plot_glyphs and "
                      "browser_previews"))
        fb_out_dir = os.path.join(args.out, "Fontbakery")
        mkdir(fb_out_dir)
        run_fontbakery(fonts_to_check, fb_out_dir)

        glyphs_out_dir = os.path.join(args.out, "Plot_Glyphs")
        mkdir(glyphs_out_dir)
        run_plot_glyphs(fonts_to_check, glyphs_out_dir)

        if not bstack_credentials:
            logger.warning(("Skipping Browser Previews. No browserstack "
                            "credentials found. See diffbrowsers readme"))
        else:
            browser_out_dir = os.path.join(args.out, "Browser_Previews")
            mkdir(browser_out_dir)
            run_browser_previews(fonts_to_check,
                                 browser_out_dir,
                                 bstack_credentials,
                                 args.gfr_is_local,
                                 gfr_url=gfr_url)
        return

    # Run FB
    if args.fontbakery:
        fb_out_dir = os.path.join(args.out, "Fontbakery")
        mkdir(fb_out_dir)
        run_fontbakery(fonts_to_check, fb_out_dir)
    else:
        logger.info("Skipping fontbakery")

    # Font Diffenator
    if args.diffenator and fonts_previous:
        diff_out_dir = os.path.join(args.out, "Diffenator")
        mkdir(diff_out_dir)
        run_diffenator(fonts_before,
                       fonts_to_check,
                       diff_out_dir,
                       thresholds=DIFFENATOR_THRESHOLDS[args.diff_mode])
    else:
        logger.info("Skipping diffenator")

    # Run DiffBrowsers
    if all([args.diffbrowsers, fonts_previous, bstack_credentials]):
        browser_out_dir = os.path.join(args.out, "Diffbrowsers")
        mkdir(browser_out_dir)
        run_diffbrowsers(fonts_before,
                         fonts_to_check,
                         browser_out_dir,
                         bstack_credentials,
                         args.gfr_is_local,
                         gfr_url=gfr_url)
    elif args.diffbrowsers and not bstack_credentials:
        logger.warning(("Skipping Diffbrowsers. No browserstack credentials "
                        "found. See diffbrowsers readme"))
    else:
        logger.info("Skipping Diffbrowsers")

    # Plot Glyphs
    if args.plot_glyphs:
        glyphs_out_dir = os.path.join(args.out, "Plot_Glyphs")
        mkdir(glyphs_out_dir)
        run_plot_glyphs(fonts_to_check, glyphs_out_dir)
    else:
        logger.info("Skipping Glyphs plot")

    # Browser Previews
    if args.browser_previews and bstack_credentials:
        browser_out_dir = os.path.join(args.out, "Browser_Previews")
        mkdir(browser_out_dir)
        run_browser_previews(fonts_to_check,
                             browser_out_dir,
                             bstack_credentials,
                             args.gfr_is_local,
                             gfr_url=gfr_url)
    elif args.browser_previews and not bstack_credentials:
        logger.warning(
            ("Skipping Browser Previews. No browserstack credentials "
             "found. See diffbrowsers readme"))
    else:
        logger.info("Skipping browser_previews")