aboutsummaryrefslogtreecommitdiffhomepage
path: root/configure.py
diff options
context:
space:
mode:
Diffstat (limited to 'configure.py')
-rw-r--r--configure.py46
1 files changed, 36 insertions, 10 deletions
diff --git a/configure.py b/configure.py
index 3646670263..5a024fb0e4 100644
--- a/configure.py
+++ b/configure.py
@@ -22,7 +22,6 @@ import errno
import os
import platform
import re
-import site
import subprocess
import sys
@@ -131,16 +130,27 @@ def cygpath(path):
return run_shell('cygpath -m "%s"' % path)
-def get_python_path(environ_cp):
+def get_python_path(environ_cp, python_bin_path):
"""Get the python site package paths."""
python_paths = []
if environ_cp.get('PYTHONPATH'):
python_paths = environ_cp.get('PYTHONPATH').split(':')
try:
- library_paths = site.getsitepackages()
- except AttributeError:
- from distutils.sysconfig import get_python_lib # pylint: disable=g-import-not-at-top
- library_paths = [get_python_lib()]
+ check_input = [
+ python_bin_path, '-c',
+ 'import site; print("\\n".join(site.getsitepackages()))'
+ ]
+ library_paths = subprocess.check_output(check_input).decode(
+ 'UTF-8').strip().split('\n')
+ except subprocess.CalledProcessError:
+ check_input = [
+ python_bin_path, '-c', 'from distutils.sysconfig import get_python_lib;'
+ + 'print(get_python_lib())'
+ ]
+ library_paths = [
+ subprocess.check_output(check_input).decode('UTF-8').strip()
+ ]
+
all_paths = set(python_paths + library_paths)
paths = []
@@ -150,6 +160,12 @@ def get_python_path(environ_cp):
return paths
+def get_python_major_version(python_bin_path):
+ """Get the python major version."""
+ check_input = [python_bin_path, '-c', 'import sys; print(sys.version[0])']
+ return subprocess.check_output(check_input).decode('UTF-8').strip()
+
+
def setup_python(environ_cp, bazel_version):
"""Setup python related env variables."""
# Get PYTHON_BIN_PATH, default is the current running python.
@@ -170,10 +186,14 @@ def setup_python(environ_cp, bazel_version):
print('%s is not executable. Is it the python binary?' % python_bin_path)
environ_cp['PYTHON_BIN_PATH'] = ''
+ # Convert python path to Windows style before checking lib and version
+ if is_windows():
+ python_bin_path = cygpath(python_bin_path)
+
# Get PYTHON_LIB_PATH
python_lib_path = environ_cp.get('PYTHON_LIB_PATH')
if not python_lib_path:
- python_lib_paths = get_python_path(environ_cp)
+ python_lib_paths = get_python_path(environ_cp, python_bin_path)
if environ_cp.get('USE_DEFAULT_PYTHON_LIB_PATH') == '1':
python_lib_path = python_lib_paths[0]
else:
@@ -187,10 +207,10 @@ def setup_python(environ_cp, bazel_version):
python_lib_path = default_python_lib_path
environ_cp['PYTHON_LIB_PATH'] = python_lib_path
- python_major_version = sys.version_info[0]
+ python_major_version = get_python_major_version(python_bin_path)
+
# Convert python path to Windows style before writing into bazel.rc
if is_windows():
- python_bin_path = cygpath(python_bin_path)
python_lib_path = cygpath(python_lib_path)
# Set-up env variables used by python_configure.bzl
@@ -726,9 +746,15 @@ def set_tf_cuda_compute_capabilities(environ_cp):
# Check whether all capabilities from the input is valid
all_valid = True
for compute_capability in tf_cuda_compute_capabilities.split(','):
- if not re.match('[0-9]+.[0-9]+', compute_capability):
+ m = re.match('[0-9]+.[0-9]+', compute_capability)
+ if not m:
print('Invalid compute capability: ' % compute_capability)
all_valid = False
+ else:
+ ver = int(m.group(0).split('.')[0])
+ if ver < 3:
+ print('Only compute capabilities 3.0 or higher are supported.')
+ all_valid = False
if all_valid:
break