Add a hack for determining the base_prefix for old-style virtualenvs, however it turns out that the correct value is already in LIBDIR so it may not be needed if we check that first.

This commit is contained in:
Robin Dunn
2016-07-01 13:53:45 -07:00
parent 86357cc0a1
commit 60065b23bf

49
wscript
View File

@@ -332,20 +332,13 @@ def my_check_python_headers(conf):
if isWindows:
libname = 'python' + conf.env['PYTHON_VERSION'].replace('.', '')
libpath = [os.path.join(dct['prefix'], "libs")]
# If we're running in a Py3 style venv then the libpath above is not
# correct, it needs to come from sys.base_prefix instead.
base_prefix = conf.get_python_variables(
["base_prefix"],
["import sys",
"base_prefix = getattr(sys, 'base_prefix')"])[0]
if base_prefix is not None:
if dct['LIBDIR'] and os.path.isdir(dct['LIBDIR']):
libpath = [dct['LIBDIR']]
else:
base_prefix = get_windows_base_prefix(conf, dct['prefix'])
libpath = [os.path.join(base_prefix, "libs")]
# TODO: handle old-style virtualenv too
conf.env['LIBPATH_PYEMBED'] = libpath
conf.env.append_value('LIB_PYEMBED', [libname])
conf.env['LIBPATH_PYEXT'] = conf.env['LIBPATH_PYEMBED']
@@ -408,6 +401,40 @@ def my_check_python_headers(conf):
env.append_value('LINKFLAGS_PYEXT', dist_compiler.ldflags_shared)
def get_windows_base_prefix(conf, default):
# If the python being used for the build in running from a virtual
# environment then sys.prefix will not be the correct path to find
# the Python libs folder.
import waflib.Errors
# If we're running in a Py3 style venv then there is a
# sys.base_prefix we can use instead.
try:
base_prefix = conf.get_python_variables(
["base_prefix"],
["import sys",
"base_prefix = getattr(sys, 'base_prefix')"])[0]
return base_prefix
except waflib.Errors.WafError:
pass
# Otherwise try importing a python library module that should
# always be in the Lib folder (at least for the versions of Python
# we're interested in) and use it's location to figure out the
# real prefix;
# TODO: There has got to be a better way to do this!
try:
base_prefix = conf.get_python_variables(
["base_prefix"],
["import os.path as op",
"import base64",
"base_prefix = op.dirname(op.dirname(base64.__file__))"])[0]
return base_prefix
except waflib.Errors.WafError:
pass
return default
#-----------------------------------------------------------------------------
# Build command