pythonpython-sphinxtraceability

How to remove traceability relations dynamically in python-sphinx conf.py


I'm using the traceability plugin for python-sphinx: sphinx traceaility plugin

The test has the following .rst documentation:

@rst
  .. item:: TST-Example
     :applicable_to: PRD-ALL
@endrst

and I want to convert PRD-ALL to a list of predefined products PRD-A PRD-B. So I was thinking to add this logic inside the traceability_callback_per_item callback which is provided by the plugin:

def traceability_callback_per_item(name, collection):
    item = collection.get_item(name)

    if name.startswith('TST-'):
        applicable_to = list(item.iter_targets('applicable_to'))

        if 'PRD-ALL' in applicable_to:
            collection.add_relation(item.identifier, 'applicable_to', 'PRD-A')
            collection.add_relation(item.identifier, 'applicable_to', 'PRD-B')

            # remove PRD-ALL from 'applicable_to' relation:
            # HOW?

I tried:

item.remove_targets('PRD-ALL', explicit=True, implicit=True, relations=['applicable_to'])

but then I get the warning:

WARNING: No automatic reverse relation: TST-Example applicable_to PRD-ALL

which fails the build as it intentionally runs with -W.

Any idea?


Solution

  • Found a solution eventually, possibly not the 'right' way but it works:

    # remove TST --> PRD relation
    item.remove_targets('PRD-ALL', explicit=True, implicit=True,
                        relations=['applicable_to'])
    
    # remove PRD --> TST relation
    prod_item = collection.get_item('PRD-ALL')
    prod_item.remove_targets(item.identifier, explicit=True, implicit=True,
                             relations=['covered_by'])
    

    Note that covered_by is specified in the traceability_relations global variable:

    traceability_relationships = {
        # ...
        'applicable_to': 'covered_by'
    }