diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl index afd9c1875c..9ba3f71a10 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 @@ def _get_toolchain_unix_cflags(rctx): 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 e0c9b0626d..714ffedd6c 100644 --- a/python/repositories.bzl +++ b/python/repositories.bzl @@ -42,6 +42,19 @@ def py_repositories(): 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 @@ -61,7 +74,7 @@ def is_standalone_interpreter(rctx, python_interpreter_target): 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