4

I am able to get a py_runtime to point to the correct python interpreter, but now I want to be able to use python 3 for my Bazel rules, and python 2 for existing Bazel rules that were written for python 2. Given py_runtime below, how do I add it to the py_library so that it runs on python 3 while everything else runs on python 2?

py_runtime(
    name = "python-3.6",
    files = [],
    interpreter = "python3interpreter",
)

py_runtime(
        name = "python-2.7",
        files = [],
        interpreter = "python2interpreter",
    )

py_library(
    name = "foo",
    srcs = ["foo.py"]
)
1

1 Answer 1

1

First of all use py_runtime_pair to define both PY2 and PY3 toolchains. Then note that only py_binary has python_version attached to it, not the libraries. That is because a library can be PY2 and PY3 compatible. Although for a py_library you must define deps correctly. You must use select on python_version to pick up correct deps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.