Description
Affected Rule
python_register_toolchains
which calls python_repository
.
Is this a regression?
Not per se. I recently migrated from a rudimentary toolchain [inspired by this blog post] to rules_python's native support in 0.21.0.
Description
python_register_toolchains
expects a tool_versions
dictionary, which by default points to the publicly accessible GitHub. However, to properly vendor a standalone Python interpreter (and avoid flooding GitHub), it is good practice to point this to another server. Many such deployments of such servers (e.g., Artifactory) require API tokens, which are often stored in netrc files.
This does not currently work because _python_repository_impl(rctx)
calls rctx.download
without setting auth
, unlike http_archive
which implicitly reads ~/.netrc
. This is a known issue with repository_ctx.download
that has a workaround.
🔬 Minimal Reproduction
In WORKSPACE
, call python_register_toolchains()
with tool_versions=<any url that requires an API token>
. Even with ~/.netrc
set up correctly (confirmed via wget
), Bazel will return HTTP GET with error code 401.
🔥 Exception or Error
WARNING: Download from https:///third_party/indygreg/python-build-standalone/cpython-3.9.11+20220318-x86_64-unknown-linux-gnu-pgo+lto-full.tar.zst failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 401
ERROR: An error occurred during the fetch of repository 'python39_x86_64-unknown-linux-gnu':
Traceback (most recent call last):
File "/home/circleci/.cache/bazel/_bazel_circleci/f16e36219ef33c22efc2ad20f3e3775c/external/rules_python/python/repositories.bzl", line 112, column 22, in _python_repository_impl
rctx.download(
Error in download: java.io.IOException: Error downloading [https:///third_party/indygreg/python-build-standalone/cpython-3.9.11+20220318-x86_64-unknown-linux-gnu-pgo+lto-full.tar.zst] to /home/circleci/.cache/bazel/_bazel_circleci/f16e36219ef33c22efc2ad20f3e3775c/external/python39_x86_64-unknown-linux-gnu/cpython-3.9.11+20220318-x86_64-unknown-linux-gnu-pgo+lto-full.tar.zst: GET returned 401
ERROR: /home/circleci/project/WORKSPACE:53:27: fetching python_repository rule //external:python39_x86_64-unknown-linux-gnu: Traceback (most recent call last):
File "/home/circleci/.cache/bazel/_bazel_circleci/f16e36219ef33c22efc2ad20f3e3775c/external/rules_python/python/repositories.bzl", line 112, column 22, in _python_repository_impl
rctx.download(
Error in download: java.io.IOException: Error downloading [https:///third_party/indygreg/python-build-standalone/cpython-3.9.11+20220318-x86_64-unknown-linux-gnu-pgo+lto-full.tar.zst] to /home/circleci/.cache/bazel/_bazel_circleci/f16e36219ef33c22efc2ad20f3e3775c/external/python39_x86_64-unknown-linux-gnu/cpython-3.9.11+20220318-x86_64-unknown-linux-gnu-pgo+lto-full.tar.zst: GET returned 401
INFO: Repository align_testdata instantiated at:
🌍 Your Environment
Operating System:
MacOS Ventura and Linux (Ubuntu 20.04)
Output of bazel version
:
Bazelisk version: development
Starting local Bazel server and connecting to it...
Build label: 6.1.2
Build target: bazel-out/darwin_arm64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Apr 18 15:31:54 2023 (1681831914)
Build timestamp: 1681831914
Build timestamp as int: 1681831914
Rules_python version:
0.21.0
Anything else relevant?