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(bzlmod): Adding base_url attr to python.toolchain #1216

Closed
wants to merge 1 commit into from
Closed
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
38 changes: 29 additions & 9 deletions python/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,27 @@ load("@rules_python//python/private:toolchains_repo.bzl", "get_host_os_arch", "g
def _python_impl(module_ctx):
for mod in module_ctx.modules:
for toolchain_attr in mod.tags.toolchain:
python_register_toolchains(
name = toolchain_attr.name,
python_version = toolchain_attr.python_version,
bzlmod = True,
# Toolchain registration in bzlmod is done in MODULE file
register_toolchains = False,
register_coverage_tool = toolchain_attr.configure_coverage_tool,
ignore_root_user_error = toolchain_attr.ignore_root_user_error,
)
if toolchain_attr.base_url:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rickeylev not sure if there is a cleaner way to do this. If we don't set the base_url when we call python.toolchain, we end up with an empty string passed in. Then python_register_toolchains passes in an empty value to python_repository. We may have a weird use case where an empty URL is allowed; if not, I can test for an empty URL in python_register_toolchains, which is fewer lines of code.

python_register_toolchains(
name = toolchain_attr.name,
python_version = toolchain_attr.python_version,
bzlmod = True,
# Toolchain registration in bzlmod is done in MODULE file
register_toolchains = False,
register_coverage_tool = toolchain_attr.configure_coverage_tool,
ignore_root_user_error = toolchain_attr.ignore_root_user_error,
base_url = toolchain_attr.base_url,
)
else:
python_register_toolchains(
name = toolchain_attr.name,
python_version = toolchain_attr.python_version,
bzlmod = True,
# Toolchain registration in bzlmod is done in MODULE file
register_toolchains = False,
register_coverage_tool = toolchain_attr.configure_coverage_tool,
ignore_root_user_error = toolchain_attr.ignore_root_user_error,
)
host_hub_name = toolchain_attr.name + "_host_interpreter"
_host_hub(
name = host_hub_name,
Expand All @@ -44,6 +56,14 @@ python = module_extension(
tag_classes = {
"toolchain": tag_class(
attrs = {
"base_url": attr.string(
mandatory = False,
doc = """\
The URL that is used to override rules_python DEFAULT_RELEASE_BASE_URL. This rule set downloads
the different Python binaries from this website. Override this URL if you want to have rules_python
download the hermetic versions of Python from a different website.
""",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the bazel downloader for this instead?

See https://blog.aspect.dev/configuring-bazels-downloader

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! I asked the folks on #1172 to get their opinion. I think folks are using base_url, so if we are not going to support it people will have to migrate to this as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

),
"configure_coverage_tool": attr.bool(
mandatory = False,
doc = "Whether or not to configure the default coverage tool for the toolchains.",
Expand Down