forked from scele/rules_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpip.html
More file actions
290 lines (255 loc) · 9.42 KB
/
pip.html
File metadata and controls
290 lines (255 loc) · 9.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!--
Documentation generated by Skydoc
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Import pip requirements into Bazel.</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" type="text/css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.1/material.green-light_blue.min.css">
<script defer src="https://code.getmdl.io/1.1.1/material.min.js"></script>
<link rel="stylesheet" href="./main.css">
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer
mdl-layout--fixed-header">
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">Import pip requirements into Bazel.</span>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout-title">Bazel</span>
<nav class="drawer-nav">
<ul class="drawer-nav">
<li><a href="./index.html">Overview</a></li>
<li>
<a href="./python/pip.html">Import pip requirements into Bazel.</a>
<ul>
</ul>
</li>
<li>
<a href="./python/python.html">python Rules</a>
<ul>
</ul>
</li>
<li>
<a href="./python/whl.html">Import .whl files into Bazel.</a>
<ul>
</ul>
</li>
</ul>
</nav>
</div>
<main class="mdl-layout__content">
<div class="page-content">
<h1>Import pip requirements into Bazel.</h1>
<nav class="toc">
<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>
<li><a href="#pip_repositories">pip_repositories</a></li>
</ul>
</nav>
<hr>
<h2 id="pip_repositories">pip_repositories</h2>
<pre>pip_repositories()</pre>
<p>Pull in dependencies needed for pulling in pip dependencies.</p>
<p>A placeholder method that will eventually pull in any dependencies
needed to install pip dependencies.</p>
<hr>
<h2 id="pip_import">pip_import</h2>
<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 <code>requirements.txt</code> dependencies into Bazel.</p>
<p>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:</p>
<pre><code>pip_import(
name = "foo",
requirements = ":requirements.txt",
)
load("@foo//:requirements.bzl", "pip_install")
pip_install()
</code></pre><p>You can then reference imported dependencies from your <code>BUILD</code>
file with:</p>
<pre><code>load("@foo//:requirements.bzl", "requirement")
py_library(
name = "bar",
...
deps = [
"//my/other:dep",
requirement("futures"),
requirement("mock"),
],
)
</code></pre><p>Or alternatively:</p>
<pre><code>load("@foo//:requirements.bzl", "all_requirements")
py_binary(
name = "baz",
...
deps = [
":foo",
] + all_requirements,
)
</code></pre>
<h3 id="pip_import_args">Attributes</h3>
<table class="params-table">
<colgroup>
<col class="col-param" />
<col class="col-description" />
</colgroup>
<tbody>
<tr id="pip_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="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>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 <code>requirements.bzl</code> file that provides
a <code>requirements()</code> function that resolves to the correct version
of python dependencies depending on the current python runtime.
This is used via the <code>WORKSPACE</code> pattern:</p>
<pre><code>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",
},
)
</code></pre><p>When importing dependencies from a <code>BUILD</code> file with</p>
<pre><code>load("@pip_deps//:requirements.bzl", "requirement")
py_library(
name = "bar",
...
deps = [
requirement("mock"),
],
)
</code></pre><p>the <code>requirement</code> macro will resolve to <code>pip_deps2</code> when
building with <code>--define python=py2</code>, and to <code>pip_deps3</code> when
building with <code>--define python=py3</code>.</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 <code>--define</code> 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 <code>--define</code> 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>
</div>
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
<div class="mdl-logo">Bazel</div>
<ul class="mdl-mini-footer__link-list">
<li><a href="http://bazel.io">Home</a></li>
<li><a href="https://github.com/bazelbuild">GitHub</a></li>
</ul>
</div>
</footer>
</main>
</div>
</body>
</html>