Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ A brief description of the categories of changes:
have it installed.
* (docs) Automatically generated documentation for {bzl:obj}`python_register_toolchains`
and related symbols.
* (toolchains) Added {attr}`python_repository.patch_strip` attribute for
allowing values that are other than `1`, which has been hard-coded up until
now. If you are relying on the undocumented `patches` support in
`TOOL_VERSIONS` for registering patched toolchains please consider setting
the `patch_strip` explicitly to `1` if you depend on this value - in the
future the value may change to default to `0`.


### Removed
* (toolchains): Removed accidentally exposed `http_archive` symbol from
Expand Down
4 changes: 2 additions & 2 deletions examples/bzlmod/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions python/private/python_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _python_repository_impl(rctx):
if patches:
for patch in patches:
# Should take the strip as an attr, but this is fine for the moment
rctx.patch(patch, strip = 1)
rctx.patch(patch, strip = rctx.attr.patch_strip)

# Write distutils.cfg to the Python installation.
if "windows" in platform:
Expand Down Expand Up @@ -450,6 +450,7 @@ py_exec_tools_toolchain(
"ignore_root_user_error": rctx.attr.ignore_root_user_error,
"name": rctx.attr.name,
"netrc": rctx.attr.netrc,
"patch_strip": rctx.attr.patch_strip,
"patches": rctx.attr.patches,
"platform": platform,
"python_version": python_version,
Expand Down Expand Up @@ -515,6 +516,21 @@ For more information see the official bazel docs
"netrc": attr.string(
doc = ".netrc file to use for authentication; mirrors the eponymous attribute from http_archive",
),
"patch_strip": attr.int(
doc = """
Same as the --strip argument of Unix patch.

:::{note}
In the future the default value will be set to `0`, to mimic the wellk known
function defaults (e.g. `single_version_override` for `MODULE.bazel` files.
:::

:::{versionadded} 0.36.0
:::
""",
default = 1,
mandatory = False,
),
"patches": attr.label_list(
doc = "A list of patch files to apply to the unpacked interpreter",
mandatory = False,
Expand Down Expand Up @@ -627,7 +643,7 @@ def python_register_toolchains(
continue

loaded_platforms.append(platform)
(release_filename, urls, strip_prefix, patches) = get_release_info(platform, python_version, base_url, tool_versions)
(release_filename, urls, strip_prefix, patches, patch_strip) = get_release_info(platform, python_version, base_url, tool_versions)

# allow passing in a tool version
coverage_tool = None
Expand All @@ -653,6 +669,7 @@ def python_register_toolchains(
),
sha256 = sha256,
patches = patches,
patch_strip = patch_strip,
platform = platform,
python_version = python_version,
release_filename = release_filename,
Expand Down
12 changes: 9 additions & 3 deletions python/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DEFAULT_RELEASE_BASE_URL = "https://github.com/indygreg/python-build-standalone/
# "strip_prefix": "python",
# },
#
# It is possible to provide lists in "url".
# It is possible to provide lists in "url". It is also possible to provide patches or patch_strip.
#
# buildifier: disable=unsorted-dict-items
TOOL_VERSIONS = {
Expand Down Expand Up @@ -636,7 +636,7 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
tool_versions: A dict listing the interpreter versions, their SHAs and URL

Returns:
A tuple of (filename, url, and archive strip prefix)
A tuple of (filename, url, archive strip prefix, patches, patch_strip)
"""

url = tool_versions[python_version]["url"]
Expand Down Expand Up @@ -673,8 +673,14 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
patches = patches[platform]
else:
patches = []
patch_strip = tool_versions[python_version].get("patch_strip", None)
if type(patch_strip) == type({}):
if platform in patch_strip.keys():
patch_strip = patch_strip[platform]
else:
patch_strip = None

return (release_filename, rendered_urls, strip_prefix, patches)
return (release_filename, rendered_urls, strip_prefix, patches, patch_strip)

def print_toolchains_checksums(name):
native.genrule(
Expand Down