Skip to content
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

sphinx-needs master throws warning needs.filter on seemingly valid filter function #1167

Open
arwedus opened this issue Apr 25, 2024 · 1 comment

Comments

@arwedus
Copy link
Contributor

arwedus commented Apr 25, 2024

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".

@danwos
Copy link
Member

danwos commented Apr 30, 2024

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:
image
image

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 :)

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

No branches or pull requests

2 participants