-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bzlmod pip extension generates a different repo if the python.toolchain
version is specified in X.Y.Z
format
#1339
Comments
Before this PR the `bzlmod` example would only work if the Python interpreter version is specified in the `X.Y` format. However, users may desire to use the full version (`X.Y.Z`) for reproducibility reasons and expect everything to continue to work. This fixes the versions used everywhere by leveraging functionality introduced in bazelbuild#1328 and fixes the `python_versions` to always contain `@python_versions//X.Y:defs.bzl` imports. NOTE, bazelbuild#1328 also fixed the case where the Python-version specific `pip` hub repos would be named `<hub_name>_XYZ` as opposed to the `<hub_name>_XY`, which is expected across the codebase. Breaking for `bzlmod` users who previously used `@python_versions//X.Y.Z:defs.bzl` in their BUILD.bazel files and/or depended on the `@pip_XYZ//:requirements.bzl`. This essentially limits the users of the `@python_versions` to a single `X.Y` toolchain version, whilst the full functionality should still be available by using the `python_version` parameter in the `py_binary` and `py_library` rules. Fixes bazelbuild#1339.
I am thinking about this a little more and I am wondering if it is actually a little more difficult than I expected, so here is my brain dump. Right now in So technically one could argue that it could always be possible to make a I am only familiar with basic
That means that we should do the following with our toolchains:
All of this view could be consistent with sysconfig, which returns @rickeylev, @chrislovecnm, what do you think about all of it? |
Before this PR the `bzlmod` example would only work if the Python interpreter version is specified in the `X.Y` format. However, users may desire to use the full version (`X.Y.Z`) for reproducibility reasons and expect everything to continue to work. This fixes the versions used everywhere by leveraging functionality introduced in bazelbuild#1328 and fixes the `python_versions` to always contain `@python_versions//X.Y:defs.bzl` imports. NOTE, bazelbuild#1328 also fixed the case where the Python-version specific `pip` hub repos would be named `<hub_name>_XYZ` as opposed to the `<hub_name>_XY`, which is expected across the codebase. Breaking for `bzlmod` users who previously used `@python_versions//X.Y.Z:defs.bzl` in their BUILD.bazel files and/or depended on the `@pip_XYZ//:requirements.bzl`. This essentially limits the users of the `@python_versions` to a single `X.Y` toolchain version, whilst the full functionality should still be available by using the `python_version` parameter in the `py_binary` and `py_library` rules. Fixes bazelbuild#1339.
Before this PR the `bzlmod` and legacy setups would only expose the multi-version python toolchain aliases as the string that is passed to the `python_register_multi_toolchains` function. This meant that if the user decided to pass the full version (e.g. `3.11.1`) then they had to import the version aware `py_*` defs via `@foo//3.11.1:defs.bzl`. This PR changes it such that the user can still do the old way of importing but we print a deprecation warning and ask the user to use `3.11:defs.bzl` instead which better reflects how the multi-version toolchain should be used. This also means that the PRs bumping the minor versions like in bazelbuild#1352 won't need updating Python code elsewhere. Whilst at it, we introduce a validation that disallows multiple Python toolchains of the same `X.Y` version. This is handled in the `bzlmod` by printing warnings that the toolchains are ignored, whilst the non-bzlmod users will get validation errors, which is a potentially breaking change. Fixes bazelbuild#1339
Before this PR the `bzlmod` and legacy setups would only expose the multi-version python toolchain aliases as the string that is passed to the `python_register_multi_toolchains` function. This meant that if the user decided to pass the full version (e.g. `3.11.1`) then they had to import the version aware `py_*` defs via `@foo//3.11.1:defs.bzl`. This PR changes it such that the user can still do the old way of importing but we print a deprecation warning and ask the user to use `3.11:defs.bzl` instead which better reflects how the multi-version toolchain should be used. This also means that the PRs bumping the minor versions like in bazelbuild#1352 won't need updating Python code elsewhere. Whilst at it, we introduce a validation that disallows multiple Python toolchains of the same `X.Y` version. This is handled in the `bzlmod` by printing warnings that the toolchains are ignored, whilst the non-bzlmod users will get validation errors, which is a potentially breaking change. Fixes bazelbuild#1339
Before this PR the `bzlmod` and legacy setups would only expose the multi-version python toolchain aliases as the string that is passed to the `python_register_multi_toolchains` function. This meant that if the user decided to pass the full version (e.g. `3.11.1`) then they had to import the version aware `py_*` defs via `@foo//3.11.1:defs.bzl`. This PR changes it such that the user can still do the old way of importing but we print a deprecation warning and ask the user to use `3.11:defs.bzl` instead which better reflects how the multi-version toolchain should be used. This also means that the PRs bumping the minor versions like in bazelbuild#1352 won't need updating Python code elsewhere. Whilst at it, we introduce a validation that disallows multiple Python toolchains of the same `X.Y` version. This is handled in the `bzlmod` by printing warnings that the toolchains are ignored, whilst the non-bzlmod users will get validation errors, which is a potentially breaking change. Fixes bazelbuild#1339
So whilst working on #1340 I realized that the desired behaviour might be the following: Allow the user not using a bzlmod to use one X.Y toolchain (e.g. no 3.9.1 and 3.9.3) per single multi-version toolchain registration. Reason for this is that in pip installations we would should treat them as identical versions because they have the same Python ABI. Requirements are also usually locked per X.Y python version and this assumption that there is only one X.Y version of python in the multi-version setup allows us to ensure that bumping a patch version of the toolchain in the user's repo does not require any other source code changes no matter how they request the toolchain version. However being able to define the toolchain with the patch version can be desirable because the toolchain sometimes differs in the way it is packaged and that may have regressions and not having this convenience would mean that users will not be able to use toolchains not defined in MINOR_MAPPING without patching rules_python. Without this assumption we cannot guarantee that a In the bzlmod land there is an additional constraint where the root module decides what version of the toolchain we use and any submodules declaring a particular version of the toolchain will be ignored. Even without explicitly declaring a toolchain, the root module will default particular versions of the toolchain based on the MINOR_MAPPING, so if the submodule asks for 3.11.1, but MINOR_MAPPING defines 3.11.4, then 3.11.4 will bue used for the root and other modules. This has to be the case because we can only have a single python toolchain hub. If we don't merge the change proposed in the #1340, we will have the current behaviour where the hub repo structure depends on exactly what is passed to the repository rule. Whilst it is consistent behaviour to some degree, it makes things a little bit hard to maintain and there is a chance to be able to register two toolchains of the same version (3.11 which expands to 3.11.4 and 3.11.4) if I remember the code logic correctly. TLDR:
cc: @rickeylev, let me know if there is a whole in my logic somewhere. |
#1696 fixed this. |
I would expect the following change to be benign:
However, it seems that it is not the case. The issue is present on both,
main
and0.24.0
releases. We may be able to use #1328 in order to fix this.The text was updated successfully, but these errors were encountered: