mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
Make the setup.py runnable by Python 3 and run 2to3 automatically.
This commit is contained in:
parent
cdb54613bd
commit
f42ac86d91
30
2to3/run.py
Normal file → Executable file
30
2to3/run.py
Normal file → Executable 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
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
rm -f src/version.py # Prevent 2to3 from copying it, since py3k/src/version.py was probably written by root.
|
||||
rm -rf py3k
|
||||
mkdir py3k
|
||||
cp -R locales/ py3k/locales
|
||||
cp -R docs/ py3k/
|
||||
cp -R plugins/ py3k/plugins # 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 "$@"
|
56
setup.py
56
setup.py
@ -32,28 +32,8 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
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)
|
||||
|
||||
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,
|
||||
@ -62,7 +42,6 @@ try:
|
||||
.strip() \
|
||||
.replace(' +', '+') \
|
||||
.replace(' ', 'T')
|
||||
|
||||
except:
|
||||
pass
|
||||
if not version:
|
||||
@ -76,13 +55,40 @@ fd = open(os.path.join('src', 'version.py'), 'a')
|
||||
fd.write("version = '0.83.4.1+limnoria %s'\n" % version)
|
||||
fd.close()
|
||||
|
||||
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
|
||||
@ -103,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',
|
||||
|
Loading…
Reference in New Issue
Block a user