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

Add a pip3_import target for Python 3 compatibility. #85

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Status: This is **ALPHA** software.
## Rules

* [pip_import](docs/python/pip.md#pip_import)
* [pip3_import](docs/python/pip.md#pip3_import)
* [py_library](docs/python/python.md#py_library)
* [py_binary](docs/python/python.md#py_binary)
* [py_test](docs/python/python.md#py_test)
Expand Down Expand Up @@ -73,6 +74,9 @@ load("@my_deps//:requirements.bzl", "pip_install")
pip_install()
```

The `pip_import` rule uses the system `python` command, which is usually
Python 2. `pip3_import` uses the system `python3` command.

## Consuming `pip` dependencies

Once a set of dependencies has been imported via `pip_import` and `pip_install`
Expand Down
11 changes: 11 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ <h3>Repository Rules</h3>
<col class="col-description" />
</colgroup>
<tbody>
<tr>
<td>
<a href="./python/pip.html#pip3_import">
<code>pip3_import</code>
</a>
</td>
<td>
<p>A rule for importing &lt;code&gt;requirements.txt&lt;/code&gt; dependencies into Bazel.</p>

</td>
</tr>
<tr>
<td>
<a href="./python/pip.html#pip_import">
Expand Down
11 changes: 11 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
<col class="col-description" />
</colgroup>
<tbody>
<tr>
<td>
<a href="./python/pip.html#pip3_import">
<code>pip3_import</code>
</a>
</td>
<td>
<p>A rule for importing &lt;code&gt;requirements.txt&lt;/code&gt; dependencies into Bazel.</p>

</td>
</tr>
<tr>
<td>
<a href="./python/pip.html#pip_import">
Expand Down
70 changes: 67 additions & 3 deletions docs/python/pip.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ <h1>Import pip requirements into Bazel.</h1>
<nav class="toc">
<h2>Repository Rules</h2>
<ul>
<li><a href="#pip3_import">pip3_import</a></li>
<li><a href="#pip_import">pip_import</a></li>
</ul>
<h2>Macros</h2>
Expand All @@ -81,14 +82,77 @@ <h2 id="pip_repositories">pip_repositories</h2>

<hr>

<h2 id="pip3_import">pip3_import</h2>

<pre>pip3_import(<a href="#pip3_import.name">name</a>, <a href="#pip3_import.requirements">requirements</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 using the system
&lt;code&gt;python3&lt;/code&gt;, and generates a new &lt;code&gt;requirements.bzl&lt;/code&gt; file.
This is used via the &lt;code&gt;WORKSPACE&lt;/code&gt; pattern:</p>
&lt;pre&gt;&lt;code&gt;pip3_import(
name = "foo",
requirements = ":requirements.txt",
)
load("@foo//:requirements.bzl", "pip_install")
pip_install()
&lt;/code&gt;&lt;/pre&gt;<p>You can then reference imported dependencies from your &lt;code&gt;BUILD&lt;/code&gt;
file with:</p>
&lt;pre&gt;&lt;code&gt;load("@foo//:requirements.bzl", "requirement")
py_library(
name = "bar",
...
deps = [
"//my/other:dep",
requirement("futures"),
requirement("mock"),
],
)
&lt;/code&gt;&lt;/pre&gt;<p>Or alternatively:</p>
&lt;pre&gt;&lt;code&gt;load("@foo//:requirements.bzl", "all_requirements")
py_binary(
name = "baz",
...
deps = [
":foo",
] + all_requirements,
)
&lt;/code&gt;&lt;/pre&gt;

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

<table class="params-table">
<colgroup>
<col class="col-param" />
<col class="col-description" />
</colgroup>
<tbody>
<tr id="pip3_import.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="pip3_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>The label of a requirements.txt file.</p>
</td>
</tr>
</tbody>
</table>
<hr>

<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>

<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
&lt;code&gt;requirements.bzl&lt;/code&gt; file. This is used via the &lt;code&gt;WORKSPACE&lt;/code&gt;
pattern:</p>
<p>This rule imports a &lt;code&gt;requirements.txt&lt;/code&gt; file using the system
&lt;code&gt;python&lt;/code&gt;, and generates a new &lt;code&gt;requirements.bzl&lt;/code&gt; file.
This is used via the &lt;code&gt;WORKSPACE&lt;/code&gt; pattern:</p>
&lt;pre&gt;&lt;code&gt;pip_import(
name = "foo",
requirements = ":requirements.txt",
Expand Down
79 changes: 76 additions & 3 deletions docs/python/pip.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Documentation generated by Skydoc
<nav class="toc">
<h2>Repository Rules</h2>
<ul>
<li><a href="#pip3_import">pip3_import</a></li>
<li><a href="#pip_import">pip_import</a></li>
</ul>
<h2>Macros</h2>
Expand All @@ -27,6 +28,78 @@ Pull in dependencies needed for pulling in pip dependencies.
A placeholder method that will eventually pull in any dependencies
needed to install pip dependencies.

<a name="pip3_import"></a>
## pip3_import

<pre>
pip3_import(<a href="#pip3_import.name">name</a>, <a href="#pip3_import.requirements">requirements</a>)
</pre>

A rule for importing <code>requirements.txt</code> dependencies into Bazel.

This rule imports a <code>requirements.txt</code> file using the system
<code>python3</code>, and generates a new <code>requirements.bzl</code> file.
This is used via the <code>WORKSPACE</code> pattern:
<pre><code>pip3_import(
name = "foo",
requirements = ":requirements.txt",
)
load("@foo//:requirements.bzl", "pip_install")
pip_install()
</code></pre>

You can then reference imported dependencies from your <code>BUILD</code>
file with:
<pre><code>load("@foo//:requirements.bzl", "requirement")
py_library(
name = "bar",
...
deps = [
"//my/other:dep",
requirement("futures"),
requirement("mock"),
],
)
</code></pre>

Or alternatively:
<pre><code>load("@foo//:requirements.bzl", "all_requirements")
py_binary(
name = "baz",
...
deps = [
":foo",
] + all_requirements,
)
</code></pre>


<a name="pip3_import_args"></a>
### Attributes


<table class="params-table">
<colgroup>
<col class="col-param" />
<col class="col-description" />
</colgroup>
<tbody>
<tr id="pip3_import.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="pip3_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>The label of a requirements.txt file.</p>
</td>
</tr>
</tbody>
</table>
<a name="pip_import"></a>
## pip_import

Expand All @@ -36,9 +109,9 @@ pip_import(<a href="#pip_import.name">name</a>, <a href="#pip_import.requirement

A rule for importing <code>requirements.txt</code> dependencies into Bazel.

This rule imports a <code>requirements.txt</code> file and generates a new
<code>requirements.bzl</code> file. This is used via the <code>WORKSPACE</code>
pattern:
This rule imports a <code>requirements.txt</code> file using the system
<code>python</code>, and generates a new <code>requirements.bzl</code> file.
This is used via the <code>WORKSPACE</code> pattern:
<pre><code>pip_import(
name = "foo",
requirements = ":requirements.txt",
Expand Down
10 changes: 9 additions & 1 deletion docs/python/whl.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h2>Repository Rules</h2>

<h2 id="whl_library">whl_library</h2>

<pre>whl_library(<a href="#whl_library.name">name</a>, <a href="#whl_library.requirements">requirements</a>, <a href="#whl_library.whl">whl</a>)</pre>
<pre>whl_library(<a href="#whl_library.name">name</a>, <a href="#whl_library.extras">extras</a>, <a href="#whl_library.requirements">requirements</a>, <a href="#whl_library.whl">whl</a>)</pre>

<p>A rule for importing &lt;code&gt;.whl&lt;/code&gt; dependencies into Bazel.</p>
<p>&lt;b&gt;This rule is currently used to implement &lt;code&gt;pip_import&lt;/code&gt;,
Expand Down Expand Up @@ -98,6 +98,14 @@ <h3 id="whl_library_args">Attributes</h3>
<p>A unique name for this rule.</p>
</td>
</tr>
<tr id="whl_library.extras">
<td><code>extras</code></td>
<td>
<p><code>List of strings; Optional; Default is []</code></p>
<p>A subset of the "extras" available from this &lt;code&gt;.whl&lt;/code&gt; for which
&lt;code&gt;requirements&lt;/code&gt; has the dependencies.</p>
</td>
</tr>
<tr id="whl_library.requirements">
<td><code>requirements</code></td>
<td>
Expand Down
10 changes: 9 additions & 1 deletion docs/python/whl.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Documentation generated by Skydoc
## whl_library

<pre>
whl_library(<a href="#whl_library.name">name</a>, <a href="#whl_library.requirements">requirements</a>, <a href="#whl_library.whl">whl</a>)
whl_library(<a href="#whl_library.name">name</a>, <a href="#whl_library.extras">extras</a>, <a href="#whl_library.requirements">requirements</a>, <a href="#whl_library.whl">whl</a>)
</pre>

A rule for importing <code>.whl</code> dependencies into Bazel.
Expand Down Expand Up @@ -52,6 +52,14 @@ This rule defines a <code>@foo//:pkg</code> <code>py_library</code> target.
<p>A unique name for this rule.</p>
</td>
</tr>
<tr id="whl_library.extras">
<td><code>extras</code></td>
<td>
<p><code>List of strings; Optional; Default is []</code></p>
<p>A subset of the "extras" available from this &lt;code&gt;.whl&lt;/code&gt; for which
&lt;code&gt;requirements&lt;/code&gt; has the dependencies.</p>
</td>
</tr>
<tr id="whl_library.requirements">
<td><code>requirements</code></td>
<td>
Expand Down