-
Notifications
You must be signed in to change notification settings - Fork 543
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(config_settings): allow matching minor version of python_version flag #1555
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7de7189
feat(config_settings): accept minor versions of Python in `python_ver…
dizzy57 459f010
Merge remote-tracking branch 'upstream/main' into minor_version_in_flag
rickeylev 768417c
generate fewer settings to match across versions
rickeylev 28d950f
rename test file to be consistent, expand test cases
rickeylev f76a5d5
fix bug with repeated allowed values, add note about default value
rickeylev 497123e
update changelog to better reflect feature added
rickeylev b943bc8
fix lint errors
rickeylev 8bcdd00
dont accept minor version as flag value, add missing import in tests
rickeylev 997d37c
alias config group for better ux; fix typo
rickeylev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2022 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load(":construct_config_settings_tests.bzl", "construct_config_settings_test_suite") | ||
|
||
construct_config_settings_test_suite( | ||
name = "construct_config_settings_tests", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Tests for construction of Python version matching config settings.""" | ||
|
||
load("@rules_testing//lib:analysis_test.bzl", "analysis_test") | ||
load("@rules_testing//lib:test_suite.bzl", "test_suite") | ||
load("@rules_testing//lib:truth.bzl", "subjects") | ||
load("@rules_testing//lib:util.bzl", rt_util = "util") | ||
|
||
_tests = [] | ||
|
||
def _subject_impl(ctx): | ||
_ = ctx # @unused | ||
return [DefaultInfo()] | ||
|
||
_subject = rule( | ||
implementation = _subject_impl, | ||
attrs = { | ||
"match_micro": attr.string(), | ||
"match_minor": attr.string(), | ||
"no_match": attr.string(), | ||
}, | ||
) | ||
|
||
def _test_minor_version_matching(name): | ||
rt_util.helper_target( | ||
_subject, | ||
name = name + "_subject", | ||
match_minor = select({ | ||
"//python/config_settings:is_python_3.11": "matched-3.11", | ||
"//conditions:default": "matched-default", | ||
}), | ||
match_micro = select({ | ||
"//python/config_settings:is_python_3.11": "matched-3.11", | ||
"//conditions:default": "matched-default", | ||
}), | ||
no_match = select({ | ||
"//python/config_settings:is_python_3.12": "matched-3.12", | ||
"//conditions:default": "matched-default", | ||
}), | ||
) | ||
|
||
analysis_test( | ||
name = name, | ||
target = name + "_subject", | ||
impl = _test_minor_version_matching_impl, | ||
config_settings = { | ||
str(Label("//python/config_settings:python_version")): "3.11.1", | ||
}, | ||
) | ||
|
||
def _test_minor_version_matching_impl(env, target): | ||
target = env.expect.that_target(target) | ||
target.attr("match_minor", factory = subjects.str).equals( | ||
"matched-3.11", | ||
) | ||
target.attr("match_micro", factory = subjects.str).equals( | ||
"matched-3.11", | ||
) | ||
target.attr("no_match", factory = subjects.str).equals( | ||
"matched-default", | ||
) | ||
|
||
_tests.append(_test_minor_version_matching) | ||
|
||
def construct_config_settings_test_suite(name): | ||
test_suite( | ||
name = name, | ||
tests = _tests, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using
build_setting_default = python_versions[0]
here looks like a minor bug, BTW.It enables a config setting, and if user manages to configure a toolchain that matches this full version, this toolchain will be selected by default, instead of the one marked by the
is_default
attr inpython.toolchain(...)
.I think a better approach would be to have something like
build_setting_default = "default"
andvalues = ["default"] + allowed_flag_values
passed to thestring_flag(...)
.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.
"default" is a bit overloaded here.
What python.toolchain's
is_default=True
affects is what//conditions:default
points to, essentially. If that is hit, it basically means either the version-unaware rules are being used, or there is no matching version-aware toolchain configured.The
build_setting_default
value here affects what the version-aware rules use if there isn't something overriding the value (i.e. command line flag, or the target-specific override).I agree that it would be best if the version set with
is_default=True
in the module config should match what this flag defaults to. I think this is possible? By putting the value in a generated repo and loading it here, similar to how rules_python_internal works. But lets have that as part of a separate PR.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.
Added a comment to note this