Пример #1
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
Пример #2
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)
Пример #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
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 setup_python2():
    #Blogofile is written for Python 3.
    #But we can also experimentally support Python 2 with lib3to2.
    from lib3to2 import main as three2two
    from distutils import dir_util
    import shutil
    import shlex
    tmp_src = "src_py2"
    try:
        shutil.rmtree(tmp_src)
    except OSError:
        pass #ignore if the directory doesn't exist.
    shutil.copytree("blogofile_blog",os.path.join(tmp_src,"blogofile_blog"))
    three2two.main("lib3to2.fixes",shlex.split(
            "-w {0}".format(tmp_src)))
    return tmp_src
Пример #6
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)))
Пример #7
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)
Пример #8
0
#!/usr/bin/env python
import sys

from lib3to2.main import main

sys.exit(main("lib3to2.fixes"))
Пример #9
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)