Skip to content

Commit 53f7407

Browse files
authored
chore: cleanup exposed python_repository symbols and add docs (bazel-contrib#2189)
The bazel inventory for this sphinxdocs is in bazel-contrib#2188. Removed the things that are definitely not used and the rest of the symbols can be left until we become bzlmod only - they do not require much maintenance.
1 parent acc4cef commit 53f7407

File tree

6 files changed

+37
-32
lines changed

6 files changed

+37
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ A brief description of the categories of changes:
5656
or deriving a new one from the original.
5757
* (py_wheel) Removed use of bash to avoid failures on Windows machines which do not
5858
have it installed.
59+
* (docs) Automatically generated documentation for {bzl:obj}`python_register_toolchains`
60+
and related symbols.
5961

6062
### Removed
61-
* Nothing yet
63+
* (toolchains): Removed accidentally exposed `http_archive` symbol from
64+
`python/repositories.bzl`.
6265

6366
## [0.35.0] - 2024-08-15
6467

docs/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ sphinx_stardocs(
8989
"//python:py_runtime_bzl",
9090
"//python:py_runtime_info_bzl",
9191
"//python:py_test_bzl",
92+
"//python:repositories_bzl",
9293
"//python/cc:py_cc_toolchain_info_bzl",
9394
"//python/entry_points:py_console_script_binary_bzl",
9495
"//python/private:py_exec_tools_info_bzl",

examples/bzlmod/MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/private/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ bzl_library(
310310
srcs = ["toolchains_repo.bzl"],
311311
deps = [
312312
":repo_utils_bzl",
313+
":text_util_bzl",
313314
"//python:versions_bzl",
314315
],
315316
)

python/private/python_repositories.bzl

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ def is_standalone_interpreter(rctx, python_interpreter_path, *, logger = None):
8080
"""Query a python interpreter target for whether or not it's a rules_rust provided toolchain
8181
8282
Args:
83-
rctx (repository_ctx): The repository rule's context object.
84-
python_interpreter_path (path): A path representing the interpreter.
83+
rctx: {type}`repository_ctx` The repository rule's context object.
84+
python_interpreter_path: {type}`path` A path representing the interpreter.
8585
logger: Optional logger to use for operations.
8686
8787
Returns:
88-
bool: Whether or not the target is from a rules_python generated toolchain.
88+
{type}`bool` Whether or not the target is from a rules_python generated toolchain.
8989
"""
9090

9191
# Only update the location when using a hermetic toolchain.
@@ -563,42 +563,43 @@ For more information see the official bazel docs
563563
def python_register_toolchains(
564564
name,
565565
python_version,
566-
distutils = None,
567-
distutils_content = None,
568566
register_toolchains = True,
569567
register_coverage_tool = False,
570568
set_python_version_constraint = False,
571-
tool_versions = TOOL_VERSIONS,
569+
tool_versions = None,
572570
**kwargs):
573571
"""Convenience macro for users which does typical setup.
574572
575-
- Create a repository for each built-in platform like "python_linux_amd64" -
573+
- Create a repository for each built-in platform like "python_3_8_linux_amd64" -
576574
this repository is lazily fetched when Python is needed for that platform.
577575
- Create a repository exposing toolchains for each platform like
578576
"python_platforms".
579577
- Register a toolchain pointing at each platform.
578+
580579
Users can avoid this macro and do these steps themselves, if they want more
581580
control.
581+
582582
Args:
583-
name: base name for all created repos, like "python38".
584-
python_version: the Python version.
585-
distutils: see the distutils attribute in the python_repository repository rule.
586-
distutils_content: see the distutils_content attribute in the python_repository repository rule.
587-
register_toolchains: Whether or not to register the downloaded toolchains.
588-
register_coverage_tool: Whether or not to register the downloaded coverage tool to the toolchains.
589-
NOTE: Coverage support using the toolchain is only supported in Bazel 6 and higher.
590-
591-
set_python_version_constraint: When set to true, target_compatible_with for the toolchains will include a version constraint.
592-
tool_versions: a dict containing a mapping of version with SHASUM and platform info. If not supplied, the defaults
593-
in python/versions.bzl will be used.
594-
**kwargs: passed to each python_repositories call.
583+
name: {type}`str` base name for all created repos, e.g. "python_3_8".
584+
python_version: {type}`str` the Python version.
585+
register_toolchains: {type}`bool` Whether or not to register the downloaded toolchains.
586+
register_coverage_tool: {type}`bool` Whether or not to register the
587+
downloaded coverage tool to the toolchains.
588+
set_python_version_constraint: {type}`bool` When set to `True`,
589+
`target_compatible_with` for the toolchains will include a version
590+
constraint.
591+
tool_versions: {type}`dict` contains a mapping of version with SHASUM
592+
and platform info. If not supplied, the defaults in
593+
python/versions.bzl will be used.
594+
**kwargs: passed to each {obj}`python_repository` call.
595595
"""
596596

597597
if BZLMOD_ENABLED:
598598
# you cannot used native.register_toolchains when using bzlmod.
599599
register_toolchains = False
600600

601601
base_url = kwargs.pop("base_url", DEFAULT_RELEASE_BASE_URL)
602+
tool_versions = tool_versions or TOOL_VERSIONS
602603

603604
python_version = full_version(python_version)
604605

@@ -656,8 +657,6 @@ def python_register_toolchains(
656657
python_version = python_version,
657658
release_filename = release_filename,
658659
urls = urls,
659-
distutils = distutils,
660-
distutils_content = distutils_content,
661660
strip_prefix = strip_prefix,
662661
coverage_tool = coverage_tool,
663662
**kwargs
@@ -709,11 +708,11 @@ def python_register_multi_toolchains(
709708
"""Convenience macro for registering multiple Python toolchains.
710709
711710
Args:
712-
name: base name for each name in python_register_toolchains call.
713-
python_versions: the Python version.
714-
default_version: the default Python version. If not set, the first version in
715-
python_versions is used.
716-
**kwargs: passed to each python_register_toolchains call.
711+
name: {type}`str` base name for each name in {obj}`python_register_toolchains` call.
712+
python_versions: {type}`list[str]` the Python versions.
713+
default_version: {type}`str` the default Python version. If not set,
714+
the first version in python_versions is used.
715+
**kwargs: passed to each {obj}`python_register_toolchains` call.
717716
"""
718717
if len(python_versions) == 0:
719718
fail("python_versions must not be empty")

python/repositories.bzl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
load(
1919
"//python/private:python_repositories.bzl",
2020
_STANDALONE_INTERPRETER_FILENAME = "STANDALONE_INTERPRETER_FILENAME",
21-
_http_archive = "http_archive",
2221
_is_standalone_interpreter = "is_standalone_interpreter",
2322
_py_repositories = "py_repositories",
2423
_python_register_multi_toolchains = "python_register_multi_toolchains",
@@ -30,9 +29,11 @@ py_repositories = _py_repositories
3029
python_register_multi_toolchains = _python_register_multi_toolchains
3130
python_register_toolchains = _python_register_toolchains
3231

32+
# Useful for documentation, but is not intended for public use - the python
33+
# module extension will be the main interface in the future.
34+
python_repository = _python_repository
35+
3336
# These symbols are of questionable public visibility. They were probably
3437
# not intended to be actually public.
3538
STANDALONE_INTERPRETER_FILENAME = _STANDALONE_INTERPRETER_FILENAME
36-
http_archive = _http_archive
3739
is_standalone_interpreter = _is_standalone_interpreter
38-
python_repository = _python_repository

0 commit comments

Comments
 (0)