Change options declarations to use inner-classes #19126
Replies: 7 comments 22 replies
-
Only downside i can see so far is there might not be a way to enforce the class attributes type-wise. E.g. if you forget to define |
Beta Was this translation helpful? Give feedback.
-
Would you expect rule authors to always define the specific options they want as rule inputs (#18856)? @stuhood, any idea if this would blow up the rule graph in a bad way? Now we have one rule per option, rather than one per subsystem. |
Beta Was this translation helpful? Give feedback.
-
How do you think this would interact with |
Beta Was this translation helpful? Give feedback.
-
Considered @rule
def my_rule(colors_container: Annotated[BoolOption, GlobalOptions.colors]) -> ...: |
Beta Was this translation helpful? Give feedback.
-
Ah and for the record, changing the existing descriptors to return a @rule
def whatever(colors_container: GlobalOptions.color) -> ...:
... results in:
|
Beta Was this translation helpful? Give feedback.
-
class GlobalOptions(BootstrapOptions, Subsystem):
options_scope = GLOBAL_SCOPE
help = "Options to control the overall behavior of Pants."
class Colors(BoolOption):
default = sys.stdout.isatty()
help = softwrap(
"""
Whether Pants should use colors in output or not. This may also impact whether
some tools Pants runs use color.
When unset, this value defaults based on whether the output destination supports color.
"""
) I think I like subclassing because it is similar to defining a target Field.
Why do you prefer a decorator over a subclass? |
Beta Was this translation helpful? Give feedback.
-
I don't feel strongly about this either way, but I like the improved granularity of option requests. One relevant detail is that because |
Beta Was this translation helpful? Give feedback.
-
I want to fix #18856, which has a secondary benefit of making rule inputs more fine-grained.
The only way to accomplish that is by converting options declarations to be types, so that they are valid annotations.
As a strawman, that'd look something like:
which was previously:
Then rule code needing the option would use:
This would extend to environment-aware options as well (although the details are fuzzy to me)
And this also gives us a place to provide argument conversion (E.g. the class can define a
convert_value
)One downside is that helper methods on subsystems would be harder to call. E.g.
my_subsystem.super_cool_method(...)
would likely be class methods taking the individual options:MySubsystem.super_cool_method(..., ..., ...)
Beta Was this translation helpful? Give feedback.
All reactions