sphinx-needs
sphinx-needs copied to clipboard
sphinx-needs master throws warning needs.filter on seemingly valid filter function
Hi all!
given this document:
.. needpie:: System Requirement Status
:legend:
:text_color: w
:labels: draft, assumed, rejected
:explode: 0, 0.3, 0
id.startswith("REQ_SYS_DC_") and status == 'draft'
id.startswith("REQ_SYS_DC_") and status == 'assumed'
id.startswith("REQ_SYS_DC_") and status == 'rejected'
.. needpie:: System Requirements linked to Feature
:legend:
:text_color: w
:labels: linked, unlinked
:explode: 0.3, 0.0
id.startswith("REQ_SYS_DC_") and status not in "rejected" and derives
id.startswith("REQ_SYS_DC_") and status not in "rejected" and not derives
Requirement without links
-------------------------
.. req-sys:: DC Configuration Availability
:id: REQ_SYS_DC_0001
:status: assumed
The subsystem shall maintain its configuration across ignition cycles.
Trigger Actions
---------------
.. req-sys:: DC Trigger Debounce
:id: REQ_SYS_DC_0002
:status: assumed
:derives: FEATURE_DC_SW_CRASHES
The subsystem shall provide a mechanism to debounce detections of the same trigger.
.. req-sys:: DC Trigger Action
:id: REQ_SYS_DC_0003
:status: assumed
:derives: FEATURE_DC_RECOMPUTE_ACTIVITY
The subsystem shall provide a trigger action called ...
I get this warning with sphinx-needs master:
system_requirements/index.rst:122: WARNING: Filter 'id.startswith("REQ_SYS_DC_") and status not in "rejected" and derives' not valid. Error: Filter did not evaluate to a boolean, instead <class 'list'>: ['REQ_SYS_DC_FFI']. [needs.filter]
The needpie filters used to do just what the author expected: Show a pie diagram with number of requirements which have a ":derives:" link vs. number of requirements having no ":derives:" link.
Indeed, the shown needpie is wrong. The filter condition must be changed to:
.. needpie:: System Requirements linked to Feature
:legend:
:text_color: w
:labels: linked, unlinked
:explode: 0.3, 0.0
id.startswith("REQ_SYS_DC_") and da_status not in "rejected" and len(derives) > 0
id.startswith("REQ_SYS_DC_") and da_status not in "rejected" and len(derives) == 0
Question: Why? Looks like a subtle incompatibility in the sphinx filter "API".
derives
contains links, so it is a list, for instance ["my_link", "another_link"]
.
Checking for derives
in a filters-string or python-statement will return the list and not a boolean interpretation (as it does when it gets checked in an if
statement).
You can check this directly via python
:
Also please be aware that da_status not in "rejected"
is checking for a single character, not the complete string. So da_status = "c"
would return False
here.
da_status not in ["rejected",]
would be safer :)