<commit_before>from __future__ import division, print_function, unicode_literals

import subprocess, os, pickle, time, argparse
import WriteFeaturesKernFDK, WriteFeaturesMarkFDK
import hindkit as kit

class Builder(object):

    def __init__(
        self,
        family,
        fontrevision = '1.000',
        devanagari_offset_matrix = ((0, 0), (0, 0)),
    ):

        self.family = family
        self.fontrevision = fontrevision
        self.devanagari_offset_matrix = devanagari_offset_matrix

        for module in [
            'kerning',
            'mark_positioning',
            'mark_to_mark_positioning',
            'devanagari_matra_i_variants',
        ]:
            if self.family.__dict__['has_' + module]:
                self.__dict__['enable_' + module] = True
            else:
                self.__dict__['enable_' + module] = False

        self.prepare_styles = False
        self.prepare_features = False
        self.compile = False

        self.makeinstances = False
        self.checkoutlines = False
        self.autohint = False

        self.do_style_linking = False
        self.use_os_2_version_4 = False
        self.prefer_typo_metrics = False
        self.is_width_weight_slope_only = False

        self.keep_build_directory = False

        self.parser = argparse.ArgumentParser()
        options = self.parser.add_argument_group(
            title = 'build options',
            description = 'execute `python build.py` to run stages as specified in build.py, or append arguments to override.'
        )
        options.add_argument(
            '-s', '--stages', action = 'store',
            help = '"1" for "prepare_styles", "2" for "prepare_features", and "3" for "compile".'
        )
        options.add_argument(
            '-o', '--options', action = 'store',
            help = '"0" for none, "1" for "makeinstances", "2" for "checkoutlines", and "3" for "autohint".'
        )

    def _parse_args(self):
        args = self.parser.parse_args()
        if args.stages:
            stages = str(args.stages)
            self.prepare_styles = True if '1' in stages else False
            self.prepare_features = True if '2' in stages else False
            self.compile = True if '3' in stages else False
        if args.options:
            options = str(args.options)
            self.makeinstances = True if '1' in options else False
            self.checkoutlines = True if '2' in options else False
            self.autohint = True if '3' in options else False

    def _check_master_files(self):
        is_missing = False
        message_lines = ['[WARNING] UFO master files missing:']
        for master in self.family.masters:
            if not os.path.exists(master.path):
                is_missing = True
                message_lines.append('\t' + master.path)
        if is_missing:
            message_lines.extend(['', '[Note] Exit.', ''])
            raise SystemExit('\n'.join(message_lines))

    def set_options(self, options = []):

        for supported_option in [

            'prepare_styles',
            'prepare_features',
            'compile',

            'makeinstances',
            'checkoutlines',
            'autohint',

            'do_style_linking',
            'use_os_2_version_4',
            'prefer_typo_metrics',
            'is_width_weight_slope_only',

            'keep_build_directory',

        ]:
            if supported_option in options:
                self.__dict__[supported_option] = True

    def generate_designspace(self):

        process = subprocess.Popen(
            ['AFDKOPython', 'AFDKOPython/generate_designspace.py'],
            stdin = subprocess.PIPE,
            cwd = kit.__path__[0],
        )
        process.communicate(pickle.dumps(self.family.dump()))

    def generate_fmndb(self):

        lines = []
        for style in self.family.styles:
            lines.append('')
            lines.append('[{}]'.format(style.output_full_name_postscript))
            lines.append('  f = {}'.format(self.family.output_name))
            lines.append('  s = {}'.format(style.name))

            if self.do_style_linking and (
                style.name == 'Regular' or style.is_bold or style.is_italic
            ):
                if style.is_bold:
                    lines.append('  # IsBoldStyle')
                if style.is_italic:
                    lines.append('  # IsItalicStyle')
            else:
                lines.append('  l = {}'.format(style.output_full_name))

        with open(kit.paths.FMNDN, 'w') as f:
            f.write(kit.templates.FMNDB_HEAD)
            f.write('\n'.join(lines))
            f.write('\n')

    def reset_build_directory(self):
        print('[Note] Resetting the build directory...\n')
        subprocess.call(['rm', '-fr', kit.paths.BUILD])
        subprocess.call(['mkdir', kit.paths.BUILD])<commit_msg>Fix "l" names in FMNDB<commit_after>from __future__ import division, print_function, unicode_literals

import subprocess, os, pickle, time, argparse
import WriteFeaturesKernFDK, WriteFeaturesMarkFDK
import hindkit as kit

