-
Notifications
You must be signed in to change notification settings - Fork 542
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
feat: support parsing whl METADATA on any python version #1693
feat: support parsing whl METADATA on any python version #1693
Conversation
With this PR we prepare the dependency resolution machinery to support other than host python versions. This may make it possible to generate select statements based on the version but we target this usecase as it requires little code to be changed and once wired to the starlark code could be of use. Creating this PR for discussion so that we can decide on a suitable interface.
c8656bb
to
8f6b8a3
Compare
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.
Mostly just small things. Otherwise LGTM.
python/pip_install/private/generate_whl_library_build_bazel.bzl
Outdated
Show resolved
Hide resolved
python/pip_install/private/generate_whl_library_build_bazel.bzl
Outdated
Show resolved
Hide resolved
8f96824
to
65c5542
Compare
examples/bzlmod/.bazelrc
Outdated
@@ -8,3 +8,6 @@ test --test_output=errors --enable_runfiles | |||
build --enable_runfiles | |||
|
|||
startup --windows_enable_symlinks | |||
|
|||
# Set the default version of python_version config | |||
common --@rules_python//python/config_settings:python_version=3.9.18 |
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.
I got this this example to work by setting the default toolchain/python version using this and then version specific selects start working in practice with regular py_binary
and py_test
rules.
@rickeylev , what do you think about how we should set the default python_version
value? I think there are several improvements (outside this PR) that we could make:
- Allow users to set
3.9
as the value topython_version
. This would requires us to change thetoolchain
definition so that it usesselect.match_any(3.9, 3.9.18)
in thetarget_settings
and update theis_python
generation code. - Move the definition of the
python_version
to thepythons_hub
under bzlmod with setting the default value the same as the default toolchain. We can make an alias if we are usingbzlmod
to thepythons_hub
string value. That way I can keep thedefault
settings in theMODULE.bazel
and would not need this line here.
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.
Allow users to set 3.9 as the value to python_version. This would requires us to change the toolchain definition so that it uses select.match_any(3.9, 3.9.18) in the target_settings and update the is_python generation code.
Yeah, I think that's fine. I was going to suggest a slightly different structure: two separate toolchain registrations, with 3.9 after any 3.9.X toolchains. This would allow multiple micro-versions. But, the rest of the everything doesn't really support a micro-version, so perhaps that is premature.
I'm mixed on allowing "3.9" as a flag value. It does seem very natural, so I do like that part. But with how flags work, "3.9" has no relation to "3.9.18", so I worry that's going to rear its head somehow. I guess our public interface here are the "is_XX" settings, though, so we have some freedom about the flag input format (e.g. "latest" as a possible value sounds convenient).
Anyways, yeah, i guess allowing 3.9 as valid value is fine.
I've heard rumor that config_common.FeatureFlagInfo can be used to allow a flag be implemented as a rule, and have the resulting value seen by config_setting. I haven't tried it myself, though, and was told this was "deprecated", so I'm not sure about that. In any case, my point in mentioning this is that would allow taking 3.9 as the input value and then transform it to 3.8.18 (by looking at MINOR_MAPPING), and everything should just work as before.
Move the definition of the python_version to the pythons_hub under bzlmod with setting the default value the same as the default toolchain.
What about just loading the default and setting it instead? e.g.
# python/config_settings/BUILD
load("@pythons_hub//:interpreters.bzl", "DEFAULT_PYTHON_VERSION")
define_python_version_flag(default=DEFAULT_PYTHON_VERSION)
Regardless, something that isn't clear to me is how to do the same for workspace builds. Is that even possible? I think python_register_multi_toolchains
would need to generate something with the default value in it. Except that function isn't always called, so we can't guarantee it is called. Yeah, I dunno.
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.
FWIW I'm currently using python_version
directly since I can mix it with constraints in a single config_setting
, like
config_setting(
name = "python_3.10.12_aarch64-apple-darwin_config",
flag_values = {"@rules_python//python/config_settings:python_version": "3.10.12"},
constraint_values = ["@platforms//os:macos", "@platforms//cpu:aarch64"],
)
Otherwise, to use the is_XX
settings, I guess I'd have to use skylib's selects.config_setting_group
?
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.
Yeah, that is what I noticed and using config_setting_group
is a little unwieldy. I have created #1720 as a POC to potentially allow having "@rules_python//python/config_settings:python_version": "3.10"
instead, but I am missing a few things there to get it fully working.
# * @platforms//cpu:{value} | ||
# * @//python/config_settings:is_python_3.{minor_version} | ||
# * {os}_{cpu} | ||
# * cp3{minor_version}_{os}_{cpu} |
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.
FYI, I had to move the rendering of the config settings outside the main loop because it was getting complex. However, this PR can generate the right select for pylint
:
deps = [
"@pip_39_astroid//:pkg",
"@pip_39_dill//:pkg",
"@pip_39_isort//:pkg",
"@pip_39_mccabe//:pkg",
"@pip_39_platformdirs//:pkg",
"@pip_39_tomlkit//:pkg",
] + select(
{
"@@rules_python~override//python/config_settings:is_python_3.10": ["@pip_39_tomli//:pkg"],
"@@rules_python~override//python/config_settings:is_python_3.9": [
"@pip_39_tomli//:pkg",
"@pip_39_typing_extensions//:pkg",
],
":is_cp310_windows_anyarch": [
"@pip_39_colorama//:pkg",
"@pip_39_dill//:pkg",
"@pip_39_tomli//:pkg",
],
":is_cp311_windows_anyarch": [
"@pip_39_colorama//:pkg",
"@pip_39_dill//:pkg",
],
":is_cp39_windows_anyarch": [
"@pip_39_colorama//:pkg",
"@pip_39_dill//:pkg",
"@pip_39_tomli//:pkg",
"@pip_39_typing_extensions//:pkg",
],
"//conditions:default": [],
},
),
Disregard the fact that the conditions and the target repos should match - this can be done as a followup item. I am not sure yet what design would be best. This versioned select is only enabled if the user specifies multiple target python versions.
Sorry, removed from queue -- just want to double check something about the unit tests. |
The bazelbuild#1693 PR incorrectly assumed that the platform tag will be os-arch specific if and only if the abi tag is of form cpxy. However, there are many wheels that are not like this (e.g. watchdog, tornado, libclang). This fixes the starlark code that is overriding the user platforms with something that only the wheel supports by also taking into account the ABI. Fixes bazelbuild#1810.
The bazelbuild#1693 PR incorrectly assumed that the platform tag will be os-arch specific if and only if the abi tag is of form cpxy. However, there are many wheels that are not like this (e.g. watchdog, tornado, libclang). This fixes the starlark code that is overriding the user platforms with something that only the wheel supports by also taking into account the ABI. Fixes bazelbuild#1810.
The #1693 PR incorrectly assumed that the platform tag will be os-arch specific if and only if the abi tag is of form cpxy. However, there are many wheels that are not like this (e.g. watchdog, tornado, libclang). This fixes the starlark code that is overriding the user platforms with something that only the wheel supports by also taking into account the ABI. Fixes #1810.
With this PR we can deterministically parse the METADATA and generate a
BUILD.bazel
file using the config settings introduced in #1555. Let'simagine we had a
requirements.txt
file that used only wheels, we coulduse the host interpreter to parse the wheel metadata for all the target
platforms and use the version aware toolchain at runtime. This potentially
unlocks more clever layouts of the
bzlmod
hub repos explored in #1625where we could have a single
whl_library
instance for all versions withina single hub repo.
Work towards #1643.