@@ -91,16 +91,94 @@ use this attribute to specify its BUILD target. This allows pip_repository to in
91
91
pip using the same interpreter as your toolchain. If set, takes precedence over
92
92
python_interpreter.
93
93
""" ),
94
- "quiet" : attr .bool (default = True ),
95
- "requirements" : attr .label (allow_single_file = True , mandatory = True ),
94
+ "quiet" : attr .bool (
95
+ default = True ,
96
+ doc = "If True, suppress printing stdout and stderr output to the terminal." ,
97
+ ),
98
+ "requirements" : attr .label (
99
+ allow_single_file = True ,
100
+ mandatory = True ,
101
+ doc = "A 'requirements.txt' pip requirements file." ,
102
+ ),
96
103
# 600 is documented as default here: https://docs.bazel.build/versions/master/skylark/lib/repository_ctx.html#execute
97
- "timeout" : attr .int (default = 600 ),
98
- "wheel_env" : attr .string_dict (),
104
+ "timeout" : attr .int (
105
+ default = 600 ,
106
+ doc = "Timeout (in seconds) on the rule's execution duration." ,
107
+ ),
99
108
},
100
109
implementation = _pip_repository_impl ,
110
+ doc = """A rule for importing `requirements.txt` dependencies into Bazel.
111
+
112
+ This rule imports a `requirements.txt` file and generates a new
113
+ `requirements.bzl` file. This is used via the `WORKSPACE` pattern:
114
+
115
+ ```python
116
+ pip_repository(
117
+ name = "foo",
118
+ requirements = ":requirements.txt",
119
+ )
120
+ ```
121
+
122
+ You can then reference imported dependencies from your `BUILD` file with:
123
+
124
+ ```python
125
+ load("@foo//:requirements.bzl", "requirement")
126
+ py_library(
127
+ name = "bar",
128
+ ...
129
+ deps = [
130
+ "//my/other:dep",
131
+ requirement("requests"),
132
+ requirement("numpy"),
133
+ ],
134
+ )
135
+ ```
136
+
137
+ Or alternatively:
138
+ ```python
139
+ load("@foo//:requirements.bzl", "all_requirements")
140
+ py_binary(
141
+ name = "baz",
142
+ ...
143
+ deps = [
144
+ ":foo",
145
+ ] + all_requirements,
146
+ )
147
+ ```
148
+ """ ,
101
149
)
102
150
103
151
def pip_install (requirements , name = DEFAULT_REPOSITORY_NAME , ** kwargs ):
152
+ """Imports a `requirements.txt` file and generates a new `requirements.bzl` file.
153
+
154
+ This is used via the `WORKSPACE` pattern:
155
+
156
+ ```python
157
+ pip_install(
158
+ requirements = ":requirements.txt",
159
+ )
160
+ ```
161
+
162
+ You can then reference imported dependencies from your `BUILD` file with:
163
+
164
+ ```python
165
+ load("@pip//:requirements.bzl", "requirement")
166
+ py_library(
167
+ name = "bar",
168
+ ...
169
+ deps = [
170
+ "//my/other:dep",
171
+ requirement("requests"),
172
+ requirement("numpy"),
173
+ ],
174
+ )
175
+ ```
176
+
177
+ Args:
178
+ requirements: A 'requirements.txt' pip requirements file.
179
+ name: A unique name for the created external repository (default 'pip').
180
+ **kwargs: Keyword arguments passed directly to the `pip_repository` repository rule.
181
+ """
104
182
pip_repository (
105
183
name = name ,
106
184
requirements = requirements ,
0 commit comments