[SCons] Fix calling 3to2 on Windows with conda 3to2 package

Fixes #408
This commit is contained in:
Bryan W. Weber 2016-12-09 14:54:42 -05:00 committed by Ray Speth
parent 086e640e46
commit 2024d0f08a
2 changed files with 12 additions and 5 deletions

View file

@ -1096,7 +1096,15 @@ if env['python_package'] in ('full','default'):
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')
# Conda installs 3to2 as an EXE file that can be executed directly
# but pip installs only a script. Try executing the EXE file first,
# and if it fails because the file doesn't exist, try the script
try:
ret = getCommandOutput(threetotwo_cmd, '-l')
env['threetotwo_cmd'] = [threetotwo_cmd]
except WindowsError:
ret = getCommandOutput(env['python_cmd'], threetotwo_cmd, '-l')
env['threetotwo_cmd'] = [env['python_cmd'], threetotwo_cmd]
else:
ret = getCommandOutput('3to2' '-l')
except (OSError, subprocess.CalledProcessError) as err:
@ -1108,7 +1116,8 @@ if env['python_package'] in ('full','default'):
env['python_convert_examples'] = True
else:
env['python_convert_examples'] = False
print """WARNING: Couldn't find '3to2'. Python examples will not work correctly."""
print ("WARNING: Couldn't find the 3to2 package. "
"Python 2 examples will not work correctly.")
else:
env['python_module_loc'] = ''

View file

@ -185,9 +185,7 @@ if localenv['python_package'] == 'full':
def convert_example(target, source, env):
shutil.copyfile(source[0].abspath, target[0].abspath)
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',
subprocess.call(env['threetotwo_cmd'] + ['--no-diff', '-n', '-w','-x', 'str',
'-f', 'all', '-f', 'printfunction', '-x', 'print',
'-x', 'open', target[0].abspath])
else: