Skip to content

Add feature flag helper#13859

Merged
feerrenrut merged 1 commit into
loadVbufStateSystemBusyfrom
addFeatureFlagHelper
Jul 12, 2022
Merged

Add feature flag helper#13859
feerrenrut merged 1 commit into
loadVbufStateSystemBusyfrom
addFeatureFlagHelper

Conversation

@feerrenrut

@feerrenrut feerrenrut commented Jun 30, 2022

Copy link
Copy Markdown
Contributor

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:

  • Store an int in the config that match with enum values, as per (AllowUiaInMSWord and AllowUiaInChromium)
  • Use "options" in config (several string values). Literal strings in code to compare refer to these.

These approaches can hide errors:

  • Looking at the config, what are the valid values when an integer is used.
  • Using string "options":
    • what are the valid options?
    • how do you find all usages?
    • Change the strategy for default?
  • For both, when looking at the config or configSpec, 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:

  • Most feature flags can use the BoolFlag.
  • If more values are required, define a new enum class in featureFlagEnums.py (include a DEFAULT member) E.G.: MyNewFeature
  • Add the entry to the configSpec.py E.G. shouldUseMyNewFeature = featureFlag(optionsEnumClass="MyNewFeature", behaviorOfDefault="ON_WEEKENDS")
  • Add a GUI option for it, using FeatureFlagCombo
  • Wrap the code for the feature with config.conf["section"]["shouldUseMyNewFeature "] == MyNewFeature.ON_WEEKENDS

Description of development approach

Introduction of a generic BoolFlag type (enabled/disabled) which needs to account for 3 states:

  • The current NVDA default (IE user has no preference)
  • User has a preference of enabled
  • User has a preference of disabled

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 featureFlag type in the spec is automatically converted to a FeatureFlag class instance.
The FeatureFlag class abstracts the consideration of "default", allowing the FeatureFlag to treated as a boolean within internal NVDA logic.

A utility GUI control is added which presents the FeatureFlag option to the user, and allows developers to give translated names to the logical values (enabled, disabled), the name for default incorporates the behaviorOfDefault (and is also translated).

Note:

  • The configSpec explicitly defines what the behavior of default is.
  • The enum class that backs the config is defined, allows for type / value checking.
  • Existing flags have not been upgraded, these would require upgrade code for the config, this introduces unnecessary complexity.

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:

  • This would require explicit code to test for the existence of the key to know if the value returned by conf["section"]["myKey"] was just the default or an explicit setting.
  • It also requires careful diligence to ensure that the value is not ever written accidentally.
  • Code to delete the key is required whenever attempting to return to the default.
  • The way validation checks are created in configObj makes transforming the type (to provide an abstraction) difficult. It is not possible to get access to the default without 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

- A config spec type ``featureFlag`` has been created for use with experimental features in NVDA. See devDocs/featureFlag.md for more information.

Code Review Checklist:

  • Pull Request description:
    • description is up to date
    • change log entries
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • API is compatible with existing add-ons.
  • Documentation:
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English

@feerrenrut

Copy link
Copy Markdown
Contributor Author

Review actions from #13851 are in commit 7ac7eaf

@feerrenrut feerrenrut marked this pull request as ready for review June 30, 2022 10:49
@feerrenrut feerrenrut requested a review from a team as a code owner June 30, 2022 10:49
@feerrenrut feerrenrut requested review from seanbudd and removed request for a team June 30, 2022 10:49
Comment thread source/gui/settingsDialogs.py Outdated
Comment thread source/gui/nvdaControls.py Outdated
ENABLED = enum.auto()


class FeatureFlag:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at #13871

Comment thread devDocs/featureFlags.md Outdated
Comment thread source/NVDAObjects/IAccessible/chromium.py Outdated
Comment thread source/gui/settingsDialogs.py Outdated
Comment thread devDocs/featureFlags.md Outdated
seanbudd
seanbudd previously approved these changes Jul 4, 2022
@feerrenrut feerrenrut self-assigned this Jul 4, 2022
@feerrenrut feerrenrut mentioned this pull request Jul 5, 2022
5 tasks
Comment thread source/NVDAObjects/IAccessible/chromium.py
@feerrenrut

Copy link
Copy Markdown
Contributor Author

I've merged in #13871 and updated the description.

@feerrenrut feerrenrut requested a review from seanbudd July 8, 2022 10:11
Comment thread requirements.txt Outdated
Comment thread source/NVDAObjects/IAccessible/chromium.py
Comment thread source/config/featureFlag.py Outdated
Comment thread source/config/featureFlag.py Outdated
Comment thread source/config/featureFlagEnums.py Outdated
Comment thread devDocs/featureFlags.md Outdated
Comment thread source/gui/nvdaControls.py Outdated
Comment thread source/gui/nvdaControls.py Outdated
Comment thread source/config/featureFlag.py Outdated
Comment thread source/config/featureFlagEnums.py Outdated
@seanbudd seanbudd dismissed their stale review July 11, 2022 03:42

stale approval

@feerrenrut

Copy link
Copy Markdown
Contributor Author

To ensure this arrive in alpha all at once I'm going to squash the loadVbufStateSystemBusy branch and squash merge this PR into that one, then merge that into master.

@feerrenrut feerrenrut force-pushed the loadVbufStateSystemBusy branch 2 times, most recently from 8ef45ec to 1bcd5d4 Compare July 12, 2022 09:32
Update changes file for PR 13859
@feerrenrut feerrenrut force-pushed the addFeatureFlagHelper branch from 11f1130 to e7df831 Compare July 12, 2022 09:34
@feerrenrut feerrenrut merged commit e86094a into loadVbufStateSystemBusy Jul 12, 2022
@feerrenrut feerrenrut deleted the addFeatureFlagHelper branch July 12, 2022 09:42
@nvaccessAuto nvaccessAuto added this to the 2022.3 milestone Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants