Allow auto conversion of Python examples on Windows

3to2 cannot be called as an executable on Windows, but it can be called
as a script. Assume that the 3to2 script is installed in
PYTHONROOT\Scripts, which is the default for installation by pip.

Cherry-pick of trunk r3113.
This commit is contained in:
Ray Speth 2014-09-10 22:33:09 +00:00
parent b7408c6daa
commit 17c89f8237
2 changed files with 14 additions and 2 deletions

View file

@ -929,7 +929,12 @@ if env['python_package'] in ('full','default','new'):
# See http://pypi.python.org/pypi/3to2
if env['python_package'] == 'new':
try:
ret = getCommandOutput('3to2','-l')
if env['OS'] == 'Windows':
python_dir = os.path.dirname(which(env['python_cmd']))
threetotwo_cmd = pjoin(python_dir, 'Scripts', '3to2')
ret = getCommandOutput(env['python_cmd'], threetotwo_cmd, '-l')
else:
ret = getCommandOutput('3to2', '-l')
except OSError:
ret = ''
if 'print' in ret:

View file

@ -213,7 +213,14 @@ if localenv['python_package'] == 'new':
if env['python_convert_examples']:
def convert_example(target, source, env):
shutil.copyfile(source[0].abspath, target[0].abspath)
subprocess.call(['3to2', '--no-diff', '-n', '-w','-x', 'str',
if env['OS'] == 'Windows':
python_dir = os.path.dirname(which(env['python_cmd']))
threetotwo_cmd = pjoin(python_dir, 'Scripts', '3to2')
subprocess.call([env['python_cmd'], threetotwo_cmd, '--no-diff', '-n', '-w','-x', 'str',
'-f', 'all', '-f', 'printfunction', '-x', 'print',
'-x', 'open', target[0].abspath])
else:
subprocess.call(['3to2', '--no-diff', '-n', '-w','-x', 'str',
'-f', 'all', '-f', 'printfunction', '-x', 'print',
'-x', 'open', target[0].abspath])