Skip to content

Commit 5a28b4b

Browse files
authored
Merge branch 'main' into refactor/namespace-pkg-star
2 parents 4ed19e0 + 6ffeff6 commit 5a28b4b

File tree

25 files changed

+280
-121
lines changed

25 files changed

+280
-121
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/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@
125125
primary_domain = None # The default is 'py', which we don't make much use of
126126
nitpicky = True
127127

128+
nitpick_ignore_regex = [
129+
# External xrefs aren't setup: ignore missing xref warnings
130+
# External xrefs to sphinx isn't setup: ignore missing xref warnings
131+
("py:.*", "(sphinx|docutils|ast|enum|collections|typing_extensions).*"),
132+
]
133+
128134
# --- Intersphinx configuration
129135

130136
intersphinx_mapping = {

DEVELOPING.md renamed to docs/devguide.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# For Developers
1+
# Dev Guide
22

33
This document covers tips and guidance for working on the rules_python code
44
base. A primary audience for it is first time contributors.
@@ -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

docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and the older way of using `WORKSPACE`.
77
It assumes you have a `requirements.txt` file with your PyPI dependencies.
88

99
For more details information about configuring `rules_python`, see:
10-
* [Configuring the runtime](toolchains)
10+
* [Configuring the runtime](configuring-toolchains)
1111
* [Configuring third party dependencies (pip/pypi)](pypi-dependencies)
1212
* [API docs](api/index)
1313

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ gazelle
104104
REPL <repl>
105105
Extending <extending>
106106
Contributing <contributing>
107+
devguide
107108
support
108109
Changelog <changelog>
109110
api/index

docs/toolchains.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
:::{default-domain} bzl
22
:::
33

4+
(configuring-toolchains)=
45
# Configuring Python toolchains and runtimes
56

67
This documents how to configure the Python toolchain and runtimes for different

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/private/proto_to_markdown.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ def _render_repository_rule(self, repo_rule: stardoc_output_pb2.RepositoryRuleIn
216216
self._render_attributes(repo_rule.attribute)
217217
if repo_rule.environ:
218218
self._write(":envvars: ", ", ".join(sorted(repo_rule.environ)))
219-
self._write("\n")
219+
self._write("\n\n")
220+
221+
self._write("::::::\n")
220222

221223
def _render_rule(self, rule: stardoc_output_pb2.RuleInfo):
222224
rule_name = rule.rule_name

sphinxdocs/src/sphinx_bzl/bzl.py

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,12 @@ def _make_xrefs_for_arg_attr(
390390
descr=index_description,
391391
),
392392
),
393-
# This allows referencing an arg as e.g `funcname.argname`
394-
alt_names=[anchor_id],
393+
alt_names=[
394+
# This allows referencing an arg as e.g `funcname.argname`
395+
anchor_id,
396+
# This allows referencing an arg as simply `argname`
397+
arg_name,
398+
],
395399
)
396400

397401
# Two changes to how arg xrefs are created:
@@ -498,7 +502,55 @@ def run(self) -> list[docutils_nodes.Node]:
498502
self.env.ref_context["bzl:file"] = file_label
499503
self.env.ref_context["bzl:object_id_stack"] = []
500504
self.env.ref_context["bzl:doc_id_stack"] = []
501-
return []
505+
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+
522+
index_description = f"File {label}"
523+
absolute_label = repo + label
524+
self.env.get_domain("bzl").add_object(
525+
_ObjectEntry(
526+
full_id=absolute_label,
527+
display_name=absolute_label,
528+
object_type="obj",
529+
search_priority=1,
530+
index_entry=domains.IndexEntry(
531+
name=basename,
532+
subtype=_INDEX_SUBTYPE_NORMAL,
533+
docname=self.env.docname,
534+
anchor="",
535+
extra="",
536+
qualifier="",
537+
descr=index_description,
538+
),
539+
),
540+
alt_names=[
541+
# Allow xref //foo:bar.bzl
542+
file_label,
543+
# Allow xref bar.bzl
544+
basename,
545+
]
546+
+ extra_alt_names,
547+
)
548+
index_node = addnodes.index(
549+
entries=[
550+
_index_node_tuple("single", f"File; {label}", ""),
551+
]
552+
)
553+
return [index_node]
502554

503555

504556
class _BzlAttrInfo(sphinx_docutils.SphinxDirective):
@@ -1156,10 +1208,10 @@ class _BzlTagClass(_BzlCallable):
11561208

11571209
doc_field_types = [
11581210
_BzlGroupedField(
1159-
"arg",
1211+
"attr",
11601212
label=_("Attributes"),
11611213
names=["attr"],
1162-
rolename="arg",
1214+
rolename="attr",
11631215
can_collapse=False,
11641216
),
11651217
]
@@ -1463,6 +1515,8 @@ class _BzlDomain(domains.Domain):
14631515
# :obj:.
14641516
# NOTE: We also use these object types for categorizing things in the
14651517
# generated index page.
1518+
# NOTE: The object type keys control what object types are recognized
1519+
# in inventory files.
14661520
object_types = {
14671521
"arg": domains.ObjType("arg", "arg", "obj"), # macro/function arg
14681522
"aspect": domains.ObjType("aspect", "aspect", "obj"),
@@ -1486,6 +1540,8 @@ class _BzlDomain(domains.Domain):
14861540
# types are objects that have a constructor and methods/attrs
14871541
"type": domains.ObjType("type", "type", "obj"),
14881542
"typedef": domains.ObjType("typedef", "typedef", "type", "obj"),
1543+
# generic objs usually come from inventories
1544+
"obj": domains.ObjType("object", "obj"),
14891545
}
14901546

14911547
# This controls:
@@ -1710,6 +1766,11 @@ def _on_missing_reference(app, env: environment.BuildEnvironment, node, contnode
17101766
# There's no Bazel docs for None, so prevent missing xrefs warning
17111767
if node["reftarget"] == "None":
17121768
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
17131774
return None
17141775

17151776

0 commit comments

Comments
 (0)