示例#1
0
def print_frame(frame):
    frame = frame if 'frame' in vars() else inspect.currentframe()
    attr_list = ['f_code.co_name', 'f_code.co_filename', 'f_back', 'f_lineno',
                 'f_code.co_names']
    obj_name = 'frame'
    execstr_print_list = ['print("%r=%%r" %% (%s,))' % (_execstr, _execstr)
                          for _execstr in execstr_attr_list(obj_name, attr_list)]
    execstr = '\n'.join(execstr_print_list)
    exec(execstr)
    local_varnames = util_str.pack_into('; '.join(frame.f_locals.keys()))
    print('Local varnames: ' + local_varnames)
    print('--- End Frame ---')
示例#2
0
def print_frame(frame):
    frame = frame if 'frame' in vars() else inspect.currentframe()
    attr_list = ['f_code.co_name', 'f_code.co_filename', 'f_back', 'f_lineno',
                 'f_code.co_names']
    obj_name = 'frame'
    execstr_print_list = ['print("%r=%%r" %% (%s,))' % (_execstr, _execstr)
                          for _execstr in execstr_attr_list(obj_name, attr_list)]
    execstr = '\n'.join(execstr_print_list)
    exec(execstr)
    local_varnames = util_str.pack_into('; '.join(frame.f_locals.keys()))
    print('Local varnames: ' + local_varnames)
    print('--- End Frame ---')
示例#3
0
    def _pack_fromimport(tup):
        name, fromlist = tup[0], tup[1]
        from_module_str = 'from {rootmodname}.{name} import ('.format(rootmodname=rootmodname, name=name)
        newline_prefix = (' ' * len(from_module_str))
        if len(fromlist) > 0:
            rawstr = from_module_str + ', '.join(fromlist) + ',)'
        else:
            rawstr = ''

        # not sure why this isn't 76? >= maybe?
        packstr = util_str.pack_into(rawstr, textwidth=75,
                                     newline_prefix=newline_prefix,
                                    break_words=False)
        return packstr
示例#4
0
    def _pack_fromimport(tup):
        name, fromlist = tup[0], tup[1]
        from_module_str = 'from {rootmodname}.{name} import ('.format(
            rootmodname=rootmodname, name=name)
        newline_prefix = (' ' * len(from_module_str))
        if len(fromlist) > 0:
            rawstr = from_module_str + ', '.join(fromlist) + ',)'
        else:
            rawstr = ''

        # not sure why this isn't 76? >= maybe?
        packstr = util_str.pack_into(rawstr,
                                     textwidth=75,
                                     newline_prefix=newline_prefix,
                                     break_words=False)
        return packstr
示例#5
0
def import_star_execstr(modname, parent=None):
    """
    print(ut.import_star_execstr('opengm.inference'))
    """
    from utool import util_str
    module_vars = import_star(modname, parent=parent)
    fromlist_str = ', '.join(sorted(module_vars.keys()))
    fromimport_prefix = 'from {modname} import ('.format(modname=modname)

    newline_prefix = (' ' * len(fromimport_prefix))
    if fromlist_str:
        rawstr = fromimport_prefix + fromlist_str + ',)'
    else:
        rawstr = ''
    textwidth = 79 - 4
    fromimport_str = util_str.pack_into(rawstr, textwidth=textwidth,
                                        newline_prefix=newline_prefix,
                                        break_words=False)

    # fromimport_str = ut.autopep8_format(fromimport_str, ignore={})
    return fromimport_str