rules_python
rules_python copied to clipboard
Build with multiple minor Python versions
Hi folks, thank you so much for the amazing work :)
I have currently set up a toolchain to run my build with a specific Python version (3.9.10) in a hermetic way.
I would like to be able to run my test build with multiple minor versions (e.g. 3.10, 3.9, 3.8). I know how to setup multiple runtimes and toolchains, but I'm not sure how to use them to achieve the objective.
I could use a feature flag (e.g. --python_minor_version 3.9.10
) or have all targets built with all runtimes, both options work for my purpose.
I tried creating a config_setting
for the feature flag, and then use a select
for python_interpreter_target
in the call to pip_parse
in WORKSPACE
but selects are not allowed in repo rules.
What is the most canonical way of achieving my goal?
Thank you for the advice.
FYI, if you haven't read this already - https://blog.aspect.dev/many-python-versions-one-bazel-build
It would be good to directly be able to specify a python runtime in py_binary
, py_test
etc, rather than using Bazel's toolchain resolution for this.
Related: https://github.com/bazelbuild/rules_python/issues/506
I have searched for a few hours for a similar solution. This may be a lack of expertise in Bazel, but we currently have a need to split the Python version by platform due to needing different major version (3.9 and 3.10). I know this could be done via a .bazelrc
file and --config
if able to select a registered toolchain from the command line. We will need to in the near future be able to specify possibly many more versions based on client needs.
Here is sample from WORKSPACE
:
# Python Dependencies
http_archive(
name = "rules_python",
sha256 = "8c8fe44ef0a9afc256d1e75ad5f448bb59b81aba149b8958f02f7b3a98f5d9b4",
strip_prefix = "rules_python-0.13.0",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.13.0.tar.gz",
)
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
python_register_toolchains(
name = "python3",
python_version = "3.10",
ignore_root_user_error = True,
)
load("@python3//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")
pip_parse(
name = "python_pending_dependencies",
python_interpreter_target = interpreter,
requirements_lock = "//third_party_libraries:requirements_pending.txt",
)
load("@python_pending_dependencies//:requirements.bzl", install_python_pending_dependencies = "install_deps")
install_python_pending_dependencies()
pip_parse(
name = "python_approved_dependencies",
python_interpreter_target = interpreter,
requirements_lock = "//third_party_libraries:requirements_approved.txt",
)
load("@python_approved_dependencies//:requirements.bzl", install_python_approved_dependencies = "install_deps")
install_python_approved_dependencies()
Then I have a duplicate of this that specifies version 3.9 vs 3.10. Is there a way to specify the registered toolchain to use from the command line with the bazel run|test|build
commands?
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!
This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"