Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow custom bootstrap template in python_repository #2032

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ A brief description of the categories of changes:
replacement for the "autodetecting" toolchain.
* (gazelle) Added new `python_label_convention` and `python_label_normalization` directives. These directive
allows altering default Gazelle label format to third-party dependencies useful for re-using Gazelle plugin
with other rules, including `rules_pycross`. See [#1939](https://github.com/bazelbuild/rules_python/issues/1939).
with other rules, including `rules_pycross`. See [#1939](https://github.com/bazelbuild/rules_python/issues/1939).
* (toolchains) `python_register_toolchains` and `python_repository` now accepts `bootstrap_template`
and `stage2_bootstrap_template` attributes. These attributes are then passed to the underlying
`py_runtime` rule to control the bootstrap template used.

### Removed
* (pip): Removes the `entrypoint` macro that was replaced by `py_console_script_binary` in 0.26.0.
Expand Down
16 changes: 16 additions & 0 deletions python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ py_runtime(
python_version = "PY3",
implementation_name = 'cpython',
pyc_tag = "cpython-{interpreter_version_info_major}{interpreter_version_info_minor}",
bootstrap_template = {bootstrap_template},
stage2_bootstrap_template = {stage2_bootstrap_template},
)

py_runtime_pair(
Expand Down Expand Up @@ -411,6 +413,8 @@ py_exec_tools_toolchain(
interpreter_version_info_major = python_version_info[0],
interpreter_version_info_minor = python_version_info[1],
interpreter_version_info_micro = python_version_info[2],
bootstrap_template = repr(str(rctx.attr.bootstrap_template)),
stage2_bootstrap_template = repr(str(rctx.attr.stage2_bootstrap_template)),
)
rctx.delete("python")
rctx.symlink(python_bin, "python")
Expand All @@ -419,6 +423,7 @@ py_exec_tools_toolchain(

attrs = {
"auth_patterns": rctx.attr.auth_patterns,
"bootstrap_template": rctx.attr.bootstrap_template,
"coverage_tool": rctx.attr.coverage_tool,
"distutils": rctx.attr.distutils,
"distutils_content": rctx.attr.distutils_content,
Expand All @@ -430,6 +435,7 @@ py_exec_tools_toolchain(
"python_version": python_version,
"release_filename": release_filename,
"sha256": rctx.attr.sha256,
"stage2_bootstrap_template": rctx.attr.stage2_bootstrap_template,
"strip_prefix": rctx.attr.strip_prefix,
}

Expand All @@ -447,6 +453,11 @@ python_repository = repository_rule(
"auth_patterns": attr.string_dict(
doc = "Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive",
),
"bootstrap_template": attr.label(
default = "//python/private:bootstrap_template",
allow_single_file = True,
doc = "See the bootstrap_template attribute in the py_runtime rule.",
),
"coverage_tool": attr.string(
# Mirrors the definition at
# https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/python/py_runtime_rule.bzl
Expand Down Expand Up @@ -511,6 +522,11 @@ For more information see the official bazel docs
doc = "The SHA256 integrity hash for the Python interpreter tarball.",
mandatory = True,
),
"stage2_bootstrap_template": attr.label(
default = "//python/private:stage2_bootstrap_template",
allow_single_file = True,
doc = "See the stage2_bootstrap_template attribute in the py_runtime rule.",
),
"strip_prefix": attr.string(
doc = "A directory prefix to strip from the extracted files.",
),
Expand Down