Skip to content

Commit 3c9423a

Browse files
authored
docs: convert raw URLs in generated docs and docstrings to hyperlinks (bazel-contrib#3987)
Plain text URLs in documentation Markdown files and Starlark/Python docstrings were rendered as non-clickable text in the generated HTML output, making navigation cumbersome. To fix this, raw URLs are converted into MyST autolinks (<https://...>), Markdown links, and {gh-issue} roles. A custom {pep} Sphinx role is also introduced in docs/conf.py to dynamically resolve PEP numbers to https://peps.python.org/pep-XXXX/, and existing PEP references in docstrings are updated to use {pep}.
1 parent 2b482da commit 3c9423a

19 files changed

Lines changed: 56 additions & 43 deletions

‎CHANGELOG.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ Other changes:
721721
* (core) `#!/usr/bin/env bash` is now used as a shebang in the stage1 bootstrap template.
722722
* (gazelle:docs) The Gazelle docs have been migrated from {gh-path}`gazelle/README.md` to
723723
{gh-path}`gazelle/docs` and are now available on the primary documentation site
724-
at https://rules-python.readthedocs.io/en/latest/gazelle/docs/index.html
724+
at <https://rules-python.readthedocs.io/en/latest/gazelle/docs/index.html>
725725

726726
[20250808]: https://github.com/astral-sh/python-build-standalone/releases/tag/20250808
727727

@@ -1133,7 +1133,7 @@ Other changes:
11331133
{#v1-2-0-changed}
11341134
### Changed
11351135
* (rules) `py_proto_library` is deprecated in favour of the
1136-
implementation in https://github.com/protocolbuffers/protobuf. It will be
1136+
implementation in <https://github.com/protocolbuffers/protobuf>. It will be
11371137
removed in the future release.
11381138
* (pypi) {obj}`pip.override` will now be ignored instead of raising an error,
11391139
fixes [#2550](https://github.com/bazel-contrib/rules_python/issues/2550).
@@ -2117,7 +2117,7 @@ Other changes:
21172117
`common --@rules_python//python/config_settings:python_version=X.Y.Z`.
21182118

21192119
* New Python versions available: `3.11.7`, `3.12.1` using
2120-
https://github.com/indygreg/python-build-standalone/releases/tag/20240107.
2120+
<https://github.com/indygreg/python-build-standalone/releases/tag/20240107>.
21212121

21222122
* (toolchain) Allow setting `x.y` as the `python_version` parameter in
21232123
the version-aware `py_binary` and `py_test` rules. This allows users to
@@ -2269,7 +2269,7 @@ Other changes:
22692269

22702270
* (docs) bzlmod extensions are now documented on rules-python.readthedocs.io
22712271
* (docs) Support and backwards compatibility policies have been documented.
2272-
See https://rules-python.readthedocs.io/en/latest/support.html
2272+
See <https://rules-python.readthedocs.io/en/latest/support.html>
22732273
* (gazelle) `file` generation mode can now also add `__init__.py` to the srcs
22742274
attribute for every target in the package. This is enabled through a separate
22752275
directive `python_generation_mode_per_file_include_init`.
@@ -2401,7 +2401,7 @@ Breaking changes:
24012401
the `py_binary` rule used to build it.
24022402

24032403
* New Python versions available: `3.8.17`, `3.11.5` using
2404-
https://github.com/indygreg/python-build-standalone/releases/tag/20230826.
2404+
<https://github.com/indygreg/python-build-standalone/releases/tag/20230826>.
24052405

24062406
* (gazelle) New `# gazelle:python_generation_mode file` directive to support
24072407
generating one `py_library` per file.
@@ -2421,7 +2421,7 @@ Breaking changes:
24212421
time being.
24222422

24232423
* New Python versions available: `3.8.18`, `3.9.18`, `3.10.13`, `3.11.6`, `3.12.0` using
2424-
https://github.com/indygreg/python-build-standalone/releases/tag/20231002.
2424+
<https://github.com/indygreg/python-build-standalone/releases/tag/20231002>.
24252425
`3.12.0` support is considered beta and may have issues.
24262426

24272427
### Removed

‎docs/conf.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Configuration file for the Sphinx documentation builder.
22

33
import os
4+
import re
5+
6+
from docutils import nodes
47

58
# -- Project information
69
project = "rules_python"
@@ -219,9 +222,19 @@
219222
]
220223

221224

225+
def _pep_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
226+
match = re.search(r"\d+", text)
227+
pep_num = match.group(0) if match else text
228+
pep_url = f"https://peps.python.org/pep-{pep_num.zfill(4)}/"
229+
display_text = text if text.startswith("PEP") else f"PEP {pep_num}"
230+
node = nodes.reference(rawtext, display_text, refuri=pep_url, **options)
231+
return [node], []
232+
233+
222234
def setup(app):
223235
# Pygments says it supports starlark, but it doesn't seem to actually
224236
# recognize `starlark` as a name. So just manually map it to python.
225237
from sphinx.highlighting import lexer_classes
226238

227239
app.add_lexer("starlark", lexer_classes["python"])
240+
app.add_role("pep", _pep_role)

‎docs/extending.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Extending the core rules is most useful when you want all or most of the
2323
behavior of a core rule.
2424
:::
2525

26-
Follow or comment on https://github.com/bazel-contrib/rules_python/issues/1647
26+
Follow or comment on {gh-issue}`1647`
2727
for the development of APIs to support custom derived rules.
2828

2929
## Creating custom rules

‎docs/toolchains.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ pip_parse(
473473
```
474474

475475
After registration, your Python targets will use the toolchain's interpreter during execution, but a system-installed interpreter
476-
is still used to "bootstrap" Python targets (see https://github.com/bazel-contrib/rules_python/issues/691).
476+
is still used to "bootstrap" Python targets (see {gh-issue}`691`).
477477
You may also find some quirks while using this toolchain. Please refer to [python-build-standalone documentation's _Quirks_ section](https://gregoryszorc.com/docs/python-build-standalone/main/quirks.html).
478478

479479
## Local toolchain

‎gazelle/docs/directives.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ Version 1.9.0 includes a fix ({gh-pr}`3498`) for a long-standing issue
837837
({gh-issue}`3497`) where ancestor `conftest.py` files were not automatically
838838
added as dependencies of {bzl:obj}`py_test` targets.
839839

840-
However, some people may not want this behavior (see https://xkcd.com/1172/).
840+
However, some people may not want this behavior (see <https://xkcd.com/1172/>).
841841
Thus the `python_include_ancestor_conftest` directive controls this behavior.
842842
It defaults to `true`, which causes all ancestor `conftest.py` files to be
843843
included as dependencies for {bzl:obj}`py_test` targets.

‎python/packaging.bzl‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ py_wheel_dist = rule(
6363
doc = """\
6464
Prepare a dist/ folder, following Python's packaging standard practice.
6565
66-
See https://packaging.python.org/en/latest/tutorials/packaging-projects/#generating-distribution-archives
66+
See <https://packaging.python.org/en/latest/tutorials/packaging-projects/#generating-distribution-archives>
6767
which recommends a dist/ folder containing the wheel file(s), source distributions, etc.
6868
6969
This also has the advantage that stamping information is included in the wheel's filename.
@@ -94,7 +94,7 @@ def py_wheel(
9494
**kwargs):
9595
"""Builds a Python Wheel.
9696
97-
Wheels are Python distribution format defined in https://www.python.org/dev/peps/pep-0427/.
97+
Wheels are Python distribution format defined in {pep}`PEP 427`.
9898
9999
This macro packages a set of targets into a single wheel.
100100
It wraps the [py_wheel rule](#py_wheel_rule).
@@ -144,7 +144,7 @@ def py_wheel(
144144
To publish the wheel to PyPI, the twine package is required and it is installed
145145
by default on `bzlmod` setups. On legacy `WORKSPACE`, `rules_python`
146146
doesn't provide `twine` itself
147-
(see https://github.com/bazel-contrib/rules_python/issues/1016), but
147+
(see {gh-issue}`1016`), but
148148
you can install it with `pip_parse`, just like we do any other dependencies.
149149
150150
Once you've installed twine, you can pass its label to the `twine`
@@ -160,7 +160,7 @@ def py_wheel(
160160
)
161161
```
162162
163-
Now you can run a command like the following, which publishes to https://test.pypi.org/
163+
Now you can run a command like the following, which publishes to <https://test.pypi.org/>
164164
165165
```sh
166166
% TWINE_USERNAME=__token__ TWINE_PASSWORD=pypi-*** \\
@@ -172,7 +172,7 @@ def py_wheel(
172172
name: A unique name for this target.
173173
twine: A label of the external location of the py_library target for twine
174174
twine_binary: A label of the external location of a binary target for twine.
175-
publish_args: arguments passed to twine, e.g. ["--repository-url", "https://pypi.my.org/simple/"].
175+
publish_args: arguments passed to twine, e.g. `["--repository-url", "https://pypi.my.org/simple/"]`.
176176
These are subject to make var expansion, as with the `args` attribute.
177177
Note that you can also pass additional args to the bazel run command as in the example above.
178178
**kwargs: other named parameters passed to the underlying [py_wheel rule](#py_wheel_rule)

‎python/private/attributes.bzl‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ source files. Possible values are:
271271
the source file. This is most useful when the code won't be modified.
272272
273273
For more information on pyc invalidation modes, see
274-
https://docs.python.org/3/library/py_compile.html#py_compile.PycInvalidationMode
274+
<https://docs.python.org/3/library/py_compile.html#py_compile.PycInvalidationMode>
275275
""",
276276
default = PrecompileInvalidationModeAttr.AUTO,
277277
values = sorted(PrecompileInvalidationModeAttr.__members__.values()),
@@ -281,7 +281,7 @@ https://docs.python.org/3/library/py_compile.html#py_compile.PycInvalidationMode
281281
The optimization level for precompiled files.
282282
283283
For more information about optimization levels, see the `compile()` function's
284-
`optimize` arg docs at https://docs.python.org/3/library/functions.html#compile
284+
`optimize` arg docs at <https://docs.python.org/3/library/functions.html#compile>
285285
286286
NOTE: The value `-1` means "current interpreter", which will be the interpreter
287287
used _at build time when pycs are generated_, not the interpreter used at
@@ -422,7 +422,7 @@ These values are transitioned on, so will affect the analysis graph and the
422422
associated memory overhead. The more unique configurations in your overall
423423
build, the more memory and (often unnecessary) re-analysis and re-building
424424
can occur. See
425-
https://bazel.build/extending/config#memory-performance-considerations for
425+
<https://bazel.build/extending/config#memory-performance-considerations> for
426426
more information about risks and considerations.
427427
:::
428428

‎python/private/py_cc_toolchain_info.bzl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ If available, information about C libraries, struct with fields:
105105
"platform_machine": """
106106
:type: str
107107
108-
The [PEP 508](https://peps.python.org/pep-0508/) `platform_machine` marker
108+
The {pep}`PEP 508` `platform_machine` marker
109109
value for the target architecture, e.g. 'x86_64', 'aarch64'.
110110
""",
111111
"platform_tag": """\
@@ -122,7 +122,7 @@ The Python Major.Minor version.
122122
"sys_platform": """
123123
:type: str
124124
125-
The [PEP 508](https://peps.python.org/pep-0508/) `sys_platform` marker value
125+
The {pep}`0508` `sys_platform` marker value
126126
for the target OS, e.g. 'linux', 'darwin', 'win32'.
127127
""",
128128
},

‎python/private/py_cc_toolchain_rule.bzl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Implementation of py_cc_toolchain rule.
1616
1717
NOTE: This is a beta-quality feature. APIs subject to change until
18-
https://github.com/bazel-contrib/rules_python/issues/824 is considered done.
18+
{gh-issue}`824` is considered done.
1919
"""
2020

2121
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")

‎python/private/py_exec_tools_info.bzl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ toolchain.
4141
:::{warning}
4242
This does not work correctly with RBE. Use {obj}`exec_runtime` instead.
4343
44-
Once https://github.com/bazelbuild/bazel/issues/23620 is resolved this warning
44+
Once [bazelbuild/bazel#23620](https://github.com/bazelbuild/bazel/issues/23620) is resolved this warning
4545
may be removed.
4646
:::
4747
""",

0 commit comments

Comments
 (0)