diff --git a/python/pip.bzl b/python/pip.bzl index 237b7d2baa..780c05a875 100644 --- a/python/pip.bzl +++ b/python/pip.bzl @@ -13,6 +13,20 @@ # limitations under the License. """Import pip requirements into Bazel.""" + +def python(repository_ctx): + if "BAZEL_PYTHON" in repository_ctx.os.environ: + return repository_ctx.os.environ.get("BAZEL_PYTHON") + + python_path = repository_ctx.which("python") + if not python_path: + python_path = repository_ctx.which("python.exe") + if python_path: + return python_path + + fail("rules_python requires a python interpreter installed. " + + "Please set BAZEL_PYTHON, or put it on your path.") + def _pip_import_impl(repository_ctx): """Core implementation of pip_import.""" @@ -24,7 +38,7 @@ def _pip_import_impl(repository_ctx): # To see the output, pass: quiet=False result = repository_ctx.execute([ - "python", repository_ctx.path(repository_ctx.attr._script), + python(repository_ctx), repository_ctx.path(repository_ctx.attr._script), "--name", repository_ctx.attr.name, "--input", repository_ctx.path(repository_ctx.attr.requirements), "--output", repository_ctx.path("requirements.bzl"), diff --git a/python/whl.bzl b/python/whl.bzl index 496755671f..372c4acc63 100644 --- a/python/whl.bzl +++ b/python/whl.bzl @@ -13,11 +13,24 @@ # limitations under the License. """Import .whl files into Bazel.""" +def python(repository_ctx): + if "BAZEL_PYTHON" in repository_ctx.os.environ: + return repository_ctx.os.environ.get("BAZEL_PYTHON") + + python_path = repository_ctx.which("python") + if not python_path: + python_path = repository_ctx.which("python.exe") + if python_path: + return python_path + + fail("rules_docker requires a python interpreter installed. " + + "Please set BAZEL_PYTHON, or put it on your path.") + def _whl_impl(repository_ctx): """Core implementation of whl_library.""" args = [ - "python", + python(repository_ctx), repository_ctx.path(repository_ctx.attr._script), "--whl", repository_ctx.path(repository_ctx.attr.whl), "--requirements", repository_ctx.attr.requirements,