question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support default values for options per file

See original GitHub issue

It would be nice to specify need option values not only globally but per file as well.

The default option values is currently available on a per-project basis in sphinx-needs:

needs_global_options = {
      'my_option': 'my_global_value'
}

However, in big projects, requirements with different “standard options” exist, and per-file grouping is a natural strategy to structure them. In projects with some mandatory requirements attributes, repeated options lead to visual noise (repetitive content repeated a lot with little additional information).

Now:

.. need:: 
   :id: NEED_ID_1
   :my_option: same_value
   :some-other-option: value1

.. need:: 
   :id: NEED_ID_2
   :my_option: same_value
   :some-other-option: value2

.. need:: 
   :id: NEED_ID_3
   :my_option: same_value
   :some-other-option: value2

Later:

.. needoptions:
  :my_option: same_value

.. need:: 
   :id: NEED_ID_2
   :some-other-option: value1

.. need:: 
   :id: NEED_ID_2
   :some-other-option: value2

.. need:: 
   :id: NEED_ID_3
   :some-other-option: value2

The needoptions shall apply to all needs in the current page starting where the directive appears. Probably there could be a filter option as well to filter certain need types (within the page).

Idea came from @arwedus 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
danwoscommented, Jul 1, 2021

Good points and I agree. conf.py should not be too related to the internal documentation structure.

I also thought that your case is somehow related to inheritance.

Here is an idea:

Need can inherit from any other need


.. need:: My basic need
   :id: basic_001
   :status: open
   :tags: tag_01
   :hide: true
   
.. need:: Another need
   :id: REAL_NEED_001
   :tags: my_tag
   :inherit: basic_001     

REAL_NEED_001 will have status: open and tags: my_tag.

The user can decide, if a need like basic_001 shall be shown or gets hidden. basic_001 could also get automatically inherited_from: True as option, so that all needs which are used for inheritance could get the hide-option automatically via needs_global_options.

This somehow feels like needextend, but only the other way around.

Beside the overall inheritance idea, wouldn’t needextend be a solution for your case?

.. needextend:: docname == "this_page.rst"
  :my_option: same_value

.. need:: 
   :id: NEED_ID_2
   :some-other-option: value1

.. need:: 
   :id: NEED_ID_2
   :some-other-option: value2

.. need:: 
   :id: NEED_ID_3
   :some-other-option: value2
1reaction
danwoscommented, May 31, 2022

Regarding the correct docname, you can check the set value by using the debug layout in one of your need objects:

.. dod::  An example
   :id: DOD_001
   :layout: debug 

Docs: https://sphinxcontrib-needs.readthedocs.io/en/latest/layout_styles.html#EX_DEBUG This shows you also all the other option values.

In your case I think the correct one is work_products/software_wp/sw_req_eng_wp/sw_requirements_specification_wp, without the file extension.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set default values for fields or controls - Microsoft Support
Click the All tab in the property sheet, locate the Default Value property, and then enter your default value. Press CTRL+S to save...
Read more >
Support click.option with default values / optional arguments
Since the default value always applies, there should be a way to differentiate between the following options usage: file.py file.py --foo
Read more >
Does Java support default parameter values? - Stack Overflow
No, the structure you found is how Java handles it, (that is, with overloading instead of default parameters).
Read more >
Compiler option defaults - IBM
To find out the current defaults, compile a program with only the SOURCE compiler option specified. The compiler listing shows the options that...
Read more >
CLI Options with Help - Typer - tiangolo
We are replacing the default values we had before with typer.Option() . As we no longer have a default value there, the first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found