@@ -41,8 +41,8 @@ def _python_repository_impl(rctx):
4141
4242 platform = rctx .attr .platform
4343 python_version = rctx .attr .python_version
44- base_url = rctx .attr .base_url
45- ( release_filename , url ) = get_release_url ( platform , python_version , base_url )
44+ release_filename = rctx .attr .release_filename
45+ url = rctx . attr . url
4646
4747 if release_filename .endswith (".zst" ):
4848 rctx .download (
@@ -101,7 +101,7 @@ def _python_repository_impl(rctx):
101101 if exec_result .return_code :
102102 fail (exec_result .stderr )
103103
104- python_bin = "python.exe" if ("windows" in rctx . attr . platform ) else "bin/python3"
104+ python_bin = "python.exe" if ("windows" in platform ) else "bin/python3"
105105
106106 build_content = """\
107107 # Generated by python/repositories.bzl
@@ -155,17 +155,15 @@ py_runtime_pair(
155155 "name" : rctx .attr .name ,
156156 "platform" : platform ,
157157 "python_version" : python_version ,
158+ "release_filename" : release_filename ,
158159 "sha256" : rctx .attr .sha256 ,
160+ "url" : url ,
159161 }
160162
161163python_repository = repository_rule (
162164 _python_repository_impl ,
163165 doc = "Fetches the external tools needed for the Python toolchain." ,
164166 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- ),
169167 "distutils" : attr .label (
170168 allow_single_file = True ,
171169 doc = "A distutils.cfg file to be included in the Python installation. " +
@@ -187,10 +185,18 @@ python_repository = repository_rule(
187185 mandatory = True ,
188186 values = TOOL_VERSIONS .keys () + MINOR_MAPPING .keys (),
189187 ),
188+ "release_filename" : attr .string (
189+ doc = "The filename of the interpreter to be downloaded" ,
190+ mandatory = True ,
191+ ),
190192 "sha256" : attr .string (
191193 doc = "The SHA256 integrity hash for the Python interpreter tarball." ,
192194 mandatory = True ,
193195 ),
196+ "url" : attr .string (
197+ doc = "The URL of the interpreter to download" ,
198+ mandatory = True ,
199+ ),
194200 "zstd_sha256" : attr .string (
195201 default = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0" ,
196202 ),
@@ -229,6 +235,8 @@ def python_register_toolchains(
229235 in python/versions.bzl will be used
230236 **kwargs: passed to each python_repositories call.
231237 """
238+ base_url = kwargs .pop ("base_url" , DEFAULT_RELEASE_BASE_URL )
239+
232240 if python_version in MINOR_MAPPING :
233241 python_version = MINOR_MAPPING [python_version ]
234242
@@ -237,6 +245,8 @@ def python_register_toolchains(
237245 if not sha256 :
238246 continue
239247
248+ (release_filename , url ) = get_release_url (platform , python_version , base_url , tool_versions )
249+
240250 python_repository (
241251 name = "{name}_{platform}" .format (
242252 name = name ,
@@ -245,6 +255,8 @@ def python_register_toolchains(
245255 sha256 = sha256 ,
246256 platform = platform ,
247257 python_version = python_version ,
258+ release_filename = release_filename ,
259+ url = url ,
248260 distutils = distutils ,
249261 distutils_content = distutils_content ,
250262 ** kwargs
0 commit comments