diff --git a/README.md b/README.md index 9c44f40d95..e50e81ac90 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,16 @@ load("@io_bazel_rules_python//python:pip.bzl", "pip_import") # This rule translates the specified requirements.txt into # @my_deps//:requirements.bzl, which itself exposes a pip_install method. pip_import( - name = "my_deps", - requirements = "//path/to:requirements.txt", + name = "my_deps", + requirements = "//path/to:requirements.txt", +) + +# Python interpreter can be specify optionally to support customized version, +# such as "python3" or "python3.7" +pip_import( + name = "my_deps", + requirements = "//path/to:requirements.txt", + python_interpreter = 'python3.7', ) # Load the pip_install symbol for my_deps, and create the dependencies' diff --git a/python/pip.bzl b/python/pip.bzl index 9d27794e4d..64e683d132 100644 --- a/python/pip.bzl +++ b/python/pip.bzl @@ -24,8 +24,10 @@ def _pip_import_impl(repository_ctx): # To see the output, pass: quiet=False result = repository_ctx.execute([ - "python", + repository_ctx.attr.python_interpreter, repository_ctx.path(repository_ctx.attr._script), + "--python_interpreter", + repository_ctx.attr.python_interpreter, "--name", repository_ctx.attr.name, "--input", @@ -41,6 +43,7 @@ def _pip_import_impl(repository_ctx): pip_import = repository_rule( attrs = { + "python_interpreter": attr.string(default="python"), "requirements": attr.label( mandatory = True, allow_single_file = True, diff --git a/python/whl.bzl b/python/whl.bzl index 3f869c29ec..2eebfee49f 100644 --- a/python/whl.bzl +++ b/python/whl.bzl @@ -17,7 +17,7 @@ def _whl_impl(repository_ctx): """Core implementation of whl_library.""" args = [ - "python", + repository_ctx.attr.python_interpreter, repository_ctx.path(repository_ctx.attr._script), "--whl", repository_ctx.path(repository_ctx.attr.whl), @@ -37,6 +37,7 @@ def _whl_impl(repository_ctx): whl_library = repository_rule( attrs = { + "python_interpreter": attr.string(default="python"), "whl": attr.label( mandatory = True, allow_single_file = True, diff --git a/rules_python/piptool.py b/rules_python/piptool.py index f5d504aa87..47fc3cdcf7 100644 --- a/rules_python/piptool.py +++ b/rules_python/piptool.py @@ -84,6 +84,9 @@ def pip_main(argv): parser = argparse.ArgumentParser( description='Import Python dependencies into Bazel.') +parser.add_argument('--python_interpreter', action='store', + help=('The python python interpreter to use ')) + parser.add_argument('--name', action='store', help=('The namespace of the import.')) @@ -175,10 +178,12 @@ def whl_library(wheel): if "{repo_name}" not in native.existing_rules(): whl_library( name = "{repo_name}", + python_interpreter = "{python_interpreter}", whl = "@{name}//:{path}", requirements = "@{name}//:requirements.bzl", extras = [{extras}] )""".format(name=args.name, repo_name=wheel.repository_name(), + python_interpreter=args.python_interpreter, path=wheel.basename(), extras=','.join([ '"%s"' % extra diff --git a/tools/piptool.par b/tools/piptool.par index 11ec453cd7..15cb46a098 100755 Binary files a/tools/piptool.par and b/tools/piptool.par differ diff --git a/tools/whltool.par b/tools/whltool.par index 7cb59c0fbe..72e8409e14 100755 Binary files a/tools/whltool.par and b/tools/whltool.par differ