-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
bb8671f
commit 6ddf262
Showing
14 changed files
with
315 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Decision Record: How to disabale requirements | ||
|
||
## Context | ||
[Feature Flags](https://eclipse-score.github.io/score/process/guidance/feature_flags/index.html#feature-flags) require the functionality | ||
of disable or enabeling requirements based on which feature flags were provided, in order to build relevant documentation only. | ||
This decision record will contain what implementation was choosen to enable this feature. | ||
|
||
## Decision | ||
Use the 'hide' option from sphinx-needs objects to remove/disable requirements. | ||
|
||
## Chosen Solution: 'hide' Option | ||
The 'hide' option was selected as the primary implementation method. | ||
|
||
### Advantages | ||
- Can be set programmatically with minimal complexity | ||
- Maintains document structure integrity | ||
- Provides clear control over element visibility | ||
- Predictable behavior in programmatic contexts | ||
|
||
### Negatives | ||
- Requirements still appear in the rst via 'view source code' | ||
- Information only saved inside the `NeedsInfoType` objects | ||
|
||
## Alternatives Considered | ||
|
||
### Alternative 1: `:delete:` Option | ||
**Why Not Chosen:** | ||
- Lacks programmatic control capabilities. Can only be set hardcoded inside rst files | ||
|
||
More info: [Delete option docs](https://sphinx-needs.readthedocs.io/en/latest/directives/need.html#delete) | ||
|
||
### Alternative 2: `del_need` Method | ||
**Why Not Chosen:** | ||
- Introduces complexity in document node management | ||
- Creates challenges in locating correct manipulation points | ||
- Risk of document structure corruption during build | ||
- Increases maintenance overhead due to complex node relationships | ||
|
||
More info: [del_need docs](https://sphinx-needs.readthedocs.io/en/latest/api.html#sphinx_needs.api.need.del_need) | ||
|
||
### Alternative 3: `variations` Approach | ||
**Why Not Chosen:** | ||
- Filtering behavior appears inconsistent or non functional when used programmatically | ||
- Requires hardcoding in configuration files for reliable operation | ||
|
||
More info: [variations docs](https://sphinx-needs.readthedocs.io/en/latest/configuration.html#needs-variants) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# ******************************************************************************* | ||
# Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Apache License Version 2.0 which is available at | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# ******************************************************************************* | ||
from sphinx.application import Sphinx | ||
from sphinx_needs.views import NeedsView | ||
from sphinx_needs.data import NeedsInfoType, NeedsFilteredBaseType | ||
from sphinx_needs.config import NeedsSphinxConfig | ||
from sphinx_needs.views import NeedsAndPartsListView | ||
from docutils import nodes | ||
from sphinx_needs.debug import measure_time | ||
|
||
|
||
# ╭──────────────────────────────────────────────────────────────────────────────╮ | ||
# │ Wrapping filter funcs to enable 'hide' to be respected │ | ||
# ╰──────────────────────────────────────────────────────────────────────────────╯ | ||
|
||
|
||
def wrap_filter_common(): | ||
""" | ||
Wrapper function to avoid circular imports by importing filter_common at runtime instead of module level. | ||
This wraps two functions used by sphinx_needs directives 'needtable' etc. in order to ensure that the | ||
hidden requirements are not showing up in the results. | ||
""" | ||
from sphinx_needs import filter_common | ||
|
||
orig_common = filter_common.process_filters | ||
orig_parts = filter_common.filter_needs_parts | ||
|
||
@measure_time("filtering") | ||
def common_wrapper( | ||
app: Sphinx, | ||
needs_view: NeedsView, | ||
filter_data: NeedsFilteredBaseType, | ||
origin: str, | ||
location: nodes.Element, | ||
include_external: bool = True, | ||
): # Used by needlist, needtable and needflow. | ||
needs_view = needs_view._copy_filtered( | ||
i["id"] for i in needs_view.Values() if i["hide"] != True | ||
) | ||
return orig_common( | ||
app, needs_view, filter_data, origin, location, include_external | ||
) | ||
|
||
@measure_time("filtering") | ||
def parts_wrapper( | ||
needs: NeedsAndPartsListView, | ||
config: NeedsSphinxConfig, | ||
filter_string: None | str = "", | ||
current_need: NeedsInfoType | None = None, | ||
*, | ||
location: tuple[str, int | None] | nodes.Node | None = None, | ||
append_warning: str = "", | ||
strict_eval: bool = False, | ||
): # Used by needpie | ||
if filter_string is not None and filter_string != "": | ||
filter_string += " and hide != True" | ||
else: | ||
filter_string = "hide != True" | ||
return orig_parts( | ||
needs, | ||
config, | ||
filter_string, | ||
current_need, | ||
location=location, | ||
append_warning=append_warning, | ||
strict_eval=strict_eval, | ||
) | ||
|
||
# Patch the original module | ||
filter_common.process_filters = common_wrapper | ||
filter_common.filter_needs_parts = parts_wrapper |
File renamed without changes
Oops, something went wrong.