Make the setup.py runnable by Python 3 and run 2to3 automatically.

Conflicts:
	sandbox/run_2to3.sh
	setup.py
This commit is contained in:
Valentin Lorentz 2013-01-30 20:10:48 +01:00
parent 9e5f7025d8
commit cadf953e86
3 changed files with 59 additions and 31 deletions

30
2to3/run.py Normal file → Executable file
View File

@ -1,6 +1,32 @@
#! /usr/bin/python2.7
#!/usr/bin/env python
import os
import sys
from lib2to3.main import main
import shutil
from glob import glob
try:
from lib2to3.main import main
except ImportError:
print('Error: you need the 2to3 tool to run this script.')
os.chdir(os.path.join(os.path.dirname(__file__), '..'))
try:
os.unlink('src/version.py')
except OSError:
pass
try:
shutil.rmtree('py3k')
except OSError:
pass
os.mkdir('py3k')
for dirname in ('locales', 'docs', 'plugins'):
shutil.copytree(dirname, os.path.join('py3k', dirname))
files = ['run.py', 'src', 'plugins', 'test', 'setup.py'] + glob('scripts/*')
args = ['-wWno', 'py3k']
fixers = []
for fix in ['all', 'def_iteritems', 'def_itervalues', 'def_iterkeys', 'reload']:
fixers += ['-f', fix]
sys.argv = files + args + fixers + sys.argv
sys.argc = len(sys.argv)
import fix_def_iteritems, fix_def_itervalues, fix_def_iterkeys, fix_reload

View File

@ -1,5 +0,0 @@
rm -f src/version.py # Prevent 2to3 from copying it, since py3k/src/version.py was probably written by root.
cp locale/ py3k/ -R
cp docs/ py3k/ -R
cp plugins/ py3k/ -R # copy plugins data
python 2to3/run.py src/ plugins/ test/ scripts/* setup.py -wWno py3k -f all -f def_iteritems -f def_itervalues -f def_iterkeys -f reload "$@"

View File

@ -31,27 +31,8 @@
###
import sys
if sys.version_info < (2, 6, 0):
sys.stderr.write("Supybot requires Python 2.6 or newer.\n")
sys.exit(-1)
import textwrap
clean = False
while '--clean' in sys.argv:
clean = True
sys.argv.remove('--clean')
import glob
import shutil
import os
import subprocess
plugins = [s for s in os.listdir('plugins') if
os.path.exists(os.path.join('plugins', s, 'plugin.py'))]
version = None
try:
proc = subprocess.Popen('git show HEAD --format=%ci', shell=True,
@ -60,7 +41,6 @@ try:
.strip() \
.replace(' +', '+') \
.replace(' ', 'T')
except:
pass
if not version:
@ -75,13 +55,40 @@ open(os.path.join('src', 'version.py'), 'a').write(
from src.version import version
if sys.version_info < (2, 6, 0):
sys.stderr.write("Supybot requires Python 2.6 or newer.")
sys.stderr.write(os.linesep)
sys.exit(-1)
elif sys.version_info[0] >= 3 and \
not os.path.split(os.path.abspath(os.path.dirname(__file__)))[-1] == 'py3k':
# The second condition is used to prevent this script to run recursively
subprocess.Popen([sys.executable, os.path.join('2to3', 'run.py')]).wait()
os.chdir('py3k')
subprocess.Popen([sys.executable] + sys.argv).wait()
import textwrap
clean = False
while '--clean' in sys.argv:
clean = True
sys.argv.remove('--clean')
import glob
import shutil
import os
plugins = [s for s in os.listdir('plugins') if
os.path.exists(os.path.join('plugins', s, 'plugin.py'))]
def normalizeWhitespace(s):
return ' '.join(s.split())
try:
from distutils.core import setup
from distutils.sysconfig import get_python_lib
except ImportError, e:
except ImportError as e:
s = normalizeWhitespace("""Supybot requires the distutils package to
install. This package is normally included with Python, but for some
unfathomable reason, many distributions to take it out of standard Python
@ -102,10 +109,10 @@ if clean:
previousInstall = os.path.join(get_python_lib(), 'supybot')
if os.path.exists(previousInstall):
try:
print 'Removing current installation.'
print('Removing current installation.')
shutil.rmtree(previousInstall)
except Exception, e:
print 'Couldn\'t remove former installation: %s' % e
except Exception as e:
print('Couldn\'t remove former installation: %s' % e)
sys.exit(-1)
packages = ['supybot',