Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support python interpreter target in pip_import. #312

Merged
merged 3 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion docs/pip.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## pip_import

<pre>
pip_import(<a href="#pip_import-name">name</a>, <a href="#pip_import-extra_pip_args">extra_pip_args</a>, <a href="#pip_import-python_interpreter">python_interpreter</a>, <a href="#pip_import-requirements">requirements</a>, <a href="#pip_import-timeout">timeout</a>)
pip_import(<a href="#pip_import-name">name</a>, <a href="#pip_import-extra_pip_args">extra_pip_args</a>, <a href="#pip_import-python_interpreter">python_interpreter</a>, <a href="#pip_import-python_interpreter_target">python_interpreter_target</a>, <a href="#pip_import-requirements">requirements</a>, <a href="#pip_import-timeout">timeout</a>)
</pre>

A rule for importing `requirements.txt` dependencies into Bazel.
Expand Down Expand Up @@ -86,6 +86,18 @@ wheels.
</p>
</td>
</tr>
<tr id="pip_import-python_interpreter_target">
<td><code>python_interpreter_target</code></td>
<td>
<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; optional
<p>
If you are using a custom python interpreter built by another repository rule,
use this attribute to specify its BUILD target. This allows pip_import to invoke
pip using the same interpreter as your toolchain. If set, takes precedence over
python_interpreter.
</p>
</td>
</tr>
<tr id="pip_import-requirements">
<td><code>requirements</code></td>
<td>
Expand Down
15 changes: 13 additions & 2 deletions python/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ def _pip_import_impl(repository_ctx):
# requirements.bzl without it.
repository_ctx.file("BUILD", "")

interpreter_path = repository_ctx.attr.python_interpreter
if repository_ctx.attr.python_interpreter_target != None:
target = repository_ctx.attr.python_interpreter_target
interpreter_path = repository_ctx.path(target)

args = [
repository_ctx.attr.python_interpreter,
interpreter_path,
repository_ctx.path(repository_ctx.attr._script),
"--python_interpreter",
repository_ctx.attr.python_interpreter,
interpreter_path,
"--name",
repository_ctx.attr.name,
"--input",
Expand Down Expand Up @@ -56,6 +61,12 @@ pip_import = repository_rule(
"python_interpreter": attr.string(default = "python", doc = """
The command to run the Python interpreter used to invoke pip and unpack the
wheels.
"""),
"python_interpreter_target": attr.label(allow_single_file = True, doc = """
If you are using a custom python interpreter built by another repository rule,
use this attribute to specify its BUILD target. This allows pip_import to invoke
pip using the same interpreter as your toolchain. If set, takes precedence over
python_interpreter.
"""),
"requirements": attr.label(
mandatory = True,
Expand Down