10000 rules_python_external: fill missing docstrings (#358) · AutomatedTester/rules_python@e821ce9 · GitHub
[go: up one dir, main page]

Skip to content

Commit e821ce9

Browse files
author
Jonathon Belotti
authored
rules_python_external: fill missing docstrings (bazel-contrib#358)
add missing docstrings for rules_python_external also remove unused attr on pip_repository repo rule
1 parent 3baa266 commit e821ce9

File tree

2 files changed

+90
-9
lines changed

2 files changed

+90
-9
lines changed

experimental/rules_python_external/defs.bzl

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,94 @@ use this attribute to specify its BUILD target. This allows pip_repository to in
9191
pip using the same interpreter as your toolchain. If set, takes precedence over
9292
python_interpreter.
9393
"""),
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+
),
96103
# 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+
),
99108
},
100109
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+
""",
101149
)
102150

103151
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+
"""
104182
pip_repository(
105183
name = name,
106184
requirements = requirements,

experimental/rules_python_external/repositories.bzl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ py_library(
4545
all_requirements = [name for (name, _, _) in _RULE_DEPS]
4646

4747
def requirement(pkg):
48-
return "@pypi__"+ pkg + "//:lib"
48+
return "@pypi__" + pkg + "//:lib"
4949

5050
def rules_python_external_dependencies():
51+
"""
52+
Fetch dependencies these rules depend on. Workspaces that use the rules_python_external should call this.
53+
"""
5154
for (name, url, sha256) in _RULE_DEPS:
5255
maybe(
5356
http_archive,
5457
name,
55-
url=url,
56-
sha256=sha256,
57-
type="zip",
58-
build_file_content=_GENERIC_WHEEL,
58+
url = url,
59+
sha256 = sha256,
60+
type = "zip",
61+
build_file_content = _GENERIC_WHEEL,
5962
)

0 commit comments

Comments
 (0)
0