本文整理汇总了Python中utool._internal.meta_util_six.get_funcname函数的典型用法代码示例。如果您正苦于以下问题:Python get_funcname函数的具体用法?Python get_funcname怎么用?Python get_funcname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_funcname函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __argv_flag_dec
def __argv_flag_dec(func, default=False, quiet=QUIET):
flag = meta_util_six.get_funcname(func)
if flag.find('no') == 0:
flag = flag[2:]
flag = '--' + flag.replace('_', '-')
def GaurdWrapper(*args, **kwargs):
# FIXME: the --print-all is a hack
default_ = kwargs.pop('default', default)
alias_flags = kwargs.pop('alias_flags', [])
is_flagged = (get_argflag(flag, default_) or
get_argflag('--print-all') or
any([get_argflag(_) for _ in alias_flags]))
if is_flagged:
indent_lbl = flag.replace('--', '').replace('print-', '')
print('')
print('\n+ --- ' + indent_lbl + ' ___')
#with util_print.Indenter('[%s]' % indent_lbl):
ret = func(*args, **kwargs)
print('L ___ ' + indent_lbl + '___\n')
return ret
else:
if not quiet:
print('\n~~~ %s ~~~' % flag)
meta_util_six.set_funcname(GaurdWrapper, meta_util_six.get_funcname(func))
return GaurdWrapper
开发者ID:animalus,项目名称:utool,代码行数:26,代码来源:util_arg.py
示例2: _generate_serial
def _generate_serial(func, args_list, prog=True, verbose=True, nTasks=None,
quiet=QUIET, **kwargs):
""" internal serial generator """
if nTasks is None:
nTasks = len(args_list)
if verbose and not quiet:
print('[util_parallel._generate_serial] executing %d %s tasks in serial' %
(nTasks, get_funcname(func)))
prog = prog and verbose and nTasks > 1
# Get iterator with or without progress
verbose = verbose or not quiet
lbl = '(sergen) %s: ' % (get_funcname(func),)
args_iter = (
util_progress.ProgressIter(args_list, nTotal=nTasks,
lbl=lbl,
freq=kwargs.get('freq', None),
adjust=kwargs.get('adjust', False),
verbose=verbose)
if prog else args_list
)
if __TIME_GENERATE__:
tt = util_time.tic('_generate_serial func=' + get_funcname(func))
for args in args_iter:
result = func(args)
yield result
if __TIME_GENERATE__:
util_time.toc(tt)
开发者ID:Erotemic,项目名称:utool,代码行数:27,代码来源:util_parallel.py
示例3: process
def process(func, args_list, args_dict={}, force_serial=None,
nTasks=None, quiet=QUIET):
"""
Use ut.generate rather than ut.process
Args:
func (func):
args_list (list or iter):
args_dict (dict):
force_serial (bool):
Returns:
result of parallel map(func, args_list)
CommandLine:
python -m utool.util_parallel --test-process
Example:
>>> # SLOW_DOCTEST
>>> import utool as ut
>>> num = 8700 # parallel is slower for smaller numbers
>>> flag_generator0 = ut.process(ut.is_prime, list(zip(range(0, num))), force_serial=True)
>>> flag_list0 = list(flag_generator0)
>>> flag_generator1 = ut.process(ut.is_prime, list(zip(range(0, num))), force_serial=False)
>>> flag_list1 = list(flag_generator1)
>>> assert flag_list0 == flag_list1
"""
if __FORCE_SERIAL__:
force_serial = __FORCE_SERIAL__
if FUTURE_ON:
raise AssertionError('USE FUTURES')
if USE_GLOBAL_POOL:
ensure_pool(quiet=quiet)
if nTasks is None:
nTasks = len(args_list)
if __POOL__ == 1 or force_serial:
if not quiet:
print('[util_parallel] executing %d %s tasks in serial' %
(nTasks, get_funcname(func)))
result_list = _process_serial(func, args_list, args_dict, nTasks=nTasks,
quiet=quiet)
else:
if __POOL__ is None:
pool = new_pool(num_procs=get_default_numprocs(),
init_worker=init_worker,
maxtasksperchild=None)
else:
pool = __POOL__
if not quiet:
print('[util_parallel] executing %d %s tasks using %d processes' %
(nTasks, get_funcname(func), pool._processes))
result_list = _process_parallel(func, args_list, args_dict, nTasks=nTasks,
quiet=quiet, pool=pool)
return result_list
开发者ID:Erotemic,项目名称:utool,代码行数:55,代码来源:util_parallel.py
示例4: wrp_adder
def wrp_adder(*args, **kwargs):
if DEBUG_ADDERS or VERB_CONTROL:
print('+------')
print('[ADD]: ' + get_funcname(func))
funccall_str = ut.func_str(func, args, kwargs, packed=True)
print('\n' + funccall_str + '\n')
print('L------')
if VERB_CONTROL:
print('[ADD]: ' + get_funcname(func))
builtins.print('\n' + ut.func_str(func, args, kwargs) + '\n')
return func_(*args, **kwargs)
开发者ID:heroinlin,项目名称:ibeis,代码行数:11,代码来源:accessor_decors.py
示例5: wrp_interested
def wrp_interested(*args, **kwargs):
sys.stdout.write('#\n')
sys.stdout.write('#\n')
sys.stdout.write(
'<!INTERESTED>: ' + meta_util_six.get_funcname(func) + '\n')
print('INTERESTING... ' + (' ' * 30) + ' <----')
return func(*args, **kwargs)
开发者ID:Erotemic,项目名称:utool,代码行数:7,代码来源:util_decor.py
示例6: checkinfo_wrapper
def checkinfo_wrapper(*args, **kwargs):
suggested_fix = ''
funcname = get_funcname(func)
packagename = funcname.replace('_version', '')
pipname_ = pipname if pipname is not None else packagename
try:
infodict = func(*args, **kwargs)
except ImportError as ex:
infodict = module_stdinfo_dict(None, name=pipname_)
suggested_fix = 'pip install ' + pipname_
if not sys.platform.startswith('win32'):
suggested_fix = 'sudo ' + suggested_fix
return False, 'None', target, infodict, ut.formatex(ex), suggested_fix
except Exception as ex:
infodict = module_stdinfo_dict(None, name=pipname_)
return False, 'None', target, infodict, ut.formatex(ex), 'Some unknown error in ' + packagename
current_version = infodict['__version__']
# Build status text
msg = ut.dict_str(infodict, strvals=True)
msg += '\n' + '%s: %r >= (target=%r)?' % (funcname, current_version, target)
statustext = ut.msgblock(infodict['__name__'], msg)
# Check if passed
passed = version_ge_target(current_version, target)
# Suggest possible fix
if not passed:
suggested_fix = 'pip install ' + infodict['__name__'] + ' --upgrade'
if not sys.platform.startswith('win32'):
suggested_fix = 'sudo ' + suggested_fix
return passed, current_version, target, infodict, statustext, suggested_fix
开发者ID:Erotemic,项目名称:ibeis,代码行数:29,代码来源:assert_modules.py
示例7: _process_parallel
def _process_parallel(func, args_list, args_dict={}, nTasks=None):
"""
Parallel process map
Use generate instead
"""
# Define progress observers
if nTasks is None:
nTasks = len(args_list)
num_tasks_returned_ptr = [0]
mark_prog, end_prog = util_progress.progress_func(
max_val=nTasks, lbl=get_funcname(func) + ': ')
def _callback(result):
mark_prog(num_tasks_returned_ptr[0])
sys.stdout.flush()
num_tasks_returned_ptr[0] += 1
# Send all tasks to be executed asynconously
apply_results = [__POOL__.apply_async(func, args, args_dict, _callback)
for args in args_list]
# Wait until all tasks have been processed
while num_tasks_returned_ptr[0] < nTasks:
#print('Waiting: ' + str(num_tasks_returned_ptr[0]) + '/' + str(nTasks))
pass
end_prog()
# Get the results
result_list = [ap.get() for ap in apply_results]
if __EAGER_JOIN__:
close_pool()
return result_list
开发者ID:animalus,项目名称:utool,代码行数:29,代码来源:util_parallel.py
示例8: __argv_flag_dec
def __argv_flag_dec(func, default=False, quiet=QUIET, indent=False):
"""
Logic for controlling if a function gets called based on command line
"""
from utool import util_decor
flagname = meta_util_six.get_funcname(func)
if flagname.find('no') == 0:
flagname = flagname[2:]
flags = (
'--' + flagname.replace('_', '-'),
'--' + flagname,
)
@util_decor.ignores_exc_tb(outer_wrapper=False)
def GaurdWrapper(*args, **kwargs):
from utool import util_print
# FIXME: the --print-all is a hack
default_ = kwargs.pop('default', default)
alias_flags = kwargs.pop('alias_flags', [])
is_flagged = (get_argflag(flags, default_) or
get_argflag('--print-all') or
any([get_argflag(_) for _ in alias_flags]))
if flagname in kwargs:
is_flagged = kwargs.pop(flagname)
if is_flagged:
func_label = flags[0].replace('--', '').replace('print-', '')
# print('')
print('\n+ --- ' + func_label + ' ___')
use_indent = indent is not False
if indent is True:
indent_ = '[%s]' % func_label
else:
indent_ = indent
with util_print.Indenter(indent_, enabled=use_indent):
ret = func(*args, **kwargs)
print('L ___ ' + func_label + '___\n')
return ret
else:
PRINT_DISABLED_FLAGDEC = not get_argflag(
'--noinform', help_='does not print disabled flag decorators')
if not quiet and PRINT_DISABLED_FLAGDEC:
#print('\n~~~ %s ~~~' % flag)
print('~~~ %s ~~~' % flags[0])
meta_util_six.set_funcname(GaurdWrapper, meta_util_six.get_funcname(func))
return GaurdWrapper
开发者ID:Erotemic,项目名称:utool,代码行数:46,代码来源:util_arg.py
示例9: tracefunc
def tracefunc(func):
lbl = '[trace.' + meta_util_six.get_funcname(func) + ']'
def wrp_tracefunc(*args, **kwargs):
print(lbl + ' +--- ENTER ---')
with util_print.Indenter(lbl + ' |'):
ret = func(*args, **kwargs)
print(lbl + ' L___ EXIT ____')
return ret
return wrp_tracefunc
开发者ID:animalus,项目名称:utool,代码行数:9,代码来源:util_decor.py
示例10: checkqterr_wrapper
def checkqterr_wrapper(self, *args, **kwargs):
try:
result = func(self, *args, **kwargs)
except Exception as ex:
funcname = meta_util_six.get_funcname(func)
msg = 'caught exception in %r' % (funcname,)
ut.printex(ex, msg, tb=True, pad_stdout=True)
raise
return result
开发者ID:Erotemic,项目名称:guitool,代码行数:9,代码来源:guitool_decorators.py
示例11: __new__
def __new__(cls, name, bases, dct):
"""
Args:
cls (type): meta
name (str): classname
supers (list): bases
dct (dict): class dictionary
"""
method_list = get_comparison_methods()
for func in method_list:
if get_funcname(func) not in dct:
funcname = get_funcname(func)
dct[funcname] = func
else:
funcname = get_funcname(func)
dct['meta_' + funcname] = func
#ut.inject_func_as_method(metaself, func)
return type.__new__(cls, name, bases, dct)
开发者ID:Erotemic,项目名称:utool,代码行数:18,代码来源:util_class.py
示例12: _inject_funcs
def _inject_funcs(module, *func_list):
for func in func_list:
if (module is not None and
hasattr(module, '__name__') and
module.__name__ not in __INJECT_BLACKLIST__ and
not module.__name__.startswith('six') and
not module.__name__.startswith('sys')):
#print('setting: %s.%s = %r' % (module.__name__, meta_util_six.get_funcname(func), func))
setattr(module, meta_util_six.get_funcname(func), func)
开发者ID:animalus,项目名称:utool,代码行数:9,代码来源:util_inject.py
示例13: ex_wrapper
def ex_wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as ex:
import utool
msg = ('[tools] ERROR: %s(%r, %r)' % (meta_util_six.get_funcname(func), args, kwargs))
#print(msg)
utool.printex(ex, msg)
#print('[tools] ERROR: %r' % ex)
raise
开发者ID:animalus,项目名称:utool,代码行数:10,代码来源:util_dbg.py
示例14: _generate_parallel
def _generate_parallel(func, args_list, ordered=True, chunksize=1,
prog=True, verbose=True, nTasks=None, freq=None):
"""
Parallel process generator
"""
prog = prog and verbose
if nTasks is None:
nTasks = len(args_list)
if chunksize is None:
chunksize = max(1, nTasks // (__POOL__._processes ** 2))
if verbose:
prefix = '[util_parallel._generate_parallel]'
fmtstr = prefix + 'executing %d %s tasks using %d processes with chunksize=%r'
print(fmtstr % (nTasks, get_funcname(func), __POOL__._processes, chunksize))
pmap_func = __POOL__.imap if ordered else __POOL__.imap_unordered
raw_generator = pmap_func(func, args_list, chunksize)
# Get iterator with or without progress
result_generator = (
util_progress.ProgressIter(raw_generator, nTotal=nTasks, lbl=get_funcname(func) + ': ', freq=freq)
if prog else raw_generator
)
if __TIME_GENERATE__:
tt = util_time.tic('_generate_parallel func=' + get_funcname(func))
try:
for result in result_generator:
yield result
if __EAGER_JOIN__:
close_pool()
except Exception as ex:
util_dbg.printex(ex, 'Parallel Generation Failed!', '[utool]', tb=True)
if __EAGER_JOIN__:
close_pool()
print('__SERIAL_FALLBACK__ = %r' % __SERIAL_FALLBACK__)
if __SERIAL_FALLBACK__:
print('Trying to handle error by falling back to serial')
serial_generator = _generate_serial(
func, args_list, prog=prog, verbose=verbose, nTasks=nTasks, freq=freq)
for result in serial_generator:
yield result
else:
raise
if __TIME_GENERATE__:
util_time.toc(tt)
开发者ID:animalus,项目名称:utool,代码行数:43,代码来源:util_parallel.py
示例15: __new__
def __new__(cls, name, bases, dct):
"""
cls - meta
name - classname
supers - bases
dct - class dictionary
"""
#assert 'get_cfgstr_list' in dct, (
# 'must have defined get_cfgstr_list. name=%r' % (name,))
# Inject registered function
for func in methods_list:
if get_funcname(func) not in dct:
funcname = get_funcname(func)
dct[funcname] = func
else:
funcname = get_funcname(func)
dct['meta_' + funcname] = func
#ut.inject_func_as_method(metaself, func)
return type.__new__(cls, name, bases, dct)
开发者ID:Erotemic,项目名称:ibeis,代码行数:19,代码来源:Config.py
示例16: pyqtSlotWrapper
def pyqtSlotWrapper(func):
#printDBG('[GUITOOL._SLOT] Wrapping: %r' % func.__name__)
funcname = meta_util_six.get_funcname(func)
@QtCore.pyqtSlot(*types, name=funcname)
@ut.ignores_exc_tb
def slot_wrapper(self, *args, **kwargs):
result = func(self, *args, **kwargs)
return result
slot_wrapper = functools.update_wrapper(slot_wrapper, func)
return slot_wrapper
开发者ID:Erotemic,项目名称:guitool,代码行数:10,代码来源:guitool_decorators.py
示例17: process
def process(func, args_list, args_dict={}, force_serial=__FORCE_SERIAL__,
nTasks=None):
"""
Use ut.generate rather than ut.process
Args:
func (func):
args_list (list or iter):
args_dict (dict):
force_serial (bool):
Returns:
result of parallel map(func, args_list)
CommandLine:
python -m utool.util_parallel --test-process
Example:
>>> # SLOW_DOCTEST
>>> import utool as ut
>>> num = 8700 # parallel is slower for smaller numbers
>>> flag_generator0 = ut.process(ut.is_prime, zip(range(0, num)), force_serial=True)
>>> flag_list0 = list(flag_generator0)
>>> flag_generator1 = ut.process(ut.is_prime, zip(range(0, num)), force_serial=False)
>>> flag_list1 = list(flag_generator1)
>>> assert flag_list0 == flag_list1
"""
ensure_pool()
if nTasks is None:
nTasks = len(args_list)
if __POOL__ == 1 or force_serial:
if not QUIET:
print('[util_parallel] executing %d %s tasks in serial' %
(nTasks, get_funcname(func)))
result_list = _process_serial(func, args_list, args_dict, nTasks=nTasks)
else:
if not QUIET:
print('[util_parallel] executing %d %s tasks using %d processes' %
(nTasks, get_funcname(func), __POOL__._processes))
result_list = _process_parallel(func, args_list, args_dict, nTasks=nTasks)
return result_list
开发者ID:animalus,项目名称:utool,代码行数:42,代码来源:util_parallel.py
示例18: _generate_serial
def _generate_serial(func, args_list, prog=True, verbose=True, nTasks=None, freq=None):
""" internal serial generator """
if nTasks is None:
nTasks = len(args_list)
if verbose:
print('[util_parallel._generate_serial] executing %d %s tasks in serial' %
(nTasks, get_funcname(func)))
prog = prog and verbose and nTasks > 1
# Get iterator with or without progress
args_iter = (
util_progress.ProgressIter(args_list, nTotal=nTasks, lbl=get_funcname(func) + ': ', freq=freq)
if prog else args_list
)
if __TIME_GENERATE__:
tt = util_time.tic('_generate_serial func=' + get_funcname(func))
for args in args_iter:
result = func(args)
yield result
if __TIME_GENERATE__:
util_time.toc(tt)
开发者ID:animalus,项目名称:utool,代码行数:20,代码来源:util_parallel.py
示例19: wrp_getter
def wrp_getter(*args, **kwargs):
# if ut.DEBUG:
# print('[IN GETTER] args=%r' % (args,))
# print('[IN GETTER] kwargs=%r' % (kwargs,))
if DEBUG_GETTERS or VERB_CONTROL:
print("+------")
print("[GET]: " + get_funcname(func))
funccall_str = ut.func_str(func, args, kwargs, packed=True)
print("\n" + funccall_str + "\n")
print("L------")
return func_(*args, **kwargs)
开发者ID:Erotemic,项目名称:ibeis,代码行数:11,代码来源:accessor_decors.py
示例20: wrp_setter
def wrp_setter(*args, **kwargs):
if DEBUG_SETTERS or VERB_CONTROL:
print("+------")
print("[SET]: " + get_funcname(func))
print("[SET]: called by: " + ut.get_caller_name(range(1, 7)))
funccall_str = ut.func_str(func, args, kwargs, packed=True)
print("\n" + funccall_str + "\n")
print("L------")
# builtins.print('\n' + funccall_str + '\n')
# print('set: funcname=%r, args=%r, kwargs=%r' % (get_funcname(func), args, kwargs))
return func_(*args, **kwargs)
开发者ID:Erotemic,项目名称:ibeis,代码行数:11,代码来源:accessor_decors.py
注:本文中的utool._internal.meta_util_six.get_funcname函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论