Given a `GoalSubsystem`, how can I iterate over th...
# plugins
p
Given a
GoalSubsystem
, how can I iterate over the options (in my
@goal_rule
)?
subsystem.options
I want to get all of the options registered for my subsystem that have modified values.
h
On any subsystem, the
.options
property is an instance of
OptionValueContainer
(https://github.com/pantsbuild/pants/blob/2.6.x/src/python/pants/option/option_value_container.py#L49)
And that has all sorts of useful methods
So, for example,
get_explicit_keys()
will return all options that were set explicitly (via flag, config or env var)
but note that if they were set explicitly to the same value as the default, they will appear here, which may not be what you want
But if that's OK, then this is how to do it
p
awesome thanks
Hmm. What about filtering
.options.get_explicit_keys()
so I only get the vars registered under my goal's scope? I see a variety of pants related options:
['backend_packages', 'plugins', 'pants_version', 'pants_bin_name', 'pants_workdir', 'pants_supportdir', 'pants_distdir', 'pythonpath', 'pants_ignore']
h
Hm, that is an instance of https://github.com/pantsbuild/pants/issues/10834. @witty-crayon-22786 how hard would that be for us to fix and possibly cherry-pick? This feels like low hanging fruit for cache hit optimizations
w
Unsure!
h
I'll take a quick stab at it!
🙌 1
In v1 accessing outer options from inner scopes was ubiquitous, but I think in v2 it should never happen
âž• 1
p
If I need global options, I can request them separately. So, they aren't needed here, and are confusing here. 🙂
h
Yep, for sure
I will look into getting rid of that, it was a v1 legacy thing
the options system is basically the only thing we carried over into v2