10000 Add a timeout attribute to pip_import rules. (#217) · PoncinMatthieu/rules_python@748aa53 · GitHub
[go: up one dir, main page]

Skip to content

Commit 748aa53

Browse files
authored
Add a timeout attribute to pip_import rules. (bazel-contrib#217)
The combination of a large requirements.txt file and a slow network can cause the default timeout for repository_ctx.execute() to be reached. This patch exposes that timeout to the pip_import() caller so they can manually specify a longer timeout. E.g. pip_import( name = "requirements", requirements = "//long_list_of_requirements.txt", timeout = 3600, )
1 parent abc4869 commit 748aa53

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

docs/pip.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## pip_import
66

77
<pre>
8-
pip_import(<a href="#pip_import-name">name</a>, <a href="#pip_import-extra_pip_args">extra_pip_args</a>, <a href="#pip_import-python_interpreter">python_interpreter</a>, <a href="#pip_import-requirements">requirements</a>)
8+
pip_import(<a href="#pip_import-name">name</a>, <a href="#pip_import-extra_pip_args">extra_pip_args</a>, <a href="#pip_import-python_interpreter">python_interpreter</a>, <a href="#pip_import-requirements">requirements</a>, <a href="#pip_import-timeout">timeout</a>)
99
</pre>
1010

1111
A rule for importing `requirements.txt` dependencies into Bazel.
@@ -95,6 +95,15 @@ wheels.
9595
</p>
9696
</td>
9797
</tr>
98+
<tr id="pip_import-timeout">
99+
<td><code>timeout</code></td>
100+
<td>
101+
Integer; optional
102+
<p>
103+
Timeout (in seconds) for repository fetch.
104+
</p>
105+
</td>
106+
</tr>
98107
</tbody>
99108
</table>
100109

python/pip.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _pip_import_impl(repository_ctx):
4343
]
4444

4545
# To see the output, pass: quiet=False
46-
result = repository_ctx.execute(args)
46+
result = repository_ctx.execute(args, timeout=repository_ctx.attr.timeout)
4747

4848
if result.return_code:
4949
fail("pip_import failed: %s (%s)" % (result.stdout, result.stderr))
@@ -62,6 +62,10 @@ wheels.
6262
allow_single_file = True,
6363
doc = "The label of the requirements.txt file.",
6464
),
65+
"timeout": attr.int(
66+
default = 600,
67+
doc = "Timeout (in seconds) for repository fetch."
68+
),
6569
"_script": attr.label(
6670
executable = True,
6771
default = Label("//tools:piptool.par"),

0 commit comments

Comments
 (0)
0