Add feature flag helper#13859
Conversation
| ENABLED = enum.auto() | ||
|
|
||
|
|
||
| class FeatureFlag: |
There was a problem hiding this comment.
Even if not handled in this PR, it would be interesting to indicate how you imagine to handle non-boolean feature choices in the future, e.g. advanced option for UIA in Word documents which has 3 choices plus the default.
Would it be worth to reserve the name FeatureFlag for generic flag that may have any number of values (choices) and rename the FeatureFlag class to something like BooleanFeatureFlag? Or even better, implement FeatureFlag with all the generic stuff and implement a subclass BooleanFeatureFlag containing all what is specifically related to a 2-value choice (excepted Default)?
A MultiChoiceFeatureFlag class could be implemented subsequently.
There was a problem hiding this comment.
I named it this way based on the assumption that a boolean feature flag is more common.
Looking at this again, I can see another way to do this which allows the introduction of different sets of options for different flags (as per AllowUiaInChromium and AllowUiaInMSWord)
The feature flag config type could also accept a param optionsEnum="BoolFeature" or optionsEnum="AllowUiaInMsWord" which results in that enum being used to validate the options.
This ties the config to an enum type, giving the possibility of static type checking.
I'll try a proof of concept for this next week.
|
I've merged in #13871 and updated the description. |
|
To ensure this arrive in alpha all at once I'm going to squash the |
8ef45ec to
1bcd5d4
Compare
Update changes file for PR 13859
11f1130 to
e7df831
Compare
Link to issue number:
As per PR #13851
Also merges in support for multi value feature flags: #13871
Summary of the issue:
NVDA increasingly makes use of feature flags to expose experimental changes to users.
There are already several approaches already in use.
It is easy to miss use-cases for changing default behavior, potentially overriding an advanced users preferred config.
Some feature flags require more than just a Boolean enabled/disabled outcome (in addition to 'default'), E.G.:
AllowUiaInMSWord[WHEN_NECESSARY,WHERE_SUITABLE, ALWAYS]AllowUiaInChromium[WHEN_NECESSARY,YES,NO]Several approaches have been tried:
intin the config that match withenumvalues, as per (AllowUiaInMSWordandAllowUiaInChromium)stringvalues). Literal strings in code to compare refer to these.These approaches can hide errors:
configorconfigSpec, how can the behavior of default be determined?Description of user facing changes
The target user of this change are developers.
This introduces constructs and utilities to streamline the approach to adding feature flags.
Adding a new feature flag:
BoolFlag.featureFlagEnums.py(include aDEFAULTmember) E.G.:MyNewFeatureconfigSpec.pyE.G.shouldUseMyNewFeature = featureFlag(optionsEnumClass="MyNewFeature", behaviorOfDefault="ON_WEEKENDS")FeatureFlagComboconfig.conf["section"]["shouldUseMyNewFeature "] == MyNewFeature.ON_WEEKENDSDescription of development approach
Introduction of a generic
BoolFlagtype (enabled/disabled) which needs to account for 3 states:To facilitate this, one of the three values (default, enabled, disabled) is stored in the config.
Spec/config transformations are provided to streamline the support.
A
featureFlagtype in the spec is automatically converted to aFeatureFlagclass instance.The
FeatureFlagclass abstracts the consideration of "default", allowing theFeatureFlagto treated as a boolean within internal NVDA logic.A utility GUI control is added which presents the
FeatureFlagoption to the user, and allows developers to give translated names to the logical values (enabled, disabled), the name for default incorporates thebehaviorOfDefault(and is also translated).Note:
configSpecexplicitly defines what the behavior of default is.Testing strategy:
Known issues with pull request:
This approach bypasses the handling for defaults provided by configObj.
It was considered whether the default not written on read behavior (of the configObj library) to facilitate the third (default) state.
However:
conf["section"]["myKey"]was just the default or an explicit setting.configObjmakes transforming the type (to provide an abstraction) difficult. It is not possible to get access to thedefaultwithout a similar approach used in this PR. If adopting the complexity of a spec and config transform step, then it is preferable to have explicit values for default. Explicit values make the config easier to inspect and make the approach more robust.Change log entries:
For Developers
Code Review Checklist: