How to use the configargparse.ArgumentTypeError function in ConfigArgParse

To help you get started, we’ve selected a few ConfigArgParse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github smarkets / marge-bot / marge / app.py View on Github external
def regexp(str_regex):
        try:
            return re.compile(str_regex)
        except re.error as err:
            raise configargparse.ArgumentTypeError('Invalid regexp: %r (%s)' % (str_regex, err.msg))
github ska-sa / montblanc / montblanc / impl / rime / slvr_config.py View on Github external
def _init_weights(s):
    """ Handle the None value in VALID_INIT_WEIGHTS """
    if s not in RimeSolverConfig.VALID_INIT_WEIGHTS:
        import configargparse

        raise configargparse.ArgumentTypeError("\'{iw}\'' must be one of {viw}"
            .format(iw=INIT_WEIGHTS, viw=RimeSolverConfig.VALID_INIT_WEIGHTS))

    return s
github iagcl / data_pipeline / data_pipeline / utils / args.py View on Github external
def positive_int_type(x):
    x = int(x)
    if x < 0:
        raise configargparse.ArgumentTypeError("A negative number was supplied")
    return x
github OpenNMT / OpenNMT-py / onmt / opts.py View on Github external
def __call__(self, parser, namespace, values, flag_name):
        help = self.help if self.help is not None else ""
        msg = "Flag '%s' is deprecated. %s" % (flag_name, help)
        raise configargparse.ArgumentTypeError(msg)
github iagcl / data_pipeline / data_pipeline / utils / args.py View on Github external
def commitpoint_type(x):
    x = int(x)
    if x < const.MIN_COMMIT_POINT:
        raise configargparse.ArgumentTypeError(
            "Minimum allowed commitpoint is: {}"
            .format(const.MIN_COMMIT_POINT))

    return x
github michellab / BioSimSpace / python / BioSimSpace / Gateway / _node.py View on Github external
def _str2bool(v):
    """Convert an argument string to a boolean value."""
    if v.lower() in ("yes", "true", "t", "y", "1"):
        return True
    elif v.lower() in ("no", "false", "f", "n", "0"):
        return False
    else:
        raise _argparse.ArgumentTypeError("Boolean value expected.")
github Niger-Volta-LTI / iranlowo / src / onmt / opts.py View on Github external
def __call__(self, parser, namespace, values, flag_name):
        help = self.help if self.help is not None else ""
        msg = "Flag '%s' is deprecated. %s" % (flag_name, help)
        raise configargparse.ArgumentTypeError(msg)
github smarkets / marge-bot / marge / app.py View on Github external
def time_interval(str_interval):
    try:
        quant, unit = re.match(r'\A([\d.]+) ?(h|m(?:in)?|s)?\Z', str_interval).groups()
        translate = {'h': 'hours', 'm': 'minutes', 'min': 'minutes', 's': 'seconds'}
        return timedelta(**{translate[unit or 's']: float(quant)})
    except (AttributeError, ValueError):
        raise configargparse.ArgumentTypeError('Invalid time interval (e.g. 12[s|min|h]): %s' % str_interval)