Skip to content
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
13 changes: 11 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ load("@io_bazel_skydoc//skylark:skylark.bzl", "skydoc_repositories")

skydoc_repositories()

# Python
load("//:python/def.bzl", "python_toolchain_repository")
python_toolchain_repository(
name = "python2",
path = "/usr/bin/python2",
)

# Requirements for building our piptool.
load("//python:pip.bzl", "pip_import")

Expand Down Expand Up @@ -166,9 +173,11 @@ pip_import(
},
remove_runtime_deps = {
# https://github.com/keras-team/keras/issues/10505
"keras-applications": ["keras"],
"keras-preprocessing": ["keras"],
"keras-applications": ["keras", "keras-applications"],
"keras-preprocessing": ["keras", "keras-preprocessing"],
"keras": ["keras"],
},
python = "@python2//:bin/python",
)

load(
Expand Down
27 changes: 23 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@
<ul>
</ul>
</li>
<li><a href="./index.html">Overview</a></li>
<li>
<a href="./python/python.html">python Rules</a>
<ul>
</ul>
</li>
<li><a href="./index.html">Overview</a></li>
<li>
<a href="./python/whl.html">Import .whl files into Bazel.</a>
<ul>
Expand Down Expand Up @@ -108,6 +106,17 @@ <h3>Repository Rules</h3>

</td>
</tr>
<tr>
<td>
<a href="./python/pip.html#pip_version_proxy">
<code>pip_version_proxy</code>
</a>
</td>
<td>
<p>A rule for proxying requirements between different python runtimes.</p>

</td>
</tr>
</tbody>
</table>
<h2><a href="./python/python.html">python Rules</a></h2>
Expand Down Expand Up @@ -165,8 +174,18 @@ <h3>Repository Rules</h3>
<tbody>
<tr>
<td>
<a href="./python/whl.html#whl_library">
<code>whl_library</code>
<a href="./python/whl.html#download_or_build_wheel">
<code>download_or_build_wheel</code>
</a>
</td>
<td>

</td>
</tr>
<tr>
<td>
<a href="./python/whl.html#extract_wheels">
<code>extract_wheels</code>
</a>
</td>
<td>
Expand Down
25 changes: 23 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@

</td>
</tr>
<tr>
<td>
<a href="./python/pip.html#pip_version_proxy">
<code>pip_version_proxy</code>
</a>
</td>
<td>
<p>A rule for proxying requirements between different python runtimes.</p>

</td>
</tr>
</tbody>
</table>
<h2><a href="./python/python.html">python Rules</a></h2>
Expand Down Expand Up @@ -108,8 +119,18 @@
<tbody>
<tr>
<td>
<a href="./python/whl.html#whl_library">
<code>whl_library</code>
<a href="./python/whl.html#download_or_build_wheel">
<code>download_or_build_wheel</code>
</a>
</td>
<td>

</td>
</tr>
<tr>
<td>
<a href="./python/whl.html#extract_wheels">
<code>extract_wheels</code>
</a>
</td>
<td>
Expand Down
137 changes: 133 additions & 4 deletions docs/python/pip.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@
<ul>
</ul>
</li>
<li><a href="./index.html">Overview</a></li>
<li>
<a href="./python/python.html">python Rules</a>
<ul>
</ul>
</li>
<li><a href="./index.html">Overview</a></li>
<li>
<a href="./python/whl.html">Import .whl files into Bazel.</a>
<ul>
Expand All @@ -62,6 +60,7 @@ <h1>Import pip requirements into Bazel.</h1>
<h2>Repository Rules</h2>
<ul>
<li><a href="#pip_import">pip_import</a></li>
<li><a href="#pip_version_proxy">pip_version_proxy</a></li>
</ul>
<h2>Macros</h2>
<ul>
Expand All @@ -83,7 +82,7 @@ <h2 id="pip_repositories">pip_repositories</h2>

<h2 id="pip_import">pip_import</h2>

<pre>pip_import(<a href="#pip_import.name">name</a>, <a href="#pip_import.requirements">requirements</a>)</pre>
<pre>pip_import(<a href="#pip_import.name">name</a>, <a href="#pip_import.additional_buildtime_deps">additional_buildtime_deps</a>, <a href="#pip_import.additional_runtime_deps">additional_runtime_deps</a>, <a href="#pip_import.pip_args">pip_args</a>, <a href="#pip_import.python">python</a>, <a href="#pip_import.remove_runtime_deps">remove_runtime_deps</a>, <a href="#pip_import.requirements">requirements</a>, <a href="#pip_import.requirements_bzl">requirements_bzl</a>)</pre>

<p>A rule for importing &lt;code&gt;requirements.txt&lt;/code&gt; dependencies into Bazel.</p>
<p>This rule imports a &lt;code&gt;requirements.txt&lt;/code&gt; file and generates a new
Expand Down Expand Up @@ -133,13 +132,143 @@ <h3 id="pip_import_args">Attributes</h3>
<p>A unique name for this rule.</p>
</td>
</tr>
<tr id="pip_import.additional_buildtime_deps">
<td><code>additional_buildtime_deps</code></td>
<td>
<p><code>Dictionary mapping strings to lists of strings; Optional; Default is {}</code></p>

</td>
</tr>
<tr id="pip_import.additional_runtime_deps">
<td><code>additional_runtime_deps</code></td>
<td>
<p><code>Dictionary mapping strings to lists of strings; Optional; Default is {}</code></p>

</td>
</tr>
<tr id="pip_import.pip_args">
<td><code>pip_args</code></td>
<td>
<p><code>List of strings; Optional; Default is []</code></p>

</td>
</tr>
<tr id="pip_import.python">
<td><code>python</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; Optional</code></p>

</td>
</tr>
<tr id="pip_import.remove_runtime_deps">
<td><code>remove_runtime_deps</code></td>
<td>
<p><code>Dictionary mapping strings to lists of strings; Optional; Default is {}</code></p>

</td>
</tr>
<tr id="pip_import.requirements">
<td><code>requirements</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; Required</code></p>
<p><code>List of <a href="https://bazel.build/docs/build-ref.html#labels">labels</a>; Required</code></p>
<p>The label of a requirements.txt file.</p>
</td>
</tr>
<tr id="pip_import.requirements_bzl">
<td><code>requirements_bzl</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; Optional</code></p>

</td>
</tr>
</tbody>
</table>
<hr>

<h2 id="pip_version_proxy">pip_version_proxy</h2>

<pre>pip_version_proxy(<a href="#pip_version_proxy.name">name</a>, <a href="#pip_version_proxy.define">define</a>, <a href="#pip_version_proxy.python">python</a>, <a href="#pip_version_proxy.values">values</a>)</pre>

<p>A rule for proxying requirements between different python runtimes.</p>
<p>This rule generates a &lt;code&gt;requirements.bzl&lt;/code&gt; file that provides
a &lt;code&gt;requirements()&lt;/code&gt; function that resolves to the correct version
of python dependencies depending on the current python runtime.
This is used via the &lt;code&gt;WORKSPACE&lt;/code&gt; pattern:</p>
&lt;pre&gt;&lt;code&gt;pip_import(
name = "pip_deps2",
requirements = ["//:requirements-pip.txt"],
python = "@python2//:bin/python",
)
pip_import(
name = "pip_deps3",
requirements = ["//:requirements-pip.txt"],
python = "@python3//:bin/python",
)
load("@pip_deps2//:requirements.bzl", pip_install2 = "pip_install")
pip_install2()
load("@pip_deps3//:requirements.bzl", pip_install3 = "pip_install")
pip_install3()

pip_version_proxy(
name = "pip_deps",
define = "python",
values = {
"py2": "@pip_deps2",
"py3": "@pip_deps3",
},
)
&lt;/code&gt;&lt;/pre&gt;<p>When importing dependencies from a &lt;code&gt;BUILD&lt;/code&gt; file with</p>
&lt;pre&gt;&lt;code&gt;load("@pip_deps//:requirements.bzl", "requirement")
py_library(
name = "bar",
...
deps = [
requirement("mock"),
],
)
&lt;/code&gt;&lt;/pre&gt;<p>the &lt;code&gt;requirement&lt;/code&gt; macro will resolve to &lt;code&gt;pip_deps2&lt;/code&gt; when
building with &lt;code&gt;--define python=py2&lt;/code&gt;, and to &lt;code&gt;pip_deps3&lt;/code&gt; when
building with &lt;code&gt;--define python=py3&lt;/code&gt;.</p>


<h3 id="pip_version_proxy_args">Attributes</h3>

<table class="params-table">
<colgroup>
<col class="col-param" />
<col class="col-description" />
</colgroup>
<tbody>
<tr id="pip_version_proxy.name">
<td><code>name</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#name">Name</a>; Required</code></p>
<p>A unique name for this rule.</p>
</td>
</tr>
<tr id="pip_version_proxy.define">
<td><code>define</code></td>
<td>
<p><code>String; Optional; Default is ''</code></p>
<p>The key of the &lt;code&gt;--define&lt;/code&gt; that selects the python version.</p>
</td>
</tr>
<tr id="pip_version_proxy.python">
<td><code>python</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; Optional</code></p>

</td>
</tr>
<tr id="pip_version_proxy.values">
<td><code>values</code></td>
<td>
<p><code>Dictionary mapping strings to string; Optional; Default is {}</code></p>
<p>For each item in the dict, the key is the value of the &lt;code&gt;--define&lt;/code&gt; to match,
and the value is the name of the pip_import repository rule that provides
the pip dependencies for that python runtime.</p>
</td>
</tr>
</tbody>
</table>

Expand Down
Loading