Skip to content

Commit 5f166c1

Browse files
authored
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'
1 parent 767e3ce commit 5f166c1

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

python/pip_install/pip_repository.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
""
22

3-
load("//python:repositories.bzl", "is_standalone_interpreter")
3+
load("//python:repositories.bzl", "get_interpreter_dirname", "is_standalone_interpreter")
44
load("//python/pip_install:repositories.bzl", "all_requirements")
55
load("//python/pip_install:requirements_parser.bzl", parse_requirements = "parse")
66
load("//python/pip_install/private:srcs.bzl", "PIP_INSTALL_PY_SRCS")
@@ -124,7 +124,7 @@ def _get_toolchain_unix_cflags(rctx):
124124
fail("could not get python version from interpreter (status {}): {}".format(er.return_code, er.stderr))
125125
_python_version = er.stdout
126126
include_path = "{}/include/python{}".format(
127-
rctx.path(Label("@{}//:WORKSPACE".format(rctx.attr.python_interpreter_target.workspace_name))).dirname.realpath,
127+
get_interpreter_dirname(rctx, rctx.attr.python_interpreter_target),
128128
_python_version,
129129
)
130130

python/repositories.bzl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ def py_repositories():
5858

5959
STANDALONE_INTERPRETER_FILENAME = "STANDALONE_INTERPRETER"
6060

61+
def get_interpreter_dirname(rctx, python_interpreter_target):
62+
"""Get a python interpreter target dirname.
63+
64+
Args:
65+
rctx (repository_ctx): The repository rule's context object.
66+
python_interpreter_target (Target): A target representing a python interpreter.
67+
68+
Returns:
69+
str: The Python interpreter directory.
70+
"""
71+
72+
return rctx.path(Label("{}//:WORKSPACE".format(str(python_interpreter_target).split("//")[0]))).dirname
73+
6174
def is_standalone_interpreter(rctx, python_interpreter_target):
6275
"""Query a python interpreter target for whether or not it's a rules_rust provided toolchain
6376
@@ -77,7 +90,7 @@ def is_standalone_interpreter(rctx, python_interpreter_target):
7790
return rctx.execute([
7891
"ls",
7992
"{}/{}".format(
80-
rctx.path(Label("@{}//:WORKSPACE".format(rctx.attr.python_interpreter_target.workspace_name))).dirname,
93+
get_interpreter_dirname(rctx, python_interpreter_target),
8194
STANDALONE_INTERPRETER_FILENAME,
8295
),
8396
]).return_code == 0

0 commit comments

Comments
 (0)