Esempio n. 1
0
def ensure_future_compatible(mod_fpath):
    failed_future_list = []
    # Test for print function
    futureline = '^from __future__ import absolute_import, division, print_function, unicode_literals$'
    lines, lineno = ut.grepfile(mod_fpath, futureline)
    if len(lines) == 0:
        print(mod_fpath)
        failed_future_list.append(mod_fpath)
        lines, lineno = ut.grepfile(mod_fpath, futureline)
def ensure_future_compatible(mod_fpath):
    failed_future_list = []
    # Test for print function
    futureline = '^from __future__ import absolute_import, division, print_function$'
    lines, lineno = ut.grepfile(mod_fpath, futureline)
    if len(lines) == 0:
        print(mod_fpath)
        failed_future_list.append(mod_fpath)
        lines, lineno = ut.grepfile(mod_fpath, futureline)
def ensure_six_moves_compatible(mod_fpath):
    six_moves = ['zip', 'map', 'range', 'filter', 'cPickle', 'cStringio', 'zip_longest']
    for funcname in six_moves:
        funcname_regex = r'\b%s\b' % (funcname)
        lines, lineno = ut.grepfile(mod_fpath, funcname_regex)
        if len(lines) > 0:
            six_import = 'from six.moves import .*' + funcname
            lines_, lineno = ut.grepfile(mod_fpath, six_import)
            if len(lines_) == 0:
                print(mod_fpath + ' failed ' + funcname)
                print(lines)
                print(lines_)
Esempio n. 4
0
def check_six_moves_compatibility(mod_fpath):
    six_moves = [
        'zip', 'map', 'range', 'filter', 'cPickle', 'cStringio', 'zip_longest'
    ]
    for funcname in six_moves:
        funcname_regex = r'\b%s\b' % (funcname)
        lines, lineno = ut.grepfile(mod_fpath, funcname_regex)
        if len(lines) > 0:
            six_import = 'from six.moves import .*' + funcname
            lines_, lineno = ut.grepfile(mod_fpath, six_import)
            if len(lines_) == 0:
                print(mod_fpath + ' failed ' + funcname)
                print(lines)
                print(lines_)
Esempio n. 5
0
def ensure_no_invalid_commands(mod_fpath):
    command_list = ['raw_input', '__builtins__', 'xrange', 'izip_longest']
    for funcname in command_list:
        funcname_regex = r'\b%s\b' % (funcname)
        lines, lineno = ut.grepfile(mod_fpath, funcname_regex)
        if len(lines) > 0:
            print(mod_fpath + ' failed ' + funcname)
            print(lines)
def ensure_no_invalid_commands(mod_fpath):
    command_list = ['raw_input', '__builtins__', 'xrange', 'izip_longest']
    for funcname in command_list:
        funcname_regex = r'\b%s\b' % (funcname)
        lines, lineno = ut.grepfile(mod_fpath, funcname_regex)
        if len(lines) > 0:
            print(mod_fpath + ' failed ' + funcname)
            print(lines)
Esempio n. 7
0
def ensure_utool_compatible(mod_fpath):
    ut_inject_line1 = r'print, rrr, profile ='
    ut_inject_line2 = r'\(print, rrr, profile\) ='
    ut_inject_line3 = r'inject2\(__name__,'
    ut_inject_lines = (ut_inject_line1, ut_inject_line2, ut_inject_line3)
    #ut.inject(__name'
    lines, lineno = ut.grepfile(mod_fpath, ut_inject_lines)
    if len(lines) == 0:
        print(mod_fpath + ' does not have utool')
def ensure_utool_compatible(mod_fpath):
    ut_inject_line1 = r'print, print_, printDBG, rrr, profile ='
    ut_inject_line2 = r'\(print, print_, printDBG, rrr, profile\) ='
    ut_inject_line3 = r'inject\(__name__,'
    ut_inject_lines = (ut_inject_line1, ut_inject_line2, ut_inject_line3)
    #ut.inject(__name'
    lines, lineno = ut.grepfile(mod_fpath, ut_inject_lines)
    if len(lines) == 0:
        print(mod_fpath + ' does not have utool')
Esempio n. 9
0
    pattern_items = [
        encoding_line,
        #'from __future__ import absolute_import, division, print_function',
        #'from __future__ import absolute_import, division, print_function, unicode_literals',
    ]

    show_diff = ut.get_argflag('--diff')
    do_write = ut.get_argflag('--write')

    need_encoding_fpaths = []

    for pat in pattern_items:
        print('Checking for pattern: %r' % (pat, ))
        for fpath in fpath_list:
            pattern = re.escape(pat)
            found_lines, found_lxs = ut.grepfile(fpath, pattern)
            # DID NOT FIND ENCODING LINE
            if len(found_lines) == 0:
                need_encoding_fpaths.append(fpath)

    print('The following fpaths need encoding lines: ' +
          ut.list_str(need_encoding_fpaths, strvals=True))

    if do_write or show_diff:
        for fpath in need_encoding_fpaths:
            print('\n-----------------\nFound file without encodeing line: ' +
                  fpath)
            line_list = ut.read_lines_from(fpath)
            linenum = find_encoding_insert_position(line_list)
            if linenum is not None:
                #print(' * linenum = %r' % (linenum,))
Esempio n. 10
0
    pattern_items = [
        encoding_line,
        #'from __future__ import absolute_import, division, print_function',
        #'from __future__ import absolute_import, division, print_function, unicode_literals',
    ]

    show_diff = ut.get_argflag('--diff')
    do_write = ut.get_argflag('--write')

    need_encoding_fpaths = []

    for pat in pattern_items:
        print('Checking for pattern: %r' % (pat,))
        for fpath in fpath_list:
            pattern = re.escape(pat)
            found_lines, found_lxs = ut.grepfile(fpath, pattern)
            # DID NOT FIND ENCODING LINE
            if len(found_lines) == 0:
                need_encoding_fpaths.append(fpath)

    print('The following fpaths need encoding lines: ' + ut.list_str(need_encoding_fpaths, strvals=True))

    if do_write or show_diff:
        for fpath in need_encoding_fpaths:
            print('\n-----------------\nFound file without encodeing line: ' + fpath)
            line_list = ut.read_lines_from(fpath)
            linenum = find_encoding_insert_position(line_list)
            if linenum is not None:
                #print(' * linenum = %r' % (linenum,))
                new_lines = line_list[:linenum] + [encoding_line + '\n'] + line_list[linenum:]
                new_text = ''.join(new_lines)