Skip to content

Commit f7e2410

Browse files
🔧 Centralise allowed variant core need fields (#1424)
Similar to #1388 for `needs_variant_options` --------- Co-authored-by: Marco Heinemann <[email protected]>
1 parent a60d397 commit f7e2410

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

‎docs/configuration.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,8 +2249,14 @@ Default: ``[]``
22492249

22502250
.. note::
22512251

2252-
1. You must ensure the options in ``needs_variant_options`` are either default need options or specified in
2253-
:ref:`extra options <needs_extra_options>` or :ref:`extra links <needs_extra_links>`.
2252+
1. You must ensure the options in ``needs_variant_options`` are specified in:
2253+
- ``status``
2254+
- ``tags``
2255+
- ``layout``
2256+
- ``style``
2257+
- ``constraints``
2258+
- :ref:`extra options <needs_extra_options>`
2259+
- :ref:`extra links <needs_extra_links>`.
22542260
2. By default, if ``needs_variant_options`` is empty, we deactivate variants handling for need options.
22552261

22562262
.. _needs_render_context:

‎sphinx_needs/data.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class CoreFieldParameters(TypedDict):
6868
"""Whether field can be modified by needextend (False if not present)."""
6969
allow_df: NotRequired[bool]
7070
"""Whether dynamic functions are allowed for this field (False if not present)."""
71+
allow_variants: NotRequired[bool]
72+
"""Whether variant options are allowed for this field (False if not present)."""
7173
deprecate_df: NotRequired[bool]
7274
"""Whether dynamic functions are deprecated for this field (False if not present)."""
7375
show_in_layout: NotRequired[bool]
@@ -112,6 +114,7 @@ class CoreFieldParameters(TypedDict):
112114
"show_in_layout": True,
113115
"allow_default": "str",
114116
"allow_df": True,
117+
"allow_variants": True,
115118
"allow_extend": True,
116119
},
117120
"tags": {
@@ -120,6 +123,7 @@ class CoreFieldParameters(TypedDict):
120123
"show_in_layout": True,
121124
"allow_default": "str_list",
122125
"allow_df": True,
126+
"allow_variants": True,
123127
"allow_extend": True,
124128
},
125129
"collapse": {
@@ -142,6 +146,7 @@ class CoreFieldParameters(TypedDict):
142146
"show_in_layout": True,
143147
"allow_default": "str",
144148
"allow_df": True,
149+
"allow_variants": True,
145150
"exclude_external": True,
146151
},
147152
"style": {
@@ -151,6 +156,7 @@ class CoreFieldParameters(TypedDict):
151156
"exclude_external": True,
152157
"allow_default": "str",
153158
"allow_df": True,
159+
"allow_variants": True,
154160
"allow_extend": True,
155161
},
156162
"arch": {
@@ -313,6 +319,7 @@ class CoreFieldParameters(TypedDict):
313319
"schema": {"type": "array", "items": {"type": "string"}, "default": []},
314320
"allow_default": "str_list",
315321
"allow_df": True,
322+
"allow_variants": True,
316323
"allow_extend": True,
317324
},
318325
"constraints_results": {

‎sphinx_needs/needs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,12 +720,15 @@ def check_configuration(app: Sphinx, config: Config) -> None:
720720
f"Variant filter value: {value} from needs_variants {external_variants} is not a string."
721721
)
722722

723+
allowed_internal_variants = {
724+
k for k, v in NeedsCoreFields.items() if v.get("allow_variants")
725+
}
723726
for option in external_variant_options:
724727
# Check variant option is added in either extra options or extra links or NEED_DEFAULT_OPTIONS
725728
if (
726729
option not in extra_options
727730
and option not in link_types
728-
and option not in NEED_DEFAULT_OPTIONS
731+
and option not in allowed_internal_variants
729732
):
730733
raise NeedsConfigException(
731734
f"Variant option `{option}` is not added in either extra options or extra links. "

0 commit comments

Comments
 (0)