Fix Python interpreter target labels with @@ prefixes. (#940)
ERROR: An error occurred during the fetch of repository 'rules_python~0.16.1~pip~pip':
Traceback (most recent call last):
File "/home/miha/.cache/bazel/_bazel_miha/bd93af10788cff1331d75ed739998a3c/external/rules_python~0.16.1/python/pip_install/pip_repository.bzl", line 335, column 63, in _pip_repository_impl
environment = _create_repository_execution_environment(rctx),
File "/home/miha/.cache/bazel/_bazel_miha/bd93af10788cff1331d75ed739998a3c/external/rules_python~0.16.1/python/pip_install/pip_repository.bzl", line 210, column 47, in _create_repository_execution_environment
cppflags.extend(_get_toolchain_unix_cflags(rctx))
File "/home/miha/.cache/bazel/_bazel_miha/bd93af10788cff1331d75ed739998a3c/external/rules_python~0.16.1/python/pip_install/pip_repository.bzl", line 115, column 37, in _get_toolchain_unix_cflags
if not is_standalone_interpreter(rctx, rctx.attr.python_interpreter_target):
File "/home/miha/.cache/bazel/_bazel_miha/bd93af10788cff1331d75ed739998a3c/external/rules_python~0.16.1/python/repositories.bzl", line 64, column 22, in is_standalone_interpreter
rctx.path(Label("@{}//:WORKSPACE".format(rctx.attr.python_interpreter_target.workspace_name))).dirname,
Error in path: Unable to load package for @[unknown repo 'rules_python~0.16.1~python~python3_10_x86_64-unknown-linux-gnu' requested from @rules_python~0.16.1]//:WORKSPACE: The repository '@[unknown repo 'rules_python~0.16.1~python~python3_10_x86_64-unknown-linux-gnu' requested from @rules_python~0.16.1]' could not be resolved: No repository visible as '@rules_python~0.16.1~python~python3_10_x86_64-unknown-linux-gnu' from repository '@rules_python~0.16.1'
diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl
index 782a947..0685a88 100644
--- a/python/pip_install/pip_repository.bzl
+++ b/python/pip_install/pip_repository.bzl
@@ -1,6 +1,6 @@
""
-load("//python:repositories.bzl", "is_standalone_interpreter")
+load("//python:repositories.bzl", "get_interpreter_dirname", "is_standalone_interpreter")
load("//python/pip_install:repositories.bzl", "all_requirements")
load("//python/pip_install:requirements_parser.bzl", parse_requirements = "parse")
load("//python/pip_install/private:srcs.bzl", "PIP_INSTALL_PY_SRCS")
@@ -124,7 +124,7 @@
fail("could not get python version from interpreter (status {}): {}".format(er.return_code, er.stderr))
_python_version = er.stdout
include_path = "{}/include/python{}".format(
- rctx.path(Label("@{}//:WORKSPACE".format(rctx.attr.python_interpreter_target.workspace_name))).dirname.realpath,
+ get_interpreter_dirname(rctx, rctx.attr.python_interpreter_target),
_python_version,
)
diff --git a/python/repositories.bzl b/python/repositories.bzl
index de8d90a..e151d88 100644
--- a/python/repositories.bzl
+++ b/python/repositories.bzl
@@ -58,6 +58,19 @@
STANDALONE_INTERPRETER_FILENAME = "STANDALONE_INTERPRETER"
+def get_interpreter_dirname(rctx, python_interpreter_target):
+ """Get a python interpreter target dirname.
+
+ Args:
+ rctx (repository_ctx): The repository rule's context object.
+ python_interpreter_target (Target): A target representing a python interpreter.
+
+ Returns:
+ str: The Python interpreter directory.
+ """
+
+ return rctx.path(Label("{}//:WORKSPACE".format(str(python_interpreter_target).split("//")[0]))).dirname
+
def is_standalone_interpreter(rctx, python_interpreter_target):
"""Query a python interpreter target for whether or not it's a rules_rust provided toolchain
@@ -77,7 +90,7 @@
return rctx.execute([
"ls",
"{}/{}".format(
- rctx.path(Label("@{}//:WORKSPACE".format(rctx.attr.python_interpreter_target.workspace_name))).dirname,
+ get_interpreter_dirname(rctx, python_interpreter_target),
STANDALONE_INTERPRETER_FILENAME,
),
]).return_code == 0