class Builder(object):

    def __init__(
        self,
        family,
        fontrevision = '1.000',
        devanagari_offset_matrix = ((0, 0), (0, 0)),
    ):

        self.family = family
        self.fontrevision = fontrevision
        self.devanagari_offset_matrix = devanagari_offset_matrix

        for module in [
            'kerning',
            'mark_positioning',
            'mark_to_mark_positioning',
            'devanagari_matra_i_variants',
        ]:
            if self.family.__dict__['has_' + module]:
                self.__dict__['enable_' + module] = True
            else:
                self.__dict__['enable_' + module] = False

        self.prepare_styles = False
        self.prepare_features = False
        self.compile = False

        self.makeinstances = False
        self.checkoutlines = False
        self.autohint = False

        self.do_style_linking = False
        self.use_os_2_version_4 = False
        self.prefer_typo_metrics = False
        self.is_width_weight_slope_only = False

        self.keep_build_directory = False

        self.parser = argparse.ArgumentParser()
        options = self.parser.add_argument_group(
            title = 'build options',
            description = 'execute `python build.py` to run stages as specified in build.py, or append arguments to override.'
        )
        options.add_argument(
            '-s', '--stages', action = 'store',
            help = '"1" for "prepare_styles", "2" for "prepare_features", and "3" for "compile".'
        )
        options.add_argument(
            '-o', '--options', action = 'store',
            help = '"0" for none, "1" for "makeinstances", "2" for "checkoutlines", and "3" for "autohint".'
        )

    def _parse_args(self):
        args = self.parser.parse_args()
        if args.stages:
            stages = str(args.stages)
            self.prepare_styles = True if '1' in stages else False
            self.prepare_features = True if '2' in stages else False
            self.compile = True if '3' in stages else False
        if args.options:
            options = str(args.options)
            self.makeinstances = True if '1' in options else False
            self.checkoutlines = True if '2' in options else False
            self.autohint = True if '3' in options else False

    def _check_master_files(self):
        is_missing = False
        message_lines = ['[WARNING] UFO master files missing:']
        for master in self.family.masters:
            if not os.path.exists(master.path):
                is_missing = True
                message_lines.append('\t' + master.path)
        if is_missing:
            message_lines.extend(['', '[Note] Exit.', ''])
            raise SystemExit('\n'.join(message_lines))

    def set_options(self, options = []):

        for supported_option in [

            'prepare_styles',
            'prepare_features',
            'compile',

            'makeinstances',
            'checkoutlines',
            'autohint',

            'do_style_linking',
            'use_os_2_version_4',
            'prefer_typo_metrics',
            'is_width_weight_slope_only',

            'keep_build_directory',

        ]:
            if supported_option in options:
                self.__dict__[supported_option] = True

    def generate_designspace(self):

        process = subprocess.Popen(
            ['AFDKOPython', 'AFDKOPython/generate_designspace.py'],
            stdin = subprocess.PIPE,
            cwd = kit.__path__[0],
        )
        process.communicate(pickle.dumps(self.family.dump()))

    def generate_fmndb(self):

        f_name = self.family.output_name
        lines = []
        
        for style in self.family.styles:

            lines.append('')
            lines.append('[{}]'.format(style.output_full_name_postscript))
            lines.append('  f = {}'.format(f_name))
            lines.append('  s = {}'.format(style.name))

            l_name = style.output_full_name
            comment_lines = []

            if self.do_style_linking:
                if style.name == 'Regular':
                    l_name = l_name.replace(' Regular', '')
                else:
                    if style.is_bold:
                        comment_lines.append('  # IsBoldStyle')
                        l_name = l_name.replace(' Bold', '')
                    if style.is_italic:
                        comment_lines.append('  # IsItalicStyle')
                        l_name = l_name.replace(' Italic', '')

            if l_name != f_name:
                lines.append('  l = {}'.format(l_name))

            lines.extend(comment_lines)

        with open(kit.paths.FMNDN, 'w') as f:
            f.write(kit.templates.FMNDB_HEAD)
            f.write('\n'.join(lines))
            f.write('\n')

    def reset_build_directory(self):
        print('[Note] Resetting the build directory...\n')
        subprocess.call(['rm', '-fr', kit.paths.BUILD])
        subprocess.call(['mkdir', kit.paths.BUILD])
{'fraction_non_alphanumeric': 0.10899209486166007, 'fraction_numerical': 0.005138339920948616, 'mean_word_length': 1.8663268195978477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3348256', 'n_tokens_mistral': 2970, 'n_tokens_neox': 2864, 'n_words': 643}