<commit_before>import re
import sys
import inspect

from optparse import OptionParser
from optparse import make_option


def to_OptionParser(options, usage=None):
    # add options, automatically detecting their -short and --long names

    single_char_prefix_re = re.compile('^[a-zA-Z0-9]_')

    optypes=[int, long, float, complex] # not type='choice' choices='a|b'
    def optype(t):
        if t is bool:
            return None
        if t in optypes:
            return t
        return "string"

    # TODO:
    # helpdict = getattr(func, 'optfunc_arghelp', {})
    helpdict = {}

    opt = OptionParser(usage)

    shortnames = set(['h'])
    for name in options.iterkeys():
        if single_char_prefix_re.match(name):
            shortnames.add(name[0])

    for original, default in options.iteritems():
        name = original
        # x_argument forces short name for argument to be x
        if single_char_prefix_re.match(name):
            short = name[0]
            name = name[2:]
            opt._custom_names[name] = original

        # or we pick the first letter from the name not already in use:
        else:
            short=None
            for s in name:
                if s not in shortnames:
                    short=s
                    break
        names = []
        if short is not None:
            shortnames.add(short)
            short_name = '-%s' % short
            names.append(short_name)

        clean_name = name.replace('_', '-')
        long_name = '--%s' % clean_name
        names.append(long_name)

        if isinstance(default, bool):
            no_name='--no%s' % clean_name
            opt.add_option(make_option(
                no_name,
                action='store_false',
                dest=name,
                help = helpdict.get(original, 'unset %s' % long_name)))
            action = 'store_true'

        else:
            action = 'store'

        example = str(default)
        if isinstance(default, int):
            if default==sys.maxint: example = "INFINITY"
            if default==(-sys.maxint-1): example = "-INFINITY"

        help_post = ' (default: %s)' % example

        opt.add_option(make_option(*names,
            action=action,
            dest=name,
            default=default,
            help=helpdict.get(original, '') + help_post,
            type=optype(type(default))))

    return opt


def get_interface(target):<commit_msg>don't show --no option for boolean arguments that are False by default<commit_after>import re
import sys
import inspect

from optparse import OptionParser
from optparse import make_option


def to_OptionParser(options, usage=None):
    # add options, automatically detecting their -short and --long names

    single_char_prefix_re = re.compile('^[a-zA-Z0-9]_')

    optypes=[int, long, float, complex] # not type='choice' choices='a|b'
    def optype(t):
        if t is bool:
            return None
        if t in optypes:
            return t
        return "string"

    # TODO:
    # helpdict = getattr(func, 'optfunc_arghelp', {})
    helpdict = {}

    opt = OptionParser(usage)

    shortnames = set(['h'])
    for name in options.iterkeys():
        if single_char_prefix_re.match(name):
            shortnames.add(name[0])

    for original, default in options.iteritems():
        name = original
        # x_argument forces short name for argument to be x
        if single_char_prefix_re.match(name):
            short = name[0]
            name = name[2:]
            opt._custom_names[name] = original

        # or we pick the first letter from the name not already in use:
        else:
            short=None
            for s in name:
                if s not in shortnames:
                    short=s
                    break
        names = []
        if short is not None:
            shortnames.add(short)
            short_name = '-%s' % short
            names.append(short_name)

        clean_name = name.replace('_', '-')
        long_name = '--%s' % clean_name
        names.append(long_name)

        if isinstance(default, bool):
            if default:
                no_name='--no%s' % clean_name
                opt.add_option(make_option(
                    no_name,
                    action='store_false',
                    dest=name,
                    help = helpdict.get(original, 'unset %s' % long_name)))
                continue

            action = 'store_true'

        else:
            action = 'store'

        example = str(default)
        if isinstance(default, int):
            if default==sys.maxint: example = "INFINITY"
            if default==(-sys.maxint-1): example = "-INFINITY"

        help_post = ' (default: %s)' % example

        opt.add_option(make_option(*names,
            action=action,
            dest=name,
            default=default,
            help=helpdict.get(original, '') + help_post,
            type=optype(type(default))))

    return opt


def get_interface(target):
{'fraction_non_alphanumeric': 0.1017017017017017, 'fraction_numerical': 0.0024024024024024023, 'mean_word_length': 1.7879464285714286, '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': '851524', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1383, 'n_words': 375}