Skip to content

Commit 55fd502

Browse files
keithalexeagle
andauthored
Add data to py_venv rule (#534)
If your venv requires runtime dependencies in the build, these previously weren't built --------- Co-authored-by: Alex Eagle <[email protected]>
1 parent e277907 commit 55fd502

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

docs/venv.md

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/defs.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ py_image_layer = _py_image_layer
5959

6060
resolutions = _resolutions
6161

62-
def _py_binary_or_test(name, rule, srcs, main, deps = [], resolutions = {}, **kwargs):
62+
def _py_binary_or_test(name, rule, srcs, main, data = [], deps = [], resolutions = {}, **kwargs):
6363
# Compatibility with rules_python, see docs in py_executable.bzl
6464
main_target = "{}.find_main".format(name)
6565
determine_main(
@@ -76,6 +76,7 @@ def _py_binary_or_test(name, rule, srcs, main, deps = [], resolutions = {}, **kw
7676
name = name,
7777
srcs = srcs,
7878
main = main_target,
79+
data = data,
7980
deps = deps,
8081
resolutions = resolutions,
8182
package_collisions = package_collisions,
@@ -84,6 +85,7 @@ def _py_binary_or_test(name, rule, srcs, main, deps = [], resolutions = {}, **kw
8485

8586
_py_venv(
8687
name = "{}.venv".format(name),
88+
data = data,
8789
deps = deps,
8890
imports = kwargs.get("imports"),
8991
resolutions = resolutions,

py/private/py_venv.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ py_venv_rule = rule(
9898
allow_files = True,
9999
providers = [[PyInfo], [PyVirtualInfo]],
100100
),
101+
"data": attr.label_list(
102+
doc = """Runtime dependencies of the program.
103+
104+
The transitive closure of the `data` dependencies will be available in the `.runfiles`
105+
folder for this binary/test. The program may optionally use the Runfiles lookup library to
106+
locate the data files, see https://pypi.org/project/bazel-runfiles/.
107+
""",
108+
allow_files = True,
109+
),
101110
"imports": attr.string_list(
102111
doc = "List of import directories to be added to the PYTHONPATH.",
103112
default = [],

0 commit comments

Comments
 (0)