You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
✨ Add ndf role, deprecate need_func & [[...]] in need content (#1269)
There were previously two methods to use dynamic functions within need directive's content:
1. ``[[copy("id")]]``; is problematic, because it does not adhere to the rst / myst syntax specification, and has already shown to cause parsing issues and be surprising to users
2. `` :need_func:`[[copy("id")]]` ``; is better but overly verbose
In this commit, these are replaced by the role: `` :ndf:`copy("id")` ``
Here we take the entire content to be the function, as so do not require the `[[]]`, reducing verbosity and processing
The other two methods now emit a deprecation warning, showing how to convert them to the new role.
Copy file name to clipboardExpand all lines: docs/dynamic_functions.rst
+14-11
Original file line number
Diff line number
Diff line change
@@ -3,32 +3,35 @@
3
3
Dynamic functions
4
4
=================
5
5
6
-
**Sphinx-Needs** provides a mechanism to set dynamic data for need-options during generation.
7
-
We do this by giving an author the possibility to set a function call to a predefined function, which calculates
8
-
the final result/value for the option.
6
+
Dynamic functions provide a mechanism to specify need fields or content that are calculated at build time, based on other fields or needs.
7
+
8
+
We do this by giving an author the possibility to set a function call to a predefined function, which calculates the final value **after all needs have been collected**.
9
9
10
10
For instance, you can use the feature if the status of a requirement depends on linked test cases and their status.
11
11
Or if you will request specific data from an external server like JIRA.
12
12
13
-
**needtable**
14
-
15
-
The options :ref:`needtable_style_row` of :ref:`needtable` also support
16
-
dynamic function execution. In this case, the function gets executed with the found need for each row.
17
-
18
-
This allows you to set row and column specific styles such as, set a row background to red, if a need-status is *failed*.
13
+
To refer to a dynamic function, you can use the following syntax:
19
14
15
+
- In a need directive option, wrap the function call in double square brackets: ``function_name(arg)``
16
+
- In a need content, use the :ref:`ndf` role: ``:ndf:\`function_name(arg)\```
20
17
21
18
.. need-example:: Dynamic function example
22
19
23
20
.. req:: my test requirement
24
21
:id: df_1
25
22
:status: open
23
+
:tags: test;[[copy("status")]]
26
24
27
-
This need has id **[[copy("id")]]** and status **[[copy("status")]]**.
25
+
This need has id :ndf:`copy("id")` and status :ndf:`copy("status")`.
26
+
27
+
.. deprecated:: 3.1.0
28
+
29
+
The :ref:`ndf` role replaces the use of the ``[[...]]`` syntax in need content.
28
30
29
31
Built-in functions
30
32
-------------------
31
-
The following functions are available in all **Sphinx-Needs** installations.
"srcdir/index.rst:40: WARNING: Error while executing function 'copy': Need not found [needs.dynamic_function]"
29
+
'srcdir/index.rst:11: WARNING: The `need_func` role is deprecated. Replace with :ndf:`copy("id")` instead. [needs.deprecation]',
30
+
'srcdir/index.rst:40: WARNING: The `need_func` role is deprecated. Replace with :ndf:`copy("id")` instead. [needs.deprecation]',
31
+
'srcdir/index.rst:44: WARNING: The `need_func` role is deprecated. Replace with :ndf:`copy("id")` instead. [needs.deprecation]',
32
+
'srcdir/index.rst:9: WARNING: The [[copy("id")]] syntax in need content is deprecated. Replace with :ndf:`copy("id")` instead. [needs.deprecation]',
33
+
'srcdir/index.rst:27: WARNING: The [[copy("tags")]] syntax in need content is deprecated. Replace with :ndf:`copy("tags")` instead. [needs.deprecation]',
34
+
"srcdir/index.rst:33: WARNING: The [[copy('id')]] syntax in need content is deprecated. Replace with :ndf:`copy('id')` instead. [needs.deprecation]",
35
+
"srcdir/index.rst:38: WARNING: The [[copy('id')]] syntax in need content is deprecated. Replace with :ndf:`copy('id')` instead. [needs.deprecation]",
36
+
"srcdir/index.rst:44: WARNING: Error while executing function 'copy': Need not found [needs.dynamic_function]",
37
+
"srcdir/index.rst:44: WARNING: Error while executing function 'copy': Need not found [needs.dynamic_function]",
"srcdir/index.rst:10: WARNING: Return value of function 'bad_function' is of type <class 'object'>. Allowed are str, int, float, list [needs.dynamic_function]",
131
+
"srcdir/index.rst:8: WARNING: The [[my_own_function()]] syntax in need content is deprecated. Replace with :ndf:`my_own_function()` instead. [needs.deprecation]",
132
+
"srcdir/index.rst:14: WARNING: The [[bad_function()]] syntax in need content is deprecated. Replace with :ndf:`bad_function()` instead. [needs.deprecation]",
121
133
"srcdir/index.rst:14: WARNING: Return value of function 'bad_function' is of type <class 'object'>. Allowed are str, int, float, list [needs.dynamic_function]",
134
+
"srcdir/index.rst:16: WARNING: The [[invalid]] syntax in need content is deprecated. Replace with :ndf:`invalid` instead. [needs.deprecation]",
122
135
"srcdir/index.rst:16: WARNING: Function string 'invalid' could not be parsed: Given dynamic function string is not a valid python call. Got: invalid [needs.dynamic_function]",
136
+
"srcdir/index.rst:18: WARNING: The [[unknown()]] syntax in need content is deprecated. Replace with :ndf:`unknown()` instead. [needs.deprecation]",
123
137
"srcdir/index.rst:18: WARNING: Unknown function 'unknown' [needs.dynamic_function]",
0 commit comments