本文整理匯總了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
示例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
示例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
示例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