diff --git a/README.md b/README.md index 9c44f40d95..f58213b0ee 100644 --- a/README.md +++ b/README.md @@ -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) @@ -75,6 +76,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` diff --git a/docs/index.html b/docs/index.html index f3487d21bd..5a35c5508d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -97,6 +97,17 @@
pip3_import
+
+ A rule for importing <code>requirements.txt</code> dependencies into Bazel.
+ +pip3_import
+
+ A rule for importing <code>requirements.txt</code> dependencies into Bazel.
+ +extras
List of strings; Optional; Default is []
A subset of the "extras" available from this <code>.whl</code> for which +<code>requirements</code> has the dependencies.
+requirements
-whl_library(name, requirements, whl) +whl_library(name, extras, requirements, whl)A rule for importing
.whl
dependencies into Bazel.
@@ -52,6 +52,14 @@ This rule defines a @foo//:pkg
py_library
target.
A unique name for this rule.
extras
List of strings; Optional; Default is []
A subset of the "extras" available from this <code>.whl</code> for which +<code>requirements</code> has the dependencies.
+requirements
requirements.txt
dependencies into Bazel.
-This rule imports a requirements.txt
file and generates a new
-requirements.bzl
file. This is used via the WORKSPACE
-pattern:
+This rule imports a requirements.txt
file using the system
+python
, and generates a new requirements.bzl
file.
+This is used via the WORKSPACE
pattern:
pip_import(
name = "foo",
requirements = ":requirements.txt",
@@ -96,6 +99,64 @@ Args:
requirements: The label of a requirements.txt file.
"""
+pip3_import = repository_rule(
+ attrs = {
+ "requirements": attr.label(
+ allow_files = True,
+ mandatory = True,
+ single_file = True,
+ ),
+ "_script": attr.label(
+ executable = True,
+ default = Label("//tools:piptool.par"),
+ cfg = "host",
+ ),
+ },
+ implementation = _pip3_import_impl,
+)
+
+"""A rule for importing requirements.txt
dependencies into Bazel.
+
+This rule imports a requirements.txt
file using the system
+python3
, and generates a new requirements.bzl
file.
+This is used via the WORKSPACE
pattern:
+pip3_import(
+ name = "foo",
+ requirements = ":requirements.txt",
+)
+load("@foo//:requirements.bzl", "pip_install")
+pip_install()
+
+
+You can then reference imported dependencies from your BUILD
+file with:
+load("@foo//:requirements.bzl", "requirement")
+py_library(
+ name = "bar",
+ ...
+ deps = [
+ "//my/other:dep",
+ requirement("futures"),
+ requirement("mock"),
+ ],
+)
+
+
+Or alternatively:
+load("@foo//:requirements.bzl", "all_requirements")
+py_binary(
+ name = "baz",
+ ...
+ deps = [
+ ":foo",
+ ] + all_requirements,
+)
+
+
+Args:
+ requirements: The label of a requirements.txt file.
+"""
+
def pip_repositories():
"""Pull in dependencies needed for pulling in pip dependencies.