Exemple #1
0
        for pat, opt in EXTRA_2TO3_FLAGS.items():
            if fnmatch.fnmatch(fn, pat):
                flag = opt
                break
        flag_sets.setdefault(flag, []).append(dst_fn)

    if patchfile:
        p = open(patchfile, 'wb+')
    else:
        p = open(os.devnull, 'wb')

    for flags, filenames in flag_sets.items():
        if flags == 'skip':
            continue

        _old_stdout = sys.stdout
        try:
            sys.stdout = StringIO()
            lib2to3.main.main("lib2to3.fixes", ['-w', '-n'] + flags.split()+filenames)
        finally:
            sys.stdout = _old_stdout

    for fn, dst_fn in to_convert:
        # perform custom mangling
        custom_mangling(dst_fn)

    p.close()

if __name__ == "__main__":
    main()
Exemple #2
0
                if verbose:
                    print("Updated %s" % new)
    if to_convert:
        print("Have %i python files to convert" % len(to_convert))
        run2to3(to_convert)


def main(python2_source, python3_source, children=["Bio", "BioSQL", "Tests", "Scripts", "Doc"]):
    # Note want to use different folders for Python 3.1, 3.2, etc
    # since the 2to3 libraries have changed so the conversion
    # may differ slightly.
    print("The 2to3 library will be called automatically now,")
    print("and the converted files cached under %s" % python3_source)
    if not os.path.isdir("build"):
        os.mkdir("build")
    if not os.path.isdir(python3_source):
        os.mkdir(python3_source)
    for child in children:
        print("Processing %s" % child)
        do_update(os.path.join(python2_source, child), os.path.join(python3_source, child))
    print("Python 2to3 processing done.")


if __name__ == "__main__":
    python2_source = "."
    python3_source = "build/py%i.%i" % sys.version_info[:2]
    children = ["Bio", "BioSQL", "Tests", "Scripts", "Doc"]
    if len(sys.argv) > 1:
        children = [x for x in sys.argv[1:] if x in children]
    main(python2_source, python3_source, children)
Exemple #3
0
                to_convert.append(new)
                if verbose: print("Will convert %s" % new)
            else:
                if verbose: print("Updated %s" % new)
    if to_convert:
        print("Have %i python files to convert" % len(to_convert))
        run2to3(to_convert)


def main(python2_source,
         python3_source,
         children=["Bio", "BioSQL", "Tests", "Scripts", "Doc"]):
    #Note want to use different folders for Python 3.1, 3.2, etc
    #since the 2to3 libraries have changed so the conversion
    #may differ slightly.
    print("The 2to3 library will be called automatically now,")
    print("and the converted files cached under %s" % python3_source)
    if not os.path.isdir(python3_source):
        os.mkdir(python3_source)
    for child in children:
        print("Processing %s" % child)
        do_update(os.path.join(python2_source, child),
                  os.path.join(python3_source, child))
    print("Python 2to3 processing done.")


if __name__ == "__main__":
    python2_source = "."
    python3_source = "build/py%i.%i" % sys.version_info[:2]
    main(python2_source, python3_source)
Exemple #4
0
        for pat, opt in EXTRA_2TO3_FLAGS.items():
            if fnmatch.fnmatch(fn, pat):
                flag = opt
                break
        flag_sets.setdefault(flag, []).append(dst_fn)

    if patchfile:
        p = open(patchfile, 'wb+')
    else:
        p = open(os.devnull, 'wb')

    for flags, filenames in flag_sets.items():
        if flags == 'skip':
            continue

        _old_stdout = sys.stdout
        try:
            sys.stdout = StringIO()
            lib2to3.main.main("lib2to3.fixes", ['-w'] + flags.split()+filenames)
        finally:
            sys.stdout = _old_stdout

    for fn, dst_fn in to_convert:
        # perform custom mangling
        custom_mangling(dst_fn)

    p.close()

if __name__ == "__main__":
    main()
Exemple #5
0
    fixer_names = requested.difference(unwanted_fixes)
    rt = MyStdRefactoringTool(sorted(fixer_names), flags, sorted(explicit),
                              options.nobackups, not options.no_diffs)
    if options.outfile:
        if len(args) > 2:
            print >> sys.stderr, "-o, --outfile used but multiple script arguments"
        elif not os.path.isfile(args[-1]):
            print >> sys.stderr, "-o, --outfile used but argumnet is a directory"
        else:
            rt.outputfilename = options.outfile

    # Refactor all files and directories passed as arguments
    if not rt.errors:
        if refactor_stdin:
            rt.refactor_stdin()
        else:
            try:
                rt.refactor(args[1:], options.write, options.doctests_only,
                            options.processes)
            except refactor.MultiprocessingUnsupported:
                assert options.processes > 1
                print >> sys.stderr, "Sorry, -j isn't " \
                    "supported on this platform."
                return 1
        rt.summarize()

    # Return error status (0 if rt.errors is zero)
    return int(bool(rt.errors))

