def closure_devprecmd(func): global DEVPRECMD_FUNCTIONS func_aliases.extend([get_funcname(func)]) DEVPRECMD_FUNCTIONS.append((tuple(func_aliases), func)) def func_wrapper(*args_, **kwargs_): #if ut.VERBOSE: #if ut.QUIET: print('[DEVPRECMD] ' + ut.func_str(func, args_, kwargs_)) return func(*args_, **kwargs_) return func_wrapper
def closure_devprecmd(func): global DEVPRECMD_FUNCTIONS func_aliases.extend([get_funcname(func)]) DEVPRECMD_FUNCTIONS.append((tuple(func_aliases), func)) def func_wrapper(*args_, **kwargs_): # if ut.VERBOSE: # if ut.QUIET: logger.info('[DEVPRECMD] ' + ut.func_str(func, args_, kwargs_)) return func(*args_, **kwargs_) return func_wrapper
def import_cyth_execstr(pyth_modname): """ >>> from cyth.cyth_importer import * # NOQA >>> from vtool import trig # NOQA >>> pyth_modname = 'vtool.trig' """ dummy_cythonized_funcs = import_cyth_default(pyth_modname) pyth_list = [] for funcname, func in dummy_cythonized_funcs.items(): pyth_list.append(funcname + ' = ' + get_funcname(func)) pyth_list2 = utool.align_lines(sorted(pyth_list), '=') try: cyth_list = [] pkgname, fromlist, cyth_modname = pkg_submodule_split(pyth_modname) cythonized_funcs = get_cythonized_funcs(pyth_modname) for funcname, func in cythonized_funcs.items(): cyth_list.append(funcname + ' = ' + cyth_modname + '.' + func.__name__) cyth_list2 = ['import ' + cyth_modname] + utool.align_lines(sorted(cyth_list), '=') except ImportError: cyth_list2 = ['raise ImportError("no cyth")'] except Exception as ex: cyth_list2 = ['raise ImportError("cyth import error: %s")' % str(ex)] cyth_block = utool.indentjoin(cyth_list2).strip() pyth_block = utool.indentjoin(pyth_list2).strip() execstr = utool.unindent( ''' try: if not cyth.WITH_CYTH: raise ImportError('no cyth') {cyth_block} CYTHONIZED = True # print('cyth is on in %s' % (__name__,)) except ImportError: {pyth_block} # print('cyth is off in %s' % (__name__,)) CYTHONIZED = False''').format(**locals()).strip('\n') #print(execstr) if cyth_args.CYTH_WRITE: write_explicit(pyth_modname, execstr) return execstr
def run_devcmds(ibs, qaid_list, daid_list, acfg=None): """ This function runs tests passed in with the -t flag """ print('\n') #print('[dev] run_devcmds') print('==========================') print('[DEV] RUN EXPERIMENTS %s' % ibs.get_dbname()) print('==========================') input_test_list = params.args.tests[:] print('input_test_list = %s' % (ut.list_str(input_test_list),)) # fnum = 1 valid_test_list = [] # build list for printing in case of failure valid_test_helpstr_list = [] # for printing def mark_test_handled(testname): input_test_list.remove(testname) def intest(*args, **kwargs): helpstr = kwargs.get('help', '') valid_test_helpstr_list.append(' -t ' + ', '.join(args) + helpstr) for testname in args: valid_test_list.append(testname) ret = testname in input_test_list ret2 = testname in params.unknown # Let unparsed args count towards tests if ret or ret2: if ret: mark_test_handled(testname) else: ret = ret2 print('\n+===================') print(' [dev] running testname = %s' % (args,)) print('+-------------------\n') return ret return False valid_test_helpstr_list.append(' # --- Simple Tests ---') # Explicit (simple) test functions if intest('export'): export(ibs) if intest('dbinfo'): dbinfo.get_dbinfo(ibs) if intest('headers', 'schema'): ibs.db.print_schema() if intest('info'): print(ibs.get_infostr()) if intest('printcfg'): printcfg(ibs) if intest('tables'): ibs.print_tables() if intest('imgtbl'): ibs.print_image_table() valid_test_helpstr_list.append(' # --- Decor Tests ---') locals_ = locals() # Implicit (decorated) test functions for (func_aliases, func) in DEVCMD_FUNCTIONS: if intest(*func_aliases): funcname = get_funcname(func) #with utool.Indenter('[dev.' + funcname + ']'): with utool.Timer(funcname): #print('[dev] qid_list=%r' % (qaid_list,)) # FIXME: , daid_list if len(ut.get_func_argspec(func).args) == 0: ret = func() else: ret = func(ibs, qaid_list, daid_list) # Add variables returned by the function to the # "local scope" (the exec scop) if hasattr(ret, 'items'): for key, val in ret.items(): if utool.is_valid_varname(key): locals_[key] = val valid_test_helpstr_list.append(' # --- Config Tests ---') # ------ # RUNS EXPERIMENT HARNESS OVER VALID TESTNAMES SPECIFIED WITH -t # ------ # Config driven test functions # Allow any testcfg to be in tests like: vsone_1 or vsmany_3 test_cfg_name_list = [] for test_cfg_name in experiment_configs.TEST_NAMES: if intest(test_cfg_name): test_cfg_name_list.append(test_cfg_name) # Hack to allow for very customized harness tests for testname in input_test_list[:]: if testname.startswith('custom:'): test_cfg_name_list.append(testname) mark_test_handled(testname) if len(test_cfg_name_list): fnum = pt.next_fnum() # Run Experiments # backwards compatibility yo acfgstr_name_list = {'OVERRIDE_HACK': (qaid_list, daid_list)} assert False, 'This way of running tests no longer works. It may be fixed in the future' #acfg harness.test_configurations(ibs, acfgstr_name_list, test_cfg_name_list) valid_test_helpstr_list.append(' # --- Help ---') if intest('help'): print('valid tests are:') print('\n'.join(valid_test_helpstr_list)) return locals_ if len(input_test_list) > 0: print('valid tests are: \n') print('\n'.join(valid_test_list)) raise Exception('Unknown tests: %r ' % input_test_list) return locals_
def run_devcmds(ibs, qaid_list, daid_list, acfg=None): """ This function runs tests passed in with the -t flag """ print('\n') #print('[dev] run_devcmds') print('==========================') print('[DEV] RUN EXPERIMENTS %s' % ibs.get_dbname()) print('==========================') input_test_list = params.args.tests[:] print('input_test_list = %s' % (ut.list_str(input_test_list), )) # fnum = 1 valid_test_list = [] # build list for printing in case of failure valid_test_helpstr_list = [] # for printing def mark_test_handled(testname): input_test_list.remove(testname) def intest(*args, **kwargs): helpstr = kwargs.get('help', '') valid_test_helpstr_list.append(' -t ' + ', '.join(args) + helpstr) for testname in args: valid_test_list.append(testname) ret = testname in input_test_list ret2 = testname in params.unknown # Let unparsed args count towards tests if ret or ret2: if ret: mark_test_handled(testname) else: ret = ret2 print('\n+===================') print(' [dev] running testname = %s' % (args, )) print('+-------------------\n') return ret return False valid_test_helpstr_list.append(' # --- Simple Tests ---') # Explicit (simple) test functions if intest('export'): export(ibs) if intest('dbinfo'): dbinfo.get_dbinfo(ibs) if intest('headers', 'schema'): ibs.db.print_schema() if intest('info'): print(ibs.get_infostr()) if intest('printcfg'): printcfg(ibs) if intest('tables'): ibs.print_tables() if intest('imgtbl'): ibs.print_image_table() valid_test_helpstr_list.append(' # --- Decor Tests ---') locals_ = locals() # Implicit (decorated) test functions for (func_aliases, func) in DEVCMD_FUNCTIONS: if intest(*func_aliases): funcname = get_funcname(func) #with utool.Indenter('[dev.' + funcname + ']'): with utool.Timer(funcname): #print('[dev] qid_list=%r' % (qaid_list,)) # FIXME: , daid_list if len(ut.get_func_argspec(func).args) == 0: ret = func() else: ret = func(ibs, qaid_list, daid_list) # Add variables returned by the function to the # "local scope" (the exec scop) if hasattr(ret, 'items'): for key, val in ret.items(): if utool.is_valid_varname(key): locals_[key] = val valid_test_helpstr_list.append(' # --- Config Tests ---') # ------ # RUNS EXPERIMENT HARNESS OVER VALID TESTNAMES SPECIFIED WITH -t # ------ # Config driven test functions # Allow any testcfg to be in tests like: vsone_1 or vsmany_3 test_cfg_name_list = [] for test_cfg_name in experiment_configs.TEST_NAMES: if intest(test_cfg_name): test_cfg_name_list.append(test_cfg_name) # Hack to allow for very customized harness tests for testname in input_test_list[:]: if testname.startswith('custom:'): test_cfg_name_list.append(testname) mark_test_handled(testname) if len(test_cfg_name_list): fnum = pt.next_fnum() # Run Experiments # backwards compatibility yo acfgstr_name_list = {'OVERRIDE_HACK': (qaid_list, daid_list)} assert False, 'This way of running tests no longer works. It may be fixed in the future' #acfg harness.test_configurations(ibs, acfgstr_name_list, test_cfg_name_list) valid_test_helpstr_list.append(' # --- Help ---') if intest('help'): print('valid tests are:') print('\n'.join(valid_test_helpstr_list)) return locals_ if len(input_test_list) > 0: print('valid tests are: \n') print('\n'.join(valid_test_list)) raise Exception('Unknown tests: %r ' % input_test_list) return locals_
def macro(expander): global MACRO_EXPANDERS_DICT from utool.util_six import get_funcname MACRO_EXPANDERS_DICT[get_funcname(expander)] = expander return expander