Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7bf15dc

Browse filesBrowse files
authored
feat: allow overriding tool versions and base url for predefined Python interpreters (bazel-contrib#647)
1 parent afb319b commit 7bf15dc
Copy full SHA for 7bf15dc

File tree

2 files changed

+14
-5
lines changed
Filter options

2 files changed

+14
-5
lines changed

‎python/repositories.bzl

Copy file name to clipboardExpand all lines: python/repositories.bzl
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ For historic reasons, pip_repositories() is defined in //python:pip.bzl.
2020
load("//python/private:toolchains_repo.bzl", "resolved_interpreter_os_alias", "toolchains_repo")
2121
load(
2222
":versions.bzl",
23+
"DEFAULT_RELEASE_BASE_URL",
2324
"MINOR_MAPPING",
2425
"PLATFORMS",
2526
"TOOL_VERSIONS",
@@ -40,7 +41,8 @@ def _python_repository_impl(rctx):
4041

4142
platform = rctx.attr.platform
4243
python_version = rctx.attr.python_version
43-
(release_filename, url) = get_release_url(platform, python_version)
44+
base_url = rctx.attr.base_url
45+
(release_filename, url) = get_release_url(platform, python_version, base_url)
4446

4547
if release_filename.endswith(".zst"):
4648
rctx.download(
@@ -160,6 +162,10 @@ python_repository = repository_rule(
160162
_python_repository_impl,
161163
doc = "Fetches the external tools needed for the Python toolchain.",
162164
attrs = {
165+
"base_url": attr.string(
166+
doc = "The base URL used for releases, will be joined to the templated 'url' field in the tool_versions dict",
167+
default = DEFAULT_RELEASE_BASE_URL,
168+
),
163169
"distutils": attr.label(
164170
allow_single_file = True,
165171
doc = "A distutils.cfg file to be included in the Python installation. " +
@@ -203,6 +209,7 @@ def python_register_toolchains(
203209
python_version,
204210
distutils = None,
205211
distutils_content = None,
212+
tool_versions = TOOL_VERSIONS,
206213
**kwargs):
207214
"""Convenience macro for users which does typical setup.
208215
@@ -218,13 +225,15 @@ def python_register_toolchains(
218225
python_version: the Python version.
219226
distutils: see the distutils attribute in the python_repository repository rule.
220227
distutils_content: see the distutils_content attribute in the python_repository repository rule.
228+
tool_versions: a dict containing a mapping of version with SHASUM and platform info. If not supplied, the defaults
229+
in python/versions.bzl will be used
221230
**kwargs: passed to each python_repositories call.
222231
"""
223232
if python_version in MINOR_MAPPING:
224233
python_version = MINOR_MAPPING[python_version]
225234

226235
for platform in PLATFORMS.keys():
227-
sha256 = TOOL_VERSIONS[python_version]["sha256"].get(platform, None)
236+
sha256 = tool_versions[python_version]["sha256"].get(platform, None)
228237
if not sha256:
229238
continue
230239

‎python/versions.bzl

Copy file name to clipboardExpand all lines: python/versions.bzl
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ MACOS_NAME = "mac os"
2020
LINUX_NAME = "linux"
2121
WINDOWS_NAME = "windows"
2222

23-
_RELEASE_BASE_URL = "https://github.com/indygreg/python-build-standalone/releases/download"
23+
DEFAULT_RELEASE_BASE_URL = "https://github.com/indygreg/python-build-standalone/releases/download"
2424

25-
def get_release_url(platform, python_version):
25+
def get_release_url(platform, python_version, base_url = DEFAULT_RELEASE_BASE_URL):
2626
release_filename = TOOL_VERSIONS[python_version]["url"].format(
2727
platform = platform,
2828
python_version = python_version,
2929
build = "static-install_only" if (WINDOWS_NAME in platform) else "install_only",
3030
)
31-
url = "/".join([_RELEASE_BASE_URL, release_filename])
31+
url = "/".join([base_url, release_filename])
3232
return (release_filename, url)
3333

3434
# When updating the versions and releases, run the following command to get

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.