pybind / pybind11_bazel

Bazel wrapper around the pybind11 repository
Other
100 stars 54 forks source link

Selecting the python version #79

Closed dragoscarp closed 4 months ago

dragoscarp commented 6 months ago

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.

junyer commented 6 months ago

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!

rickeylev commented 6 months ago

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.

dragoscarp commented 6 months ago

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

junyer commented 6 months ago

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

dragoscarp commented 4 months ago

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