Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def diffenator(self, **kwargs):
logger.info("Running Diffenator")
dst = os.path.join(self.out, "Diffenator")
mkdir(dst)
for style in self.matching_instances:
font_before = DFont(self.instances_before[style]['filename'])
font_after = DFont(self.instances[style]['filename'])
out = os.path.join(dst, style)
if font_after.is_variable and not font_before.is_variable:
font_after.set_variations_from_static(font_before)
elif not font_after.is_variable and font_before.is_variable:
font_before.set_variations_from_static(font_after)
elif font_after.is_variable and font_before.is_variable:
coordinates = self.instances_before[style]['coordinates']
font_after.set_variations(coordinates)
font_before.set_variations(coordinates)
# TODO add settings
def diffbrowsers(self, **kwargs):
"""Test fonts on GFR regression and take screenshots using
diffbrowsers. A browserstack account is required."""
logger.info("Running Diffbrowsers")
if not self._bstack_auth:
logger.info("Skipping. No Browserstack credentials. "
"See https://github.com/googlefonts/"
"diffbrowsers#installation on how to add them.")
return
dst = os.path.join(self.out, "Diffbrowsers")
mkdir(dst)
browsers_to_test = test_browsers["vf_browsers"]
fonts = [(k, self.instances_before[k]['filename'],
self.instances[k]['filename']) for k in self.matching_instances]
font_groups = self.chunkify(sorted(fonts), 4)
for group in font_groups:
styles = [i[0] for i in group]
dir_name = "_".join(styles)
fonts_before = [i[1] for i in group]
fonts_after = [i[2] for i in group]
out = os.path.join(dst, dir_name)
diff_browsers = DiffBrowsers(
auth=self._bstack_auth,
gfr_instance_url=self.GFR_URL,
dst_dir=out,
browsers=browsers_to_test,
)
def fontbakery(self):
logger.info("Running Fontbakery")
out = os.path.join(self.out, "Fontbakery")
mkdir(out)
cmd = (
["fontbakery", "check-googlefonts", "-l", "WARN"]
+ [f.reader.file.name for f in self.fonts]
+ ["-C"]
+ ["--ghmarkdown", os.path.join(out, "report.md")]
)
subprocess.call(cmd)
def plot_glyphs(self):
logger.info("Running plot glyphs")
out = os.path.join(self.out, "plot_glyphs")
mkdir(out)
fonts = [f.reader.file.name for f in self.fonts]
for font in fonts:
font_filename = os.path.basename(font)[:-4]
dfont = DFont(font)
if dfont.is_variable:
for coords in dfont.instances_coordinates:
dfont.set_variations(coords)
img_out = os.path.join(
out,
"%s_%s.png"
% (font_filename, self._instance_coords_to_filename(coords)),
)
dfont.glyphs.to_png(img_out, limit=100000)
else:
img_out = os.path.join(out, font_filename + ".png")
dfont.glyphs.to_png(dst=img_out)
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)
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:
"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)
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)
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"))]
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
)
elif args.github_dir_before:
fonts_before = download_files_in_github_dir(
args.github_dir_before, font_before_dir
)
elif args.googlefonts_before and family_on_gf:
fonts_before = download_family_from_Google_Fonts(
family_name, fonts_before_dir
)