diff --git a/docs/venv.md b/docs/venv.md index 8ea6335d..0206837a 100644 --- a/docs/venv.md +++ b/docs/venv.md @@ -14,7 +14,7 @@ Using `py_venv` directly is only required for cases where those defaults do not ## py_venv_rule
-py_venv_rule(name, deps, imports, location, package_collisions, resolutions, venv_name)
+py_venv_rule(name, data, deps, imports, location, package_collisions, resolutions, venv_name)
 
Create a Python virtual environment with the dependencies listed. @@ -25,6 +25,7 @@ Create a Python virtual environment with the dependencies listed. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | +| data | Runtime dependencies of the program.

The transitive closure of the data dependencies will be available in the .runfiles folder for this binary/test. The program may optionally use the Runfiles lookup library to locate the data files, see https://pypi.org/project/bazel-runfiles/. | List of labels | optional | [] | | deps | Targets that produce Python code, commonly py_library rules. | List of labels | optional | [] | | imports | List of import directories to be added to the PYTHONPATH. | List of strings | optional | [] | | location | Path from the workspace root for where to root the virtial environment | String | optional | "" | diff --git a/py/defs.bzl b/py/defs.bzl index 5316355f..59c8ddd3 100644 --- a/py/defs.bzl +++ b/py/defs.bzl @@ -59,7 +59,7 @@ py_image_layer = _py_image_layer resolutions = _resolutions -def _py_binary_or_test(name, rule, srcs, main, deps = [], resolutions = {}, **kwargs): +def _py_binary_or_test(name, rule, srcs, main, data = [], deps = [], resolutions = {}, **kwargs): # Compatibility with rules_python, see docs in py_executable.bzl main_target = "{}.find_main".format(name) determine_main( @@ -76,6 +76,7 @@ def _py_binary_or_test(name, rule, srcs, main, deps = [], resolutions = {}, **kw name = name, srcs = srcs, main = main_target, + data = data, deps = deps, resolutions = resolutions, package_collisions = package_collisions, @@ -84,6 +85,7 @@ def _py_binary_or_test(name, rule, srcs, main, deps = [], resolutions = {}, **kw _py_venv( name = "{}.venv".format(name), + data = data, deps = deps, imports = kwargs.get("imports"), resolutions = resolutions, diff --git a/py/private/py_venv.bzl b/py/private/py_venv.bzl index 47117e9e..c8c0c51f 100644 --- a/py/private/py_venv.bzl +++ b/py/private/py_venv.bzl @@ -97,6 +97,15 @@ py_venv_rule = rule( allow_files = True, providers = [[PyInfo], [PyVirtualInfo]], ), + "data": attr.label_list( + doc = """Runtime dependencies of the program. + + The transitive closure of the `data` dependencies will be available in the `.runfiles` + folder for this binary/test. The program may optionally use the Runfiles lookup library to + locate the data files, see https://pypi.org/project/bazel-runfiles/. + """, + allow_files = True, + ), "imports": attr.string_list( doc = "List of import directories to be added to the PYTHONPATH.", default = [],