当前位置: 首页>>代码示例>>Python>>正文


Python argh.arg方法代码示例

本文整理汇总了Python中argh.arg方法的典型用法代码示例。如果您正苦于以下问题:Python argh.arg方法的具体用法?Python argh.arg怎么用?Python argh.arg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在argh的用法示例。


在下文中一共展示了argh.arg方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: enable_logging

# 需要导入模块: import argh [as 别名]
# 或者: from argh import arg [as 别名]
def enable_logging(default_loglevel='info', default_file_loglevel='debug'):
    """Adds the parameter ``--loglevel`` and sets up logging

    Args:
      default_loglevel: loglevel used when --loglevel is not passed
    """
    def decorator(func):
        @arg('--loglevel', help="Set logging level (debug, info, warning, error, critical)")
        @arg('--logfile', help="Write log to file")
        @arg('--logfile-level', help="Log level for log file")
        @arg('--log-command-max-lines', help="Limit lines emitted for commands executed")
        @utils.wraps(func)
        def wrapper(*args, loglevel=default_loglevel, logfile=None,
                    logfile_level=default_file_loglevel,
                    log_command_max_lines=None, **kwargs):
            max_lines = int(log_command_max_lines) if log_command_max_lines else None
            utils.setup_logger('bioconda_utils', loglevel, logfile, logfile_level,
                               max_lines)
            func(*args, **kwargs)
        return wrapper
    return decorator 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:23,代码来源:cli.py

示例2: enable_debugging

# 需要导入模块: import argh [as 别名]
# 或者: from argh import arg [as 别名]
def enable_debugging():
    """Adds the paremeter ``--pdb`` (or ``-P``) to enable dropping into PDB"""
    def decorator(func):
        @arg('-P', '--pdb', help="Drop into debugger on exception")
        @utils.wraps(func)
        def wrapper(*args, pdb=False, **kwargs):
            try:
                func(*args, **kwargs)
            except Exception as e:
                logger.exception("Dropping into debugger")
                if pdb:
                    import pdb
                    pdb.post_mortem()
                else:
                    raise
        return wrapper
    return decorator 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:19,代码来源:cli.py

示例3: enable_threads

# 需要导入模块: import argh [as 别名]
# 或者: from argh import arg [as 别名]
def enable_threads():
    """Adds the parameter ``--threads`` (or ``-t``) to limit parallelism"""
    def decorator(func):
        @arg('-t', '--threads', help="Limit maximum number of processes used.")
        @utils.wraps(func)
        def wrapper(*args, threads=16, **kwargs):
            utils.set_max_threads(threads)
            func(*args, **kwargs)
        return wrapper
    return decorator 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:12,代码来源:cli.py

示例4: recipe_folder_and_config

# 需要导入模块: import argh [as 别名]
# 或者: from argh import arg [as 别名]
def recipe_folder_and_config(allow_missing_for=None):
    """Adds optional positional arguments recipe_folder and config

    Requires that func has synopsis ``def x(recipe_folder, config,...)``.
    """
    def check_arg(args, idx, name, default, allow_missing):
        val = args[idx]
        if not val:
            val = default
        if not os.path.exists(val) and not allow_missing:
            sys.exit(f"Argument '{name}' points to missing file '{val}'")
        if val != args[idx]:
            lst = list(args)
            lst[idx] = val
            return tuple(lst)
        return args

    def decorator(func):
        args = inspect.getfullargspec(func).args
        try:
            recipe_folder_idx = args.index('recipe_folder')
            config_idx = args.index('config')
            allow_missing_idx = [args.index(field)
                                 for field in allow_missing_for or []]
        except ValueError:
            sys.exit(f"Function {func} must have 'recipe_folder' and 'config' args")
        @arg('recipe_folder', nargs='?',
             help='Path to folder containing recipes (default: recipes/)')
        @arg('config', nargs='?',
             help='Path to Bioconda config (default: config.yml)')
        @utils.wraps(func)
        def wrapper(*args, **kwargs):
            allow = any(args[idx] for idx in allow_missing_idx)
            args = check_arg(args, recipe_folder_idx, 'recipe_folder', 'recipes/', allow)
            args = check_arg(args, config_idx, 'config', 'config.yml', allow)
            func(*args, **kwargs)
        return wrapper
    return decorator 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:40,代码来源:cli.py


注:本文中的argh.arg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。