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

feat: allow overriding tool versions and base url for predefined Python interpreters #647

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

Merged
merged 2 commits into from
Mar 10, 2022
Merged
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
13 changes: 11 additions & 2 deletions 13 python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ For historic reasons, pip_repositories() is defined in //python:pip.bzl.
load("//python/private:toolchains_repo.bzl", "resolved_interpreter_os_alias", "toolchains_repo")
load(
":versions.bzl",
"DEFAULT_RELEASE_BASE_URL",
"MINOR_MAPPING",
"PLATFORMS",
"TOOL_VERSIONS",
Expand All @@ -40,7 +41,8 @@ def _python_repository_impl(rctx):

platform = rctx.attr.platform
python_version = rctx.attr.python_version
(release_filename, url) = get_release_url(platform, python_version)
base_url = rctx.attr.base_url
(release_filename, url) = get_release_url(platform, python_version, base_url)

if release_filename.endswith(".zst"):
rctx.download(
Expand Down Expand Up @@ -160,6 +162,10 @@ python_repository = repository_rule(
_python_repository_impl,
doc = "Fetches the external tools needed for the Python toolchain.",
attrs = {
"base_url": attr.string(
doc = "The base URL used for releases, will be joined to the templated 'url' field in the tool_versions dict",
default = DEFAULT_RELEASE_BASE_URL,
),
"distutils": attr.label(
allow_single_file = True,
doc = "A distutils.cfg file to be included in the Python installation. " +
Expand Down Expand Up @@ -203,6 +209,7 @@ def python_register_toolchains(
python_version,
distutils = None,
distutils_content = None,
tool_versions = TOOL_VERSIONS,
**kwargs):
"""Convenience macro for users which does typical setup.

Expand All @@ -218,13 +225,15 @@ def python_register_toolchains(
python_version: the Python version.
distutils: see the distutils attribute in the python_repository repository rule.
distutils_content: see the distutils_content attribute in the python_repository repository rule.
tool_versions: a dict containing a mapping of version with SHASUM and platform info. If not supplied, the defaults
in python/versions.bzl will be used
**kwargs: passed to each python_repositories call.
"""
if python_version in MINOR_MAPPING:
python_version = MINOR_MAPPING[python_version]

for platform in PLATFORMS.keys():
sha256 = TOOL_VERSIONS[python_version]["sha256"].get(platform, None)
sha256 = tool_versions[python_version]["sha256"].get(platform, None)
if not sha256:
continue

Expand Down
6 changes: 3 additions & 3 deletions 6 python/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ MACOS_NAME = "mac os"
LINUX_NAME = "linux"
WINDOWS_NAME = "windows"

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

def get_release_url(platform, python_version):
def get_release_url(platform, python_version, base_url = DEFAULT_RELEASE_BASE_URL):
release_filename = TOOL_VERSIONS[python_version]["url"].format(
platform = platform,
python_version = python_version,
build = "static-install_only" if (WINDOWS_NAME in platform) else "install_only",
)
url = "/".join([_RELEASE_BASE_URL, release_filename])
url = "/".join([base_url, release_filename])
return (release_filename, url)

# When updating the versions and releases, run the following command to get
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.