sphinx-needs icon indicating copy to clipboard operation
sphinx-needs copied to clipboard

discrepancy between manually setting needs_extra_options and use of add_extra_option

Open David-Le-Nir opened this issue 2 years ago • 4 comments

I am using add_extra_option to add custom fields to needs.

If I define needtable I can see values for those fields and they are part of the needs.json.

In another document, using needs_external_needs to reference multiple external needs sources, I want to create the same needtable but here the values for custom fields are empty.

When running with debugger it shows that as the fields are not part of the app.config.needs_extra_options value (which is empty) at line 83 in external_needs

Thus when adding the fields with needs_extra_options directly, the issue does not appear and I can see custom fields for external needs in needtable.

David-Le-Nir avatar Jun 23 '23 09:06 David-Le-Nir

Thanks for reporting. For me, this is the expected behavior.

There is only one master for the configuration, the conf.py file.

If you import needs from an external source, your conf.py must also contain a configuration that supports the imported data. There is no automatic way to analyze imported data, extract missing configuration parts and add them to the one given by conf.py.

There were some discussions in the past to export also the used configuration, so that a project, which imports these data, can update its configuration with the missing parts. But it was just an idea, with no implementation yet.

In all of my bigger projects, this behavior is wanted by the responsible project leaders/teams. As they are importing data from 5-10 different docs and they want to keep their config under their control.

So for me, this is not a bug, more a feature ;)

I close this issue already. If you see it differently feel free to reopen it.

danwos avatar Jun 30 '23 06:06 danwos

My concern was initially that add_extra_option says in its doc that it is equivalent to manually using app.config.needs_extra_options. Thus to configure my document I preferred to use the api way instead of using more internal functions.

I agree the configuration cannot be automatic, just I would have thought using add_extra_option would have the same behavior and would be the cleanest way of adding extra options.

David-Le-Nir avatar Jun 30 '23 07:06 David-Le-Nir

Argh, got your problem now. And you are right, this is a bug.

add_extra_option adds the new config to our internal Config class. But the external_needs code is taking it from the app.config.needs_extra_option config value, which gets not updated by the API call.

I reopen the issue. And thanks for the clarification.

danwos avatar Jun 30 '23 07:06 danwos

not sure if it's a separate issue or an incidence of this bug, but when using e.g. sphinx-test-reports which uses add_extra_option() to add some fields such as result, those fields are not directly usable by expicitly written

.. need::  
  ...
  :result: something

directives because add_extra_option doesn't seem to be updating the NeedDirective.option_spec in the way that sphinx_needs.load_config does, and so it fails during rst parsing with an unknown option for the need:: directive.

tfh-cri avatar Jan 22 '24 15:01 tfh-cri