GeezerVison is showing github.com — docs: generate docs for py_common, PyInfoBuilder APIs (#2920) · bookingcom/rules_python@cd550d9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/BUILD.bazel +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -113,6 +113,7 @@ sphinx_stardocs( | 113 | 113 | "//python/private:builders_util_bzl", | 114 | 114 | "//python/private:py_binary_rule_bzl", | 115 | 115 | "//python/private:py_cc_toolchain_rule_bzl", | | 116 | + "//python/private:py_info_bzl", | 116 | 117 | "//python/private:py_library_rule_bzl", | 117 | 118 | "//python/private:py_runtime_rule_bzl", | 118 | 119 | "//python/private:py_test_rule_bzl", | |
Collapse file Copy file name to clipboardExpand all lines: python/api/api.bzl +20-1Lines changed: 20 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -"""Public, analysis phase APIs for Python rules.""" | | 1 | +"""Public, analysis phase APIs for Python rules. | | 2 | +
| | 3 | +To use the analyis-time API, add the attributes to your rule, then | | 4 | +use `py_common.get()` to get the api object: | | 5 | +
| | 6 | +``` | | 7 | +load("@rules_python//python/api:api.bzl", "py_common") | | 8 | +
| | 9 | +def _impl(ctx): | | 10 | + py_api = py_common.get(ctx) | | 11 | +
| | 12 | +myrule = rule( | | 13 | + implementation = _impl, | | 14 | + attrs = {...} | py_common.API_ATTRS | | 15 | +) | | 16 | +``` | | 17 | +
| | 18 | +:::{versionadded} 0.37.0 | | 19 | +::: | | 20 | +""" | 2 | 21 |
| 3 | 22 | load("//python/private/api:api.bzl", _py_common = "py_common") | 4 | 23 |
| |
Collapse file Copy file name to clipboardExpand all lines: python/private/api/api.bzl +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,17 @@ will depend on the target that is providing the API struct. | 27 | 27 | }, | 28 | 28 | ) | 29 | 29 |
| | 30 | +def _py_common_typedef(): | | 31 | + """Typedef for py_common. | | 32 | +
| | 33 | + :::{field} API_ATTRS | | 34 | + :type: dict[str, Attribute] | | 35 | +
| | 36 | + The attributes that rules must have for `py_common.get()` to work. | | 37 | + ::: | | 38 | +
| | 39 | + """ | | 40 | + | 30 | 41 | def _py_common_get(ctx): | 31 | 42 | """Get the py_common API instance. | 32 | 43 |
| @@ -45,6 +56,7 @@ def _py_common_get(ctx): | 45 | 56 | return ctx.attr._py_common_api[ApiImplInfo].impl | 46 | 57 |
| 47 | 58 | py_common = struct( | | 59 | + TYPEDEF = _py_common_typedef, | 48 | 60 | get = _py_common_get, | 49 | 61 | API_ATTRS = { | 50 | 62 | "_py_common_api": attr.label( | |
Collapse file Copy file name to clipboardExpand all lines: python/private/api/py_common_api.bzl +26-3Lines changed: 26 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,17 +22,40 @@ def _py_common_api_impl(ctx): | 22 | 22 |
| 23 | 23 | py_common_api = rule( | 24 | 24 | implementation = _py_common_api_impl, | 25 | | - doc = "Rule implementing py_common API.", | | 25 | + doc = "Internal Rule implementing py_common API.", | 26 | 26 | ) | 27 | 27 |
| | 28 | +def _py_common_api_typedef(): | | 29 | + """The py_common API implementation. | | 30 | +
| | 31 | + An instance of this object is obtained using {obj}`py_common.get()` | | 32 | + """ | | 33 | + | 28 | 34 | def _merge_py_infos(transitive, *, direct = []): | 29 | | - builder = PyInfoBuilder() | | 35 | + """Merge PyInfo objects into a single PyInfo. | | 36 | +
| | 37 | + This is a convenience wrapper around {obj}`PyInfoBuilder.merge_all`. For | | 38 | + more control over merging PyInfo objects, use {obj}`PyInfoBuilder`. | | 39 | +
| | 40 | + Args: | | 41 | + transitive: {type}`list[PyInfo]` The PyInfo objects with info | | 42 | + considered indirectly provided by something (e.g. via | | 43 | + its deps attribute). | | 44 | + direct: {type}`list[PyInfo]` The PyInfo objects that are | | 45 | + considered directly provided by something (e.g. via | | 46 | + the srcs attribute). | | 47 | +
| | 48 | + Returns: | | 49 | + {type}`PyInfo` A PyInfo containing the merged values. | | 50 | + """ | | 51 | + builder = PyInfoBuilder.new() | 30 | 52 | builder.merge_all(transitive, direct = direct) | 31 | 53 | return builder.build() | 32 | 54 |
| 33 | 55 | # Exposed for doc generation, not directly used. | 34 | 56 | # buildifier: disable=name-conventions | 35 | 57 | PyCommonApi = struct( | | 58 | + TYPEDEF = _py_common_api_typedef, | 36 | 59 | merge_py_infos = _merge_py_infos, | 37 | | - PyInfoBuilder = PyInfoBuilder, | | 60 | + PyInfoBuilder = PyInfoBuilder.new, | 38 | 61 | ) |
Collapse file Copy file name to clipboardExpand all lines: python/private/common.bzl +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -405,7 +405,7 @@ def create_py_info( | 405 | 405 | transitive sources collected from dependencies (the latter is only | 406 | 406 | necessary for deprecated extra actions support). | 407 | 407 | """ | 408 | | - py_info = PyInfoBuilder() | | 408 | + py_info = PyInfoBuilder.new() | 409 | 409 | py_info.site_packages_symlinks.add(site_packages_symlinks) | 410 | 410 | py_info.direct_original_sources.add(original_sources) | 411 | 411 | py_info.direct_pyc_files.add(required_pyc_files) | |
|