-
Notifications
You must be signed in to change notification settings - Fork 560
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
fix(bzlmod): set the default_version to the python_version flag #2253
fix(bzlmod): set the default_version to the python_version flag #2253
Conversation
Summary: * Add pythons_hub to the WORKSPACE with dummy data to make pythons_hub work. * Add MINOR_MAPPING and PYTHON_VERSIONS to pythons_hub to generate the config settings. * Remove the default_version usage from pythons_hub, this will be important when consolidating the code later. We can also potentially relax the need for requiring users to set python_version attribute because python_versions can now be just read from the interpreters.bzl file and we can just setup the python deps for all available interpreters instead. This also makes sharing the same whl repo for multiple python versions work as the deps in the whl_library will always resolve correctly * Update the test code to continue to work
This will just use config_setting targets instead of creating aliases back to rules python which makes the code more self contained.
internal_setup.bzl
Outdated
if not BZLMOD_ENABLED: | ||
hub_repo( | ||
name = "pythons_hub", | ||
minor_mapping = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we wanted, we could do extra plumbing within the pythons_hub
and pass the correct values for minor_mapping
and python_versions
from the //python:versions.bzl
, but given that WORKSPACE is on the way out and this is temporary, I thought it would be best to leave it like this.
@@ -528,7 +529,7 @@ def config_settings_test_suite(name): # buildifier: disable=function-docstring | |||
|
|||
config_settings( | |||
name = "dummy", | |||
python_versions = ["3.8", "3.9", "3.10"], | |||
python_versions = ["3.7", "3.8", "3.9", "3.10"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python_versions = ["3.7", "3.8", "3.9", "3.10"], | |
# NOTE: We don't have any `3.7` in `//python:versions.bzl` and | |
# this value has been selected on purpose to test what happens if the value | |
# is unknown to rules_python - i.e. we should still be able to work. | |
python_versions = ["3.7", "3.8", "3.9", "3.10"], |
However this is not a test for the code in question as those tests probably need to wait for bazelbuild#2253 to land to make the test writing easier.
Oh? How? Aren't we still stuck with the case where the same python version interpreter has to go find and download something? sdists? I think I see what you mean for a pure-wheel build. Well, maybe. When requirements.in is resolved by e.g. compile_pip_requirements to a particular python-specific requirements.txt, the python version has, effectively, been decided. But -- I don't recall requirements.txt storing the python version? So how do we know that |
name = is_python, | ||
actual = Label("//python/config_settings:" + is_python), | ||
flag_values = { | ||
Label("//python/config_settings:_python_version_major_minor"): python_version, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, maybe we should expose python_version_major_minor as a public setting. Otherwise, users don't have a good way to perform e.g. select({"3.10": ..., "3.11": ...})
, which is the most common type of selection on python version.
Don't have to address in this PR though.
…o feat/default-version-python-hub Resolve changelog conflict
CI's error is about running it under Bazel 6 -- I think it's trying to say pythons_hub isn't defined. Though, the (Mac, pystar, workspace) job is also failing and that is using Bazel 7. Looks like something to do with workspace builds. |
Ok, think I found the problem (wrong load in a test file). Pushed a fix. CI is acting weird right now, though. Maybe it'll be in a better mood when you log on; I suggest pushing a no-op change and having it start over. |
The idea is that we can just always define This is only true for |
…major_minor With this change the users can simply reuse our internal flag that will correctly report the `X.Y` version in `select` statements. If users previously depended on now removed `is_python_config_setting` now they have an alternative. Followup to bazelbuild#2253
…ble versions I think that bazelbuild#2253 has introduced an issue that went unnoticed because we did not have an integration test checking this. The main issue is that config settings of `is_python_3.x.y` were being generated only for registered toolchains and that is not necessarily the desired behaviour -- we may want to use the config settings for more values, so coupling that was a mistake.
…#2350) #2253 broke how the config settings are generated and only generated the config setting values for the python version values that we would have the registered toolchains for. This PR restores the previous behaviour. However, if the root module uses `python.override` to remove the allowed toolchains, then `config_settings` will be also affected.
…#2350) PR #2253 broke how the config settings are generated and only generated the config setting values for the python version values that we would have the registered toolchains for. This PR restores the previous behaviour. However, if the root module uses `python.override` to remove the allowed toolchains, then `config_settings` will be also affected. (cherry picked from commit 9340a81) Conflicts: - CHANGELOG.md
…#2350) PR #2253 broke how the config settings are generated and only generated the config setting values for the python version values that we would have the registered toolchains for. This PR restores the previous behaviour. However, if the root module uses `python.override` to remove the allowed toolchains, then `config_settings` will be also affected. (cherry picked from commit 9340a81) Conflicts: - CHANGELOG.md
With this change we set the default value of
--python_version
whenthe
python.toolchain
is used inbzlmod
and we generate theappropriate config settings based on the registered toolchains and
given overrides by the root module.
This means that we expect the
--python_version
to be always set toa non-empty value under
bzlmod
and we can cleanup code which washandling
//conditions:default
case. This also means that we canin theory drop the requirement for
python_version
inpip.parse
and just setup dependencies for all packages that we find in the
requirements.txt
file and move on. This is left as future workby myself or anyone willing to contribute. We can also start reusing
the same
whl_library
instance for multi-platform packages becausethe python version flag is always set - this will simplify the layout
and makes the feature non-experimental anymore under bzlmod.
Summary:
@pythons_hub
to theWORKSPACE
with dummy data to makepythons_hub work.
MINOR_MAPPING
andPYTHON_VERSIONS
to pythons_hub togenerate the config settings.
pypi
code under bzlmod.Work towards #2081, #260, #1708