Skip to content

Commit 9bc3aa8

Browse files
authored
docs: Add some missing attribute docs (bazel-contrib#1805)
Adds docs for: stamp, srcs, deps, srcs_version, data, and python_version
1 parent 9c538ea commit 9bc3aa8

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

python/private/common/attributes.bzl

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,28 @@ _PackageSpecificationInfo = getattr(py_internal, "PackageSpecificationInfo", Non
3030
_STAMP_VALUES = [-1, 0, 1]
3131

3232
def create_stamp_attr(**kwargs):
33-
return {"stamp": attr.int(values = _STAMP_VALUES, **kwargs)}
33+
return {
34+
"stamp": attr.int(
35+
values = _STAMP_VALUES,
36+
doc = """
37+
Whether to encode build information into the binary. Possible values:
38+
39+
* `stamp = 1`: Always stamp the build information into the binary, even in
40+
`--nostamp` builds. **This setting should be avoided**, since it potentially kills
41+
remote caching for the binary and any downstream actions that depend on it.
42+
* `stamp = 0`: Always replace build information by constant values. This gives
43+
good build result caching.
44+
* `stamp = -1`: Embedding of build information is controlled by the
45+
`--[no]stamp` flag.
46+
47+
Stamped binaries are not rebuilt unless their dependencies change.
48+
49+
WARNING: Stamping can harm build performance by reducing cache hits and should
50+
be avoided if possible.
51+
""",
52+
**kwargs
53+
),
54+
}
3455

3556
def create_srcs_attr(*, mandatory):
3657
return {
@@ -40,6 +61,12 @@ def create_srcs_attr(*, mandatory):
4061
mandatory = mandatory,
4162
# Necessary for --compile_one_dependency to work.
4263
flags = ["DIRECT_COMPILE_TIME_INPUT"],
64+
doc = """
65+
The list of Python source files that are processed to create the target. This
66+
includes all your checked-in code and may include generated source files. The
67+
`.py` files belong in `srcs` and library targets belong in `deps`. Other binary
68+
files that may be needed at run time belong in `data`.
69+
""",
4370
),
4471
}
4572

@@ -51,6 +78,7 @@ def create_srcs_version_attr(values):
5178
"srcs_version": attr.string(
5279
default = "PY2AND3",
5380
values = values,
81+
doc = "Defunct, unused, does nothing.",
5482
),
5583
}
5684

@@ -81,6 +109,13 @@ DATA_ATTRS = {
81109
"data": attr.label_list(
82110
allow_files = True,
83111
flags = ["SKIP_CONSTRAINTS_OVERRIDE"],
112+
doc = """
113+
The list of files need by this library at runtime. See comments about
114+
the [`data` attribute typically defined by rules](https://bazel.build/reference/be/common-definitions#typical-attributes).
115+
116+
There is no `py_embed_data` like there is `cc_embed_data` and `go_embed_data`.
117+
This is because Python has a concept of runtime resources.
118+
""",
84119
),
85120
}
86121

@@ -136,6 +171,16 @@ PY_SRCS_ATTRS = union_attrs(
136171
# TODO(b/228692666): Google-specific; remove these allowances once
137172
# the depot is cleaned up.
138173
allow_rules = DEPS_ATTR_ALLOW_RULES,
174+
doc = """
175+
List of additional libraries to be linked in to the target.
176+
See comments about
177+
the [`deps` attribute typically defined by
178+
rules](https://bazel.build/reference/be/common-definitions#typical-attributes).
179+
These are typically `py_library` rules.
180+
181+
Targets that only provide data files used at runtime belong in the `data`
182+
attribute.
183+
""",
139184
),
140185
# Required attribute, but details vary by rule.
141186
# Use create_srcs_attr to create one.

python/private/common/py_executable.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ filename in `srcs`, `main` must be specified.
9393
default = "PY3",
9494
# NOTE: Some tests care about the order of these values.
9595
values = ["PY2", "PY3"],
96+
doc = "Defunct, unused, does nothing.",
9697
),
9798
"_windows_constraints": attr.label_list(
9899
default = [

0 commit comments

Comments
 (0)