示例#1
0
文件: setup.py 项目: avallark/err
def setup_python2():
    from pip import main as mainpip
    mainpip(['install', '3to2'])
    from lib3to2 import main as three2two
    import shutil
    import shlex

    try:
        regenerate = need_to_regenerate()
    except Exception as _:
        regenerate = True  # we need to do it if the dir doesn't exist

    if regenerate:
        for d in src_dirs:
            tmp_src = os.path.join(py2_root, d)
            try:
                shutil.rmtree(tmp_src)
            except OSError:
                pass  # ignore if the directory doesn't exist.

            shutil.copytree(d, tmp_src)
            for fname in all_files_in_rep(tmp_src):
                os.utime(fname, None)

        three2two.main("lib3to2.fixes", shlex.split("-n --no-diffs -w {0}".format(py2_root)))
    else:
        print('Sources already uptodate for python 2')

    return py2_root
示例#2
0
文件: py2conv.py 项目: preoctopus/err
def convert_to_python2():
    """
    Convert errbot source code (which is written for Python 3) to
    Python 2-compatible code (in-place) using lib3to2.
    """
    try:
        from lib3to2 import main as three2two
    except ImportError:
        print(
            "Installing Err under Python 2, which requires 3to2 to be installed, but it was not found"
        )
        print(
            "I will now attempt to install it automatically, but this requires at least pip 1.4 to be installed"
        )
        print(
            "If you get the error 'no such option: --no-clean', please `pip install 3to2` manually and "
            "then `pip install err` again.")

        from pip import main as mainpip
        mainpip(['install', '3to2', '--no-clean'])
        from lib3to2 import main as three2two

    files_to_convert = list(walk_lib3to2_input_sources())
    three2two.main("lib3to2.fixes",
                   ["-n", "--no-diffs", "-w"] + files_to_convert)
示例#3
0
def setup_python2():
    from pip import main as mainpip
    mainpip(['install', '3to2'])
    from lib3to2 import main as three2two
    import shutil
    import shlex

    try:
        regenerate = need_to_regenerate()
    except Exception as _:
        regenerate = True  # we need to do it if the dir doesn't exist

    if regenerate:
        for d in src_dirs:
            tmp_src = os.path.join(py2_root, d)
            try:
                shutil.rmtree(tmp_src)
            except OSError:
                pass  # ignore if the directory doesn't exist.

            shutil.copytree(d, tmp_src)
            for fname in all_files_in_rep(tmp_src):
                os.utime(fname, None)

        three2two.main("lib3to2.fixes",
                       shlex.split("-n --no-diffs -w {0}".format(py2_root)))
    else:
        print('Sources already uptodate for python 2')

    return py2_root
示例#4
0
文件: setup.py 项目: foxxyz/err
def convert_to_python2():
    try:
        from lib3to2 import main as three2two
    except ImportError:
        print("Installing Err under Python 2, which requires 3to2 to be installed, but it was not found")
        print("I will now attempt to install it automatically, but this requires at least pip 1.4 to be installed")
        print("If you get the error 'no such option: --no-clean', please `pip install 3to2` manually and then `pip install err` again.")
        from pip import main as mainpip
        mainpip(['install', '3to2', '--no-clean'])
        from lib3to2 import main as three2two
    import shutil
    import shlex

    for d in src_dirs:
        three2two.main("lib3to2.fixes", shlex.split("-n --no-diffs -w {0}".format(d)))
示例#5
0
def convert_to_python2():
    try:
        from lib3to2 import main as three2two
    except ImportError:
        print("Installing Err under Python 2, which requires 3to2 to be installed, but it was not found")
        print("I will now attempt to install it automatically, but this requires at least pip 1.4 to be installed")
        print("If you get the error 'no such option: --no-clean', please `pip install 3to2` manually and "
              "then `pip install err` again.")
        from pip import main as mainpip

        mainpip(['install', '3to2', '--no-clean'])
        from lib3to2 import main as three2two
    import shlex

    for d in src_dirs:
        three2two.main("lib3to2.fixes", shlex.split("-n --no-diffs -w {0}".format(d)))
示例#6
0
def convert_to_python2():
    """
    Convert errbot source code (which is written for Python 3) to
    Python 2-compatible code (in-place) using lib3to2.
    """
    try:
        from lib3to2 import main as three2two
    except ImportError:
        print("Installing Err under Python 2, which requires 3to2 to be installed, but it was not found")
        print("I will now attempt to install it automatically, but this requires at least pip 1.4 to be installed")
        print("If you get the error 'no such option: --no-clean', please `pip install 3to2` manually and "
              "then `pip install err` again.")

        from pip import main as mainpip
        mainpip(['install', '3to2', '--no-clean'])
        from lib3to2 import main as three2two

    files_to_convert = list(walk_lib3to2_input_sources())
    three2two.main("lib3to2.fixes", ["-n", "--no-diffs", "-w"] + files_to_convert)
示例#7
0
#!/usr/bin/env python

import unittest
import sys

if sys.version_info[0] < 3:
    try:
        from lib3to2 import main as three2two
    except ImportError:
        print('If this keeps happening please install'
              '3to2 yourself with `pip install 3to2 --user`.')
        from pip import main as mainpip
        mainpip(['install', '3to2', 'mock', '--user'])
        from lib3to2 import main as three2two
    three2two.main('lib3to2.fixes', '-n --no-diffs -w paperworks'.split(' '))
    three2two.main('lib3to2.fixes', '-n --no-diffs -w test'.split(' '))

if __name__ == '__main__':
    testsuite = unittest.TestLoader().discover('./test/')
    unittest.TextTestRunner(verbosity=1).run(testsuite)