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.
This commit is contained in:
Bryan W. Weber 2014-08-25 18:41:56 +00:00
parent 3a6d72346d
commit eeab08d683
2 changed files with 14 additions and 2 deletions

View file

@ -948,7 +948,12 @@ if env['python_package'] in ('full','default'):
# Check for 3to2. See http://pypi.python.org/pypi/3to2
if env['python_package'] == 'full':
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

@ -170,7 +170,14 @@ if localenv['python_package'] == 'full':
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])