-
Notifications
You must be signed in to change notification settings - Fork 14
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
docs: feature flag handling #217
base: main
Are you sure you want to change the base?
docs: feature flag handling #217
Conversation
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/README.md
Outdated
Show resolved
Hide resolved
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/README.md
Outdated
Show resolved
Hide resolved
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/README.md
Outdated
Show resolved
Hide resolved
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/README.md
Outdated
Show resolved
Hide resolved
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/modularity.py
Outdated
Show resolved
Hide resolved
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/modularity.py
Outdated
Show resolved
Hide resolved
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/modularity.py
Outdated
Show resolved
Hide resolved
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/modularity.py
Outdated
Show resolved
Hide resolved
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/modularity.py
Outdated
Show resolved
Hide resolved
This PR provdies a way to disable requirements based on feature flags set in bazel. It has a 'translation' layer where we can map feature flags to tags, which are then used to disable/hide requirements.
Added integration tests to the packaging. Added docstrings to functions inside the extension. Formatting also done.
docs/_tooling/sphinx_extensions/sphinx_extensions/build/modularity/README.md
Outdated
Show resolved
Hide resolved
```bzl | ||
FEATURE_TAG_MAPPING = { | ||
"feature1": ["some-ip", "tag2"], # --//docs:feature1=true -> will expand to 'some-ip', 'tag2' | ||
"second-feature": ["test-feat", "tag6"], | ||
} | ||
``` | ||
|
||
The default values are defined like such: | ||
```bzl | ||
def define_feature_flags(name): | ||
bool_flag( | ||
name = "feature1", | ||
build_setting_default = False, | ||
) | ||
bool_flag( | ||
name = "second-feature", | ||
build_setting_default = False, | ||
) | ||
|
||
feature_flag_translator( | ||
name = name, | ||
flags = {":feature1": "True", ":second-feature": "True"}, | ||
) | ||
``` |
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.
This restricts us to only bool flags. We also need to consider other feature_flag types of Skylark. But for now this is a great start.
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.
That is true, but the foundation at least should allow this to be expanded into other flag types in the future. The translation then might have to be adapted to account for those.
Revised logic, so now feature=true means that those requirements are enabled, not disabled. Added a decision record to lay out why 'hide' was choosen Adapted README to make it a bit clearer. Added wrappers for filtering functions used by needpie, etc.
e1fa9ab
to
6ddf262
Compare
docs/BUILD
Outdated
@@ -171,3 +177,28 @@ score_py_pytest( | |||
visibility = ["//visibility:public"], | |||
deps = [":score_metamodel"], | |||
) | |||
|
|||
py_library( | |||
name = "modularity", |
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.
Can we pick a name that is less ambiguous? "modularity" is too close to "module" which we will be using for the SCORE code implementations. Something with "variant", "feature" or "flag" maybe?
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.
The name was chosen as packaging didn't sound right and might interfere with other things. I think for sure though a more descriptive name would be better.
Maybe one of these?
- FlagConfiguration
- VariantHandling
- FeatureFlagsConfig
- ConfigureRequirements
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.
FeatureFlaggedRequirements 😆
This requirement will not be disabled. | ||
``` | ||
We can then build it with our feature flag enabled via `bazel build //docs:docs --//docs:second-feature=true` | ||
This will expand via our translation layer `feature_flag.bzl` into the tags `test-feat` and `tag5`. |
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.
Why do we need such a translation layer? Unless I missed it, it's not described anywhere?
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.
The main reason why it is needed is to make it possible to expand one flag into multiple tags. We theoretically could work without this layer with some adaptations, but then you need to add EACH tag as a separate argument in the command.
Edit:
It also allows for more complex 'flags' in the future instead of just 'boolean' as it is currently.
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.
Why do we have more flags than commands? Can you mention that somewhere in md/rst?
fake_app_ok = SimpleNamespace() | ||
fake_app_ok.config = SimpleNamespace() | ||
fake_app_ok.config.filter_tags_file_path = str( | ||
feature_flags_dir / "filter_tags.txt" | ||
) |
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.
e.g.: fake_app_ok = fake_app({filter_tags_file_path: str( feature_flags_dir / "filter_tags.txt" )})
def test_modularity_hide_ok( | ||
sphinx_app_setup, basic_conf, basic_rst_file, positive_filter_tags, sphinx_base_dir | ||
): | ||
app = sphinx_app_setup(basic_conf, basic_rst_file, positive_filter_tags) |
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.
👍
Reworked README to add clarity Renamed extension from modularity to give a more meaningful name Reverted upgraded lockfile Integrated extension/feature into 'incremental'
Can't the extension As some Sphinx-Needs internal functions get monkey patched, I see a huge risk that this may not work with upcoming Sphinx-Needs releases and it keeps the maintenance high on the SCORE side. So would it be okay to create an upstream PR with this and get rid of the SCORE-specific implementation for the Sphinx-Needs part? |
This for sure would make future compatibility nicer and easier. I could make this an upstream PR, although some questions would need to be clarified etc. |
def setup(app): | ||
logger.debug("score_feature_flag_handling extension loaded") | ||
app.add_config_value("filter_tags_file_path", None, "env") | ||
app.connect("env-updated", hide_needs) |
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.
There is a specific event for this needs-before-sealing
; func(app, needs)
, as mentioned in https://sphinx-needs.readthedocs.io/en/latest/changelog.html#improvements-to-filtering-at-scale
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.
Hmm interesting, I must have made a mistake then. I tried this in the beginning but decided not go go with it as something didn't quite work. I will check it out again, as if we have such specific events it would be nicer to call them correctly.
Thanks for pointing it out.
An issue in the Sphinx-Needs repo would be super. |
I have created a related Sphinx-Needs ticket: useblocks/sphinx-needs#1399 @MaximilianSoerenPollak Can you please check, if my description/idea supports your use case or if anything is missing? Thanks. |
@danwos how about a small issue for sphinx-needs to correctly account for |
That's tough because the current implementation is the expected one. For "hiding" it completely, |
@danwos well it can be there. It should just not show up in needpie etc?! |
That's the point for |
This PR is still a WIP as there is tests missing and some implementation details may change.
Any feedback is appreciated.
Todo
docs/_tooling/extensions
needtable
,needpie
etc. also ignore hidden requirementsdocs:incremental
PR provides a way to disable requirements based on feature flags set in bazel.
It has a 'translation' layer where we can map feature flags to tags, which are then used to disable/hide requirements.
Closes #202