<commit_before># Copyright (C) 2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


'Parse command-line arguments into rules for replacing mounts.'


import argparse
import itertools
flatten = itertools.chain.from_iterable


__all__ = ('extend_arg_parser',)


def extend_arg_parser(ap, argnames=('--replace',), dest='replace'):
    replaceparser = argparse.ArgumentParser()
    replaceparser.add_argument('--filter', nargs='*',
                               action='append', default=[])
    replaceparser.add_argument('--mount-source')
    replaceparser.add_argument('--mount-type')
    replaceparser.add_argument('--mount-options', '-o', nargs='*', action='append',
                               default=[])

    class RecursiveReplaceAction(argparse.Action):
        def __call__(self, subparser, subnamespace, values, option_string=None):
            subns, unparsed = replaceparser.parse_known_args(args=values)

            filters = frozenset(tuple(filter.split('=', 1))
                                for filter in sorted(flatten(subns.filter)))
            mount_options = tuple(flatten(subns.mount_options))

            replacements = getattr(subnamespace, self.dest)
            replacements[filters] = (subns.mount_source, subns.mount_type, mount_options)

            subnamespace._unrecognized_args = unparsed

    replaceparser.add_argument(*argnames, dest=dest, nargs=argparse.REMAINDER,
                               action=RecursiveReplaceAction, default={})

    class ToplevelReplaceAction(argparse.Action):
        def __call__(self, parser, namespace, values, option_string=None):
            subns, unparsed = replaceparser.parse_known_args(args=values)<commit_msg>Default mount source to none, so you aren't required to pass a dummy value for special file system mounts<commit_after># Copyright (C) 2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


'Parse command-line arguments into rules for replacing mounts.'


import argparse
import itertools
flatten = itertools.chain.from_iterable


__all__ = ('extend_arg_parser',)


def extend_arg_parser(ap, argnames=('--replace',), dest='replace'):
    replaceparser = argparse.ArgumentParser()
    replaceparser.add_argument('--filter', nargs='*',
                               action='append', default=[])
    replaceparser.add_argument('--mount-source', default='none')
    replaceparser.add_argument('--mount-type')
    replaceparser.add_argument('--mount-options', '-o', nargs='*', action='append',
                               default=[])

    class RecursiveReplaceAction(argparse.Action):
        def __call__(self, subparser, subnamespace, values, option_string=None):
            subns, unparsed = replaceparser.parse_known_args(args=values)

            filters = frozenset(tuple(filter.split('=', 1))
                                for filter in sorted(flatten(subns.filter)))
            mount_options = tuple(flatten(subns.mount_options))

            replacements = getattr(subnamespace, self.dest)
            replacements[filters] = (subns.mount_source, subns.mount_type, mount_options)

            subnamespace._unrecognized_args = unparsed

    replaceparser.add_argument(*argnames, dest=dest, nargs=argparse.REMAINDER,
                               action=RecursiveReplaceAction, default={})

    class ToplevelReplaceAction(argparse.Action):
        def __call__(self, parser, namespace, values, option_string=None):
            subns, unparsed = replaceparser.parse_known_args(args=values)
{'fraction_non_alphanumeric': 0.09427609427609428, 'fraction_numerical': 0.007154882154882155, 'mean_word_length': 3.433768656716418, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7120723', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1269, 'n_words': 396}