pybind11_bazel icon indicating copy to clipboard operation
pybind11_bazel copied to clipboard

Selecting the python version

Open dragoscarp opened this issue 1 year ago • 4 comments

When used in a multi python version bzlmod workspace add an attribute to select the python version for pybind_extension, pybind_library and pybind_library_test rules.

dragoscarp avatar Mar 19 '24 12:03 dragoscarp

My understanding is that the py_binary() and py_test() rules may specify Python versions and that whatever the current Python toolchain happens to be will propagate to other rules as needed. See this and this in the rules_python examples for a sense of what I mean. Please correct me if I'm wrong, @rickeylev, or if I'm overlooking some subtlety in this feature request!

junyer avatar Mar 19 '24 15:03 junyer

Correct. Library rules shouldn't be specifying a version because that's the responsibility of a higher level rule.

Do you want to force a particular version because you're building something for packaging (e.g. for pypi distribution)? If so, then the rule that performs the packaging (e.g. py_wheel, py_package, or what have you) should use a transition to set the python version.

rickeylev avatar Mar 20 '24 20:03 rickeylev

Thank you for the answers! Maybe I'm missing something, but as an example I think it should be possible to have py_binary targets depending on a pybind_extension target. How could I do this for target version_3_10 or version_3_9 in this example? https://github.com/bazelbuild/rules_python/blob/c5c03b2477dd1ce0c06c9dc60bf816995f222bcf/examples/multi_python_versions/tests/BUILD.bazel#L35

dragoscarp avatar Mar 25 '24 09:03 dragoscarp

As per the documentation, please add the pybind_extension target to the data attribute – not the deps attribute – of the py_* target.

junyer avatar Mar 27 '24 17:03 junyer

Thank you! It seems to work indeed when the data attribute is used!

dragoscarp avatar May 18 '24 08:05 dragoscarp