Fix selection of the python executable on Windows so virtualenv pythons can be used.

Fix --python

Fix indentation bug in the code setting INCLUDES_PY* in wscript

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73650 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2013-03-14 01:15:00 +00:00
parent b9871f9e66
commit 05608fb3b4
2 changed files with 47 additions and 29 deletions

View File

@@ -170,44 +170,51 @@ def main(args):
def setPythonVersion(args):
# TODO: Should we have a --option for specifying the path to the python
# executable that should be used?
global PYVER
global PYSHORTVER
global PYTHON
global PYTHON_ARCH
havePyVer = False
havePyPath = False
for idx, arg in enumerate(args):
if re.match(r'^[0-9]\.[0-9]$', arg):
havePyVer = True
PYVER = arg
PYSHORTVER = arg[0] + arg[2]
PYTHON = 'python%s' % PYVER
del args[idx]
break
if re.match(r'^[0-9][0-9]$', arg):
havePyVer = True
PYVER = '%s.%s' % (arg[0], arg[1])
PYSHORTVER = arg
PYTHON = 'python%s' % PYVER
del args[idx]
break
if arg.startswith('--python'):
havePyPath = True
if '=' in arg:
PYTHON = arg.split('=')[1]
del args[idx]
else:
PYTHON = args[idx+1]
del args[idx:idx+1]
PYVER = runcmd('%s -c "import sys; print(sys.version[:3)"', getOutput=True, echoCmd=False)
del args[idx:idx+2]
PYVER = runcmd('%s -c "import sys; print(sys.version[:3])"' % PYTHON,
getOutput=True, echoCmd=False)
PYSHORTVER = PYVER[0] + PYVER[2]
break
if not PYTHON:
PYTHON = sys.executable # Use the Python running this script
#'python'+PYVER if not isWindows else 'python.exe' # Use one on the PATH
if isWindows:
if os.environ.get('TOOLS'):
if havePyVer:
if isWindows and os.environ.get('TOOLS'):
# Use $TOOLS to find the correct Python. It should be the install
# root of all Python's on the system, with the 64-bit ones in an
# amd64 subfolder, like this:
#
# $TOOLS\Python27
# $TOOLS\Python33
# $TOOLS\amd64\Python27
# $TOOLS\amd64\Python33
#
TOOLS = os.environ.get('TOOLS')
if 'cygdrive' in TOOLS:
TOOLS = runcmd('c:/cygwin/bin/cygpath -w '+TOOLS, True, False)
@@ -220,21 +227,31 @@ def setPythonVersion(args):
PYTHON = posixjoin(TOOLS,
'python%s' % PYSHORTVER,
'python.exe')
else:
# if TOOLS is not set then default to the python that invoked
# this script
elif isWindows:
# Otherwise check if the invoking Python is the right version
if sys.version[:3] != PYVER:
msg('ERROR: The invoking Python is not the requested version. Perhaps you should use --python')
sys.exit(1)
PYTHON = sys.executable
PYVER = sys.version[:3]
PYSHORTVER = PYVER[0] + PYVER[2]
PYTHON = os.path.abspath(PYTHON)
msg('Using %s' % PYTHON)
elif not isWindows:
# find a pythonX.Y on the PATH
PYTHON = runcmd("which python%s" % PYVER, True, False)
if not PYTHON:
# If no version or path were specified then default to the python
# that invoked this script
PYTHON = sys.executable
PYVER = sys.version[:3]
PYSHORTVER = PYVER[0] + PYVER[2]
PYTHON = os.path.abspath(PYTHON)
msg('Build using: %s' % PYTHON)
else:
findPython = runcmd("which %s" % PYTHON, True, False)
msg('Found %s at %s' % (PYTHON, findPython))
PYTHON = findPython
msg(runcmd('%s -c "import sys; print(sys.version)"' % PYTHON, True, False))
PYTHON_ARCH = runcmd('%s -c "import platform; print(platform.architecture()[0])"'
% PYTHON, True, False)
@@ -242,8 +259,7 @@ def setPythonVersion(args):
os.environ['PYTHON'] = PYTHON
if PYTHON_ARCH == '64bit':
# This may be set already, but there are a couple code paths above
# where it may not be...
# Make sure this is set in case it wasn't above.
os.environ['CPU'] = 'X64'

10
wscript
View File

@@ -278,7 +278,9 @@ def configure(conf):
#
# This is a copy of WAF's check_python_headers with some problematic stuff ripped out.
#
from waflib.Configure import conf
@conf
@@ -371,10 +373,10 @@ def my_check_python_headers(conf):
conf.to_log("\n\n### LIB NOT FOUND\n")
conf.to_log("Include path for Python extensions "
"(found via distutils module): %r\n" % (dct['INCLUDEPY'],))
env['INCLUDES_PYEXT'] = [dct['INCLUDEPY']]
env['INCLUDES_PYEMBED'] = [dct['INCLUDEPY']]
conf.to_log("Include path for Python extensions "
"(found via distutils module): %r\n" % (dct['INCLUDEPY'],))
env['INCLUDES_PYEXT'] = [dct['INCLUDEPY']]
env['INCLUDES_PYEMBED'] = [dct['INCLUDEPY']]
# Code using the Python API needs to be compiled with -fno-strict-aliasing
if env['CC_NAME'] == 'gcc':