-
-
Notifications
You must be signed in to change notification settings - Fork 634
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
parametrize: expand grouped parametrizations. #21027
Conversation
Adding my response from the original slack thread from where the suggesting to implemented this functionality came around. Awesome! I’ve just tested and it works great! With only one small catch which I’m not sure if is expected or not. If I setup my defaults like:
I get the following error:
I can make the error go aways if I do this more verbose/specific alternative (and this works!):
I was under the impression that the all keyword should take care of this type of situations, is it failing because of the new parametrize functionality? Or am I missing something? |
Follow up on my previous comments about the behavior of def default_resolvers_per_python_version(**kwargs):
"""Expand a mapping of python version and resolvers into a BUILD __defaults__
specialized for python targets.
Expands:
default_resolvers_per_python_version(
py310=[
"service-a",
"service-b",
],
py39=[
"service-c",
"service-d",
"service-e,
],
)
Into:
__defaults__(
{ (python_sources, python_tests): dict(
**parametrize(
"py310-compat",
resolve=parametrize("service-a", "service-b")
interpreter_constraints=[
"CPython == 3.10.*",
]
),
**parametrize(
"py39-compat",
resolve=parametrize(
"service-c",
"service-d",
"service-e",
),
interpreter_constraints=[
"CPython == 3.9.*",
]
)
),
(python_requirement, ): dict(
resolve=parametrize(
"service-a",
"service-b",
"service-c",
"service-d",
"service-e",
),
)
}
)
"""
supported_versions = {
"py39": [
"CPython == 3.9.*",
],
"py310": [
"CPython == 3.10.*",
]
}
defaults_for_python_sources = {}
all_resolvers = set()
for version, resolvers in kwargs.items():
if version not in supported_versions:
raise ValueError(
"Invalid python version {}, we only support {}".format(
version, list(supported_versions.keys())
)
)
# parametrize resolvers and interpreter_constraints
defaults_for_python_sources.update(
parametrize(
f"{version}-compat",
resolve=parametrize(*resolvers),
interpreter_constraints=supported_versions[version],
)
)
all_resolvers.update(resolvers)
default_mapping = {
(python_sources, python_tests): defaults_for_python_sources,
(python_requirement): dict(
resolve=parametrize(*all_resolvers)
)
}
__defaults__(default_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.
Nice! A few questions/minor tweaks.
…ct conflicts from nested parametrizations.
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.
Nice!
This adds support for having parametrized fields within a parametrize group.
Example:
Notice
Parametrize groups does not work well with defaults for
all
, as the parametrized fields will be added to all targets and will result in errors unless it's a field that all targets support.