setup.py: Add the --debug switch.

This commit is contained in:
Valentin Lorentz 2013-02-22 20:50:38 +01:00
parent 29421f3cd7
commit 3e26a2d7cf

View File

@ -34,7 +34,11 @@ import sys
import tempfile import tempfile
import subprocess import subprocess
debug = '--debug' in sys.argv
path = os.path.dirname(__file__) path = os.path.dirname(__file__)
if debug:
print('DEBUG: Changing dir from %r to %r' % (os.getcwd(), path))
if path: if path:
os.chdir(path) os.chdir(path)
@ -64,19 +68,32 @@ if sys.version_info < (2, 6, 0):
sys.stderr.write("Supybot requires Python 2.6 or newer.") sys.stderr.write("Supybot requires Python 2.6 or newer.")
sys.stderr.write(os.linesep) sys.stderr.write(os.linesep)
sys.exit(-1) sys.exit(-1)
elif sys.version_info[0] >= 3 and \ elif sys.version_info[0] >= 3:
not os.path.split(os.path.abspath(os.path.dirname(__file__)))[-1] == 'py3k': if os.path.split(os.path.abspath(os.path.dirname(__file__)))[-1] == 'py3k':
# The second condition is used to prevent this script to run recursively if debug:
print('Converting code from Python 2 to Python 3. This make take a ' print('DEBUG: Running setup.py with Python 3: second stage.')
'few minutes.') while '--debug' in sys.argv:
# For some reason, using open(os.devnull) makes the subprocess exit before sys.argv.remove('--debug')
# it finishes... else:
subprocess.Popen([sys.executable, os.path.join('2to3', 'run.py')], if debug:
stdout=tempfile.TemporaryFile(), print('DEBUG: Running setup.py with Python 3: first stage.')
stderr=tempfile.TemporaryFile()).wait() print('Converting code from Python 2 to Python 3. This make take a '
os.chdir('py3k') 'few minutes.')
subprocess.Popen([sys.executable] + sys.argv).wait() # For some reason, using open(os.devnull) makes the subprocess exit before
exit() # it finishes...
subprocess.Popen([sys.executable, os.path.join('2to3', 'run.py')],
stdout=tempfile.TemporaryFile(),
stderr=tempfile.TemporaryFile()).wait()
if debug:
print('DEBUG: Changing dir to py3k/')
os.chdir('py3k')
if debug:
print('DEBUG: Running %r' % ([sys.executable] + sys.argv))
subprocess.Popen([sys.executable] + sys.argv).wait()
exit()
else:
while '--debug' in sys.argv:
sys.argv.remove('--debug')
import textwrap import textwrap