Skip to content

Commit 3ae4475

Browse files
authored
Merge branch 'main' into docs.ignore.py.external.xrefs
2 parents 93c654c + 1ea9102 commit 3ae4475

File tree

19 files changed

+176
-116
lines changed

19 files changed

+176
-116
lines changed

CHANGELOG.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ END_UNRELEASED_TEMPLATE
6666
* (rules) On Windows, {obj}`--bootstrap_impl=system_python` is forced. This
6767
allows setting `--bootstrap_impl=script` in bazelrc for mixed-platform
6868
environments.
69-
* (rules) {obj}`pip_compile` now generates a `.test` target. The `_test` target is deprecated
70-
and will be removed in the next major release.
69+
* (rules) {obj}`compile_pip_requirements` now generates a `.test` target. The
70+
`_test` target is deprecated and will be removed in the next major release.
7171
([#2794](https://github.com/bazel-contrib/rules_python/issues/2794)
7272
* (py_wheel) py_wheel always creates zip64-capable wheel zips
7373

@@ -190,7 +190,7 @@ END_UNRELEASED_TEMPLATE
190190
packages through SimpleAPI unless they are pulled through direct URL
191191
references. Fixes [#2023](https://github.com/bazel-contrib/rules_python/issues/2023).
192192
In case you see issues with `rules_python` being too eager to fetch the SimpleAPI
193-
metadata, you can use the newly added {attr}`pip.parse.experimental_skip_sources`
193+
metadata, you can use the newly added {attr}`pip.parse.simpleapi_skip`
194194
to skip metadata fetching for those packages.
195195
* (uv) A {obj}`lock` rule that is the replacement for the
196196
{obj}`compile_pip_requirements`. This may still have rough corners
@@ -251,7 +251,7 @@ END_UNRELEASED_TEMPLATE
251251

252252
{#v1-3-0-added}
253253
### Added
254-
* (python) {attr}`python.defaults` has been added to allow users to
254+
* (python) {obj}`python.defaults` has been added to allow users to
255255
set the default python version in the root module by reading the
256256
default version number from a file or an environment variable.
257257
* {obj}`//python/bin:python`: convenience target for directly running an
@@ -271,7 +271,7 @@ END_UNRELEASED_TEMPLATE
271271
and py_library rules
272272
([#1647](https://github.com/bazel-contrib/rules_python/issues/1647))
273273
* (rules) Added env-var to allow additional interpreter args for stage1 bootstrap.
274-
See {obj}`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` environment variable.
274+
See {any}`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` environment variable.
275275
Only applicable for {obj}`--bootstrap_impl=script`.
276276
* (rules) Added {obj}`interpreter_args` attribute to `py_binary` and `py_test`,
277277
which allows pass arguments to the interpreter before the regular args.
@@ -377,7 +377,7 @@ END_UNRELEASED_TEMPLATE
377377
values. Fixes [#2466](https://github.com/bazel-contrib/rules_python/issues/2466).
378378
* (py_proto_library) Fix import paths in Bazel 8.
379379
* (whl_library) Now the changes to the dependencies are correctly tracked when
380-
PyPI packages used in {bzl:obj}`whl_library` during the `repository_rule` phase
380+
PyPI packages used in `whl_library` during the repository rule phase
381381
change. Fixes [#2468](https://github.com/bazel-contrib/rules_python/issues/2468).
382382
+ (gazelle) Gazelle no longer ignores `setup.py` files by default. To restore
383383
this behavior, apply the `# gazelle:python_ignore_files setup.py` directive.
@@ -396,7 +396,7 @@ END_UNRELEASED_TEMPLATE
396396
* (pypi) Freethreaded packages are now fully supported in the
397397
{obj}`experimental_index_url` usage or the regular `pip.parse` usage.
398398
To select the free-threaded interpreter in the repo phase, please use
399-
the documented [env](/environment-variables.html) variables.
399+
the documented [env](environment-variables) variables.
400400
Fixes [#2386](https://github.com/bazel-contrib/rules_python/issues/2386).
401401
* (toolchains) Use the latest astrahl-sh toolchain release [20241206] for Python versions:
402402
* 3.9.21
@@ -490,7 +490,7 @@ Other changes:
490490
for the latest toolchain versions for each minor Python version. You can control
491491
the toolchain selection by using the
492492
{bzl:obj}`//python/config_settings:py_linux_libc` build flag.
493-
* (providers) Added {obj}`py_runtime_info.site_init_template` and
493+
* (providers) Added {obj}`PyRuntimeInfo.site_init_template` and
494494
{obj}`PyRuntimeInfo.site_init_template` for specifying the template to use to
495495
initialize the interpreter via venv startup hooks.
496496
* (runfiles) (Bazel 7.4+) Added support for spaces and newlines in runfiles paths
@@ -688,8 +688,8 @@ Other changes:
688688
* (bzlmod) The default value for the {obj}`--python_version` flag will now be
689689
always set to the default python toolchain version value.
690690
* (bzlmod) correctly wire the {attr}`pip.parse.extra_pip_args` all the
691-
way to {obj}`whl_library`. What is more we will pass the `extra_pip_args` to
692-
{obj}`whl_library` for `sdist` distributions when using
691+
way to `whl_library`. What is more we will pass the `extra_pip_args` to
692+
`whl_library` for `sdist` distributions when using
693693
{attr}`pip.parse.experimental_index_url`. See
694694
[#2239](https://github.com/bazel-contrib/rules_python/issues/2239).
695695
* (whl_filegroup): Provide per default also the `RECORD` file
@@ -737,8 +737,8 @@ Other changes:
737737

738738
{#v0-37-0-removed}
739739
### Removed
740-
* (precompiling) {obj}`--precompile_add_to_runfiles` has been removed.
741-
* (precompiling) {obj}`--pyc_collection` has been removed. The `pyc_collection`
740+
* (precompiling) `--precompile_add_to_runfiles` has been removed.
741+
* (precompiling) `--pyc_collection` has been removed. The `pyc_collection`
742742
attribute now bases its default on {obj}`--precompile`.
743743
* (precompiling) The {obj}`precompile=if_generated_source` value has been removed.
744744
* (precompiling) The {obj}`precompile_source_retention=omit_if_generated_source` value has been removed.
@@ -790,7 +790,7 @@ Other changes:
790790
in extra_requires in py_wheel rule.
791791
* (rules) Prevent pytest from trying run the generated stage2
792792
bootstrap .py file when using {obj}`--bootstrap_impl=script`
793-
* (toolchain) The {bzl:obj}`gen_python_config_settings` has been fixed to include
793+
* (toolchain) The `gen_python_config_settings` has been fixed to include
794794
the flag_values from the platform definitions.
795795

796796
{#v0-36-0-added}
@@ -1205,9 +1205,9 @@ Other changes:
12051205
depend on legacy labels instead of the hub repo aliases and you use the
12061206
`experimental_requirement_cycles`, now is a good time to migrate.
12071207

1208-
[python_default_visibility]: gazelle/README.md#directive-python_default_visibility
1208+
[python_default_visibility]: https://github.com/bazel-contrib/rules_python/tree/main/gazelle/README.md#directive-python_default_visibility
12091209
[test_file_pattern_issue]: https://github.com/bazel-contrib/rules_python/issues/1816
1210-
[test_file_pattern_docs]: gazelle/README.md#directive-python_test_file_pattern
1210+
[test_file_pattern_docs]: https://github.com/bazel-contrib/rules_python/tree/main/gazelle/README.md#directive-python_test_file_pattern
12111211
[20240224]: https://github.com/indygreg/python-build-standalone/releases/tag/20240224.
12121212
[20240415]: https://github.com/indygreg/python-build-standalone/releases/tag/20240415.
12131213

docs/devguide.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ more important for tests to balance understandability and maintainability.
3939

4040
### sh_py_run_test
4141

42-
The [`sh_py_run_test`](tests/support/sh_py_run_test.bzl) rule is a helper to
42+
The {gh-path}`sh_py_run_test <tests/support/sh_py_run_test.bzl` rule is a helper to
4343
make it easy to run a Python program with custom build settings using a shell
4444
script to perform setup and verification. This is best to use when verifying
4545
behavior needs certain environment variables or directory structures to
@@ -56,6 +56,8 @@ Python binaries and tests with custom build flags. This is best to use when
5656
verifying behavior that requires specific flags to be set and when the program
5757
itself can verify the desired state.
5858

59+
They are located in {gh-path}`tests/support/py_reconfig.bzl`
60+
5961
When adding a test, you may find the flag you need to set isn't supported by
6062
the rule. To have it support setting a new flag:
6163

python/private/rule_builders.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def _ToolchainType_build(self):
253253
self: implicitly added
254254
255255
Returns:
256-
{type}`config_common.toolchain_type`
256+
{type}`toolchain_type`
257257
"""
258258
kwargs = dict(self.kwargs)
259259
name = kwargs.pop("name") # Name must be positional
@@ -673,7 +673,7 @@ def _AttrsDict_build(self):
673673
"""Build an attribute dict for passing to `rule()`.
674674
675675
Returns:
676-
{type}`dict[str, attribute]` where the values are `attr.XXX` objects
676+
{type}`dict[str, Attribute]` where the values are `attr.XXX` objects
677677
"""
678678
attrs = {}
679679
for k, v in self.map.items():

sphinxdocs/inventories/bazel_inventory.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# Version: 7.3.0
44
# The remainder of this file is compressed using zlib
55
Action bzl:type 1 rules/lib/Action -
6+
Attribute bzl:type 1 rules/lib/builtins/Attribute -
67
CcInfo bzl:provider 1 rules/lib/providers/CcInfo -
78
CcInfo.linking_context bzl:provider-field 1 rules/lib/providers/CcInfo#linking_context -
9+
DefaultInfo bzl:type 1 rules/lib/providers/DefaultInfo -
810
ExecutionInfo bzl:type 1 rules/lib/providers/ExecutionInfo -
911
File bzl:type 1 rules/lib/File -
1012
Label bzl:type 1 rules/lib/Label -
@@ -38,6 +40,7 @@ config.string_list bzl:function 1 rules/lib/toplevel/config#string_list -
3840
config.target bzl:function 1 rules/lib/toplevel/config#target -
3941
config_common.FeatureFlagInfo bzl:type 1 rules/lib/toplevel/config_common#FeatureFlagInfo -
4042
config_common.toolchain_type bzl:function 1 rules/lib/toplevel/config_common#toolchain_type -
43+
ctx bzl:type 1 rules/lib/builtins/repository_ctx -
4144
ctx.actions bzl:obj 1 rules/lib/builtins/ctx#actions -
4245
ctx.aspect_ids bzl:obj 1 rules/lib/builtins/ctx#aspect_ids -
4346
ctx.attr bzl:obj 1 rules/lib/builtins/ctx#attr -
@@ -96,6 +99,7 @@ module_ctx.report_progress bzl:function 1 rules/lib/builtins/module_ctx#report_p
9699
module_ctx.root_module_has_non_dev_dependency bzl:function 1 rules/lib/builtins/module_ctx#root_module_has_non_dev_dependency -
97100
module_ctx.watch bzl:function 1 rules/lib/builtins/module_ctx#watch -
98101
module_ctx.which bzl:function 1 rules/lib/builtins/module_ctx#which -
102+
native bzl:obj 1 rules/lib/toplevel/native -
99103
native.existing_rule bzl:function 1 rules/lib/toplevel/native#existing_rule -
100104
native.existing_rules bzl:function 1 rules/lib/toplevel/native#existing_rules -
101105
native.exports_files bzl:function 1 rules/lib/toplevel/native#exports_files -
@@ -140,6 +144,8 @@ repository_os bzl:type 1 rules/lib/builtins/repository_os -
140144
repository_os.arch bzl:obj 1 rules/lib/builtins/repository_os#arch
141145
repository_os.environ bzl:obj 1 rules/lib/builtins/repository_os#environ
142146
repository_os.name bzl:obj 1 rules/lib/builtins/repository_os#name
147+
rule bzl:type 1 rules/lib/builtins/rule -
148+
rule bzl:function rules/lib/globals/bzl.html#rule -
143149
runfiles bzl:type 1 rules/lib/builtins/runfiles -
144150
runfiles.empty_filenames bzl:type 1 rules/lib/builtins/runfiles#empty_filenames -
145151
runfiles.files bzl:type 1 rules/lib/builtins/runfiles#files -
@@ -156,6 +162,8 @@ testing.TestEnvironment bzl:function 1 rules/lib/toplevel/testing#TestEnvironmen
156162
testing.analysis_test bzl:rule 1 rules/lib/toplevel/testing#analysis_test -
157163
toolchain bzl:rule 1 reference/be/platforms-and-toolchains#toolchain -
158164
toolchain.exec_compatible_with bzl:rule 1 reference/be/platforms-and-toolchains#toolchain.exec_compatible_with -
159-
toolchain.target_settings bzl:attr 1 reference/be/platforms-and-toolchains#toolchain.target_settings -
160165
toolchain.target_compatible_with bzl:attr 1 reference/be/platforms-and-toolchains#toolchain.target_compatible_with -
166+
toolchain.target_settings bzl:attr 1 reference/be/platforms-and-toolchains#toolchain.target_settings -
161167
toolchain_type bzl:type 1 rules/lib/builtins/toolchain_type.html -
168+
transition bzl:type 1 rules/lib/builtins/transition -
169+
tuple bzl:type 1 rules/lib/core/tuple -

sphinxdocs/src/sphinx_bzl/bzl.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def _make_xrefs_for_arg_attr(
394394
# This allows referencing an arg as e.g `funcname.argname`
395395
anchor_id,
396396
# This allows referencing an arg as simply `argname`
397-
arg_name
397+
arg_name,
398398
],
399399
)
400400

@@ -503,7 +503,22 @@ def run(self) -> list[docutils_nodes.Node]:
503503
self.env.ref_context["bzl:object_id_stack"] = []
504504
self.env.ref_context["bzl:doc_id_stack"] = []
505505

506-
_, _, basename = file_label.partition(":")
506+
package_label, _, basename = file_label.partition(":")
507+
508+
# Transform //foo/bar:BUILD.bazel into "bar"
509+
# This allows referencing "bar" as itself
510+
extra_alt_names = []
511+
if basename in ("BUILD.bazel", "BUILD"):
512+
# Allow xref //foo
513+
extra_alt_names.append(package_label)
514+
basename = os.path.basename(package_label)
515+
# Handle //:BUILD.bazel
516+
if not basename:
517+
# There isn't a convention for referring to the root package
518+
# besides `//:`, which is already the file_label. So just
519+
# use some obvious value
520+
basename = "__ROOT_BAZEL_PACKAGE__"
521+
507522
index_description = f"File {label}"
508523
absolute_label = repo + label
509524
self.env.get_domain("bzl").add_object(
@@ -527,7 +542,8 @@ def run(self) -> list[docutils_nodes.Node]:
527542
file_label,
528543
# Allow xref bar.bzl
529544
basename,
530-
],
545+
]
546+
+ extra_alt_names,
531547
)
532548
index_node = addnodes.index(
533549
entries=[
@@ -1750,6 +1766,11 @@ def _on_missing_reference(app, env: environment.BuildEnvironment, node, contnode
17501766
# There's no Bazel docs for None, so prevent missing xrefs warning
17511767
if node["reftarget"] == "None":
17521768
return contnode
1769+
1770+
# Any and object are just conventions from Python, but useful for
1771+
# indicating what something is in Starlark, so treat them specially.
1772+
if node["reftarget"] in ("Any", "object"):
1773+
return contnode
17531774
return None
17541775

17551776

sphinxdocs/tests/sphinx_stardoc/sphinx_output_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def _doc_element(self, doc):
6767
("tag_class_attr_using_attr_role_just_attr_name", "ta1", "module_extension.html#myext.mytag.ta1"),
6868
("file_without_repo", "//lang:rule.bzl", "rule.html"),
6969
("file_with_repo", "@testrepo//lang:rule.bzl", "rule.html"),
70+
("package_absolute", "//lang", "target.html"),
71+
("package_basename", "lang", "target.html"),
7072
# fmt: on
7173
)
7274
def test_xrefs(self, text, href):

sphinxdocs/tests/sphinx_stardoc/xrefs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ Various tests of cross referencing support
5151

5252
* without repo {obj}`//lang:rule.bzl`
5353
* with repo {obj}`@testrepo//lang:rule.bzl`
54+
55+
## Package refs
56+
57+
* absolute label {obj}`//lang`
58+
* package basename {obj}`lang`

tests/bootstrap_impls/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ load("@rules_shell//shell:sh_test.bzl", "sh_test")
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_binary", "py_reconfig_test", "sh_py_run_test")
16+
load("//tests/support:py_reconfig.bzl", "py_reconfig_binary", "py_reconfig_test")
17+
load("//tests/support:sh_py_run_test.bzl", "sh_py_run_test")
1718
load("//tests/support:support.bzl", "SUPPORTS_BOOTSTRAP_SCRIPT")
1819
load(":venv_relative_path_tests.bzl", "relative_path_test_suite")
1920

tests/bootstrap_impls/a/b/c/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
2-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
2+
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
33

44
_SUPPORTS_BOOTSTRAP_SCRIPT = select({
55
"@platforms//os:windows": ["@platforms//:incompatible"],

tests/interpreter/interpreter_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""This file contains helpers for testing the interpreter rule."""
1616

17-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
17+
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
1818

1919
# The versions of Python that we want to run the interpreter tests against.
2020
PYTHON_VERSIONS_TO_TEST = (

0 commit comments

Comments
 (0)