Support building against Python 3 (#17)
Add python_version argument to python_configure().
diff --git a/python_configure.bzl b/python_configure.bzl
index 795fa71..8f3eb5e 100644
--- a/python_configure.bzl
+++ b/python_configure.bzl
@@ -156,7 +156,14 @@
python_bin = repository_ctx.os.environ.get(_PYTHON_BIN_PATH)
if python_bin != None:
return python_bin
- python_bin_path = repository_ctx.which("python")
+ if repository_ctx.attr.python_version == "3":
+ python_bin_path = repository_ctx.which("python3")
+ elif repository_ctx.attr.python_version == "2":
+ python_bin_path = repository_ctx.which("python2")
+ elif repository_ctx.attr.python_version == "default":
+ python_bin_path = repository_ctx.which("python")
+ else:
+ _fail("Invalid python_version value, must be '2', '3', or 'default'.")
if python_bin_path != None:
return str(python_bin_path)
_fail("Cannot find python in PATH, please make sure " +
@@ -377,6 +384,9 @@
_PYTHON_BIN_PATH,
_PYTHON_LIB_PATH,
],
+ attrs = {
+ "python_version": attr.string(default="default"),
+ },
)
"""Detects and configures the local Python.
@@ -388,4 +398,10 @@
Args:
name: A unique name for this workspace rule.
+ python_version: If set to "3", will build for Python 3, i.e. will build
+ against the installation corresponding to the binary returned by
+ `which python3`.
+ If set to "2", will build for Python 2 (`which python2`).
+ By default, will build for whatever Python version is returned by
+ `which python`.
"""