sys.exit(main("Orange.fixes", sys.argv))
Exemple #6
0
        print("Have %i python files to convert" % len(to_convert))
        run2to3(to_convert)


def main(python2_source,
         python3_source,
         children=["Bio", "BioSQL", "Tests", "Scripts", "Doc"]):
    #Note want to use different folders for Python 3.1, 3.2, etc
    #since the 2to3 libraries have changed so the conversion
    #may differ slightly.
    print("The 2to3 library will be called automatically now,")
    print("and the converted files cached under %s" % python3_source)
    if not os.path.isdir("build"):
        os.mkdir("build")
    if not os.path.isdir(python3_source):
        os.mkdir(python3_source)
    for child in children:
        print("Processing %s" % child)
        do_update(os.path.join(python2_source, child),
                  os.path.join(python3_source, child))
    print("Python 2to3 processing done.")


if __name__ == "__main__":
    python2_source = "."
    python3_source = "build/py%i.%i" % sys.version_info[:2]
    children = ["Bio", "BioSQL", "Tests", "Scripts", "Doc"]
    if len(sys.argv) > 1:
        children = [x for x in sys.argv[1:] if x in children]
    main(python2_source, python3_source, children)
Exemple #7
0
                #Also run 2to3 on it
                to_convert.append(new)
                if verbose:
                    print("Will convert %s" % new)
            else:
                if verbose:
                    print("Updated %s" % new)
    if to_convert:
        print("Have %i python files to convert" % len(to_convert))
        run2to3(to_convert)

def main(python2_source, python3_source,
         children=["Bio", "BioSQL", "Tests", "Scripts", "Doc"]):
    #Note want to use different folders for Python 3.1, 3.2, etc
    #since the 2to3 libraries have changed so the conversion
    #may differ slightly.
    print("The 2to3 library will be called automatically now,")
    print("and the converted files cached under %s" % python3_source)
    if not os.path.isdir(python3_source):
        os.mkdir(python3_source)
    for child in children:
        print("Processing %s" % child)
        do_update(os.path.join(python2_source, child),
                  os.path.join(python3_source, child))
    print("Python 2to3 processing done.")

if __name__ == "__main__":
    python2_source = "."
    python3_source = "build/py%i.%i" % sys.version_info[:2]
    main(python2_source, python3_source)
Exemple #8
0
        if len(args) > 2:
            print >> sys.stderr, "-o, --outfile used but multiple script arguments"
        elif not os.path.isfile(args[-1]):
            print >> sys.stderr, "-o, --outfile used but argumnet is a directory"
        else:
            rt.outputfilename = options.outfile
        
    # Refactor all files and directories passed as arguments
    if not rt.errors:
        if refactor_stdin:
            rt.refactor_stdin()
        else:
            try:
                rt.refactor(args[1:], options.write, options.doctests_only,
                            options.processes)
            except refactor.MultiprocessingUnsupported:
                assert options.processes > 1
                print >> sys.stderr, "Sorry, -j isn't " \
                    "supported on this platform."
                return 1
        rt.summarize()

    # Return error status (0 if rt.errors is zero)
    return int(bool(rt.errors))

sys.exit(main("Orange.fixes", sys.argv))




Exemple #9
0
def _remove_init_all(r):
    """Remove any __all__ in __init__.py file"""
    new_r = redbaron.NodeList()
    for n in r.node_list:
        if n.type == 'assignment' and n.target.value == '__all__':
            pass
        else:
            new_r.append(n)
    return new_r


def _insert_copyright_header(r):
    for i, n in enumerate(r.node_list):
        if n.type == 'comment' and re.search(r'Copyright.*DataONE', n.value):
            return r
    logging.info('Adding copyright header')
    i = 0
    for n in r('CommentNode', recursive=False)[:3]:
        if n.value.startswith('#!') or 'coding' in n.value:
            # Skip endl node.
            i = n.index_on_parent_raw + 2
    r.node_list.insert(
        i,
        redbaron.RedBaron(
            COPYRIGHT_NOTICE.format(d1_common.date_time.utc_now().year)))
    return r


if __name__ == '__main__':
    sys.exit(main())