Skip to content

Commit

Permalink
Simplify checking for 3to2
Browse files Browse the repository at this point in the history
Switch to importing the lib3to2 as a check, which is platform agnostic
and doesn't depend on how 3to2 was installed
  • Loading branch information
bryanwweber committed Nov 13, 2017
1 parent 77205d9 commit c501b2e
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -1294,23 +1294,13 @@ for py_ver in [2, 3]:
# Check for 3to2. See http://pypi.python.org/pypi/3to2
# Only needed for Python 2 package
if env['python2_package'] == 'full':
from textwrap import dedent
script = dedent("""\
from lib3to2.main import main
print(main('lib3to2.fixes', ['-l']))
""")
try:
python_dir = os.path.dirname(which(env['python2_cmd']))
if env['OS'] == 'Windows':
threetotwo_cmd = pjoin(python_dir, 'Scripts', '3to2')
# 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['python2_cmd'], threetotwo_cmd, '-l')
env['threetotwo_cmd'] = [env['python2_cmd'], threetotwo_cmd]
else:
threetotwo_cmd = pjoin(python_dir, '3to2')
ret = getCommandOutput(threetotwo_cmd, '-l')
env['threetotwo_cmd'] = [threetotwo_cmd]
ret = getCommandOutput(env['python2_cmd'], '-c', script)
except (OSError, subprocess.CalledProcessError) as err:
if env['VERBOSE']:
print('Error checking for 3to2:')
Expand Down

0 comments on commit c501b2e

Please sign in to comment.