From 21d810e406c7628dc9ad86faec3afc9646e557b6 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Sun, 26 Jan 2025 15:05:45 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A7=20Centralise=20extendable=20co?= =?UTF-8?q?re=20need=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sphinx_needs/data.py | 9 +++++++++ sphinx_needs/defaults.py | 2 -- sphinx_needs/needs.py | 32 +++++++++++++++++++------------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/sphinx_needs/data.py b/sphinx_needs/data.py index 2cbc74d92..be7e7871d 100644 --- a/sphinx_needs/data.py +++ b/sphinx_needs/data.py @@ -60,6 +60,8 @@ class CoreFieldParameters(TypedDict): """Description of the field.""" schema: dict[str, Any] """JSON schema for the field.""" + allow_extend: NotRequired[bool] + """Whether field can be modified by needextend (False if not present).""" show_in_layout: NotRequired[bool] """Whether to show the field in the rendered layout of the need by default (False if not present).""" exclude_external: NotRequired[bool] @@ -103,23 +105,27 @@ class CoreFieldParameters(TypedDict): "description": "Status of the need.", "schema": {"type": ["string", "null"], "default": None}, "show_in_layout": True, + "allow_extend": True, }, "tags": { "description": "List of tags.", "schema": {"type": "array", "items": {"type": "string"}, "default": []}, "show_in_layout": True, + "allow_extend": True, }, "collapse": { "description": "Hide the meta-data information of the need.", "schema": {"type": "boolean", "default": False}, "exclude_json": True, "exclude_external": True, + "allow_extend": True, }, "hide": { "description": "If true, the need is not rendered.", "schema": {"type": "boolean", "default": False}, "exclude_json": True, "exclude_external": True, + "allow_extend": True, }, "delete": { "description": "If true, the need is deleted entirely.", @@ -132,12 +138,14 @@ class CoreFieldParameters(TypedDict): "schema": {"type": ["string", "null"], "default": None}, "show_in_layout": True, "exclude_external": True, + "allow_extend": True, }, "style": { "description": "Comma-separated list of CSS classes (all appended by `needs_style_`).", "schema": {"type": ["string", "null"], "default": None}, "show_in_layout": True, "exclude_external": True, + "allow_extend": True, }, "arch": { "description": "Mapping of uml key to uml content.", @@ -292,6 +300,7 @@ class CoreFieldParameters(TypedDict): "constraints": { "description": "List of constraint names, which are defined for this need.", "schema": {"type": "array", "items": {"type": "string"}, "default": []}, + "allow_extend": True, }, "constraints_results": { "description": "Mapping of constraint name, to check name, to result.", diff --git a/sphinx_needs/defaults.py b/sphinx_needs/defaults.py index b477af838..0f758a2bc 100644 --- a/sphinx_needs/defaults.py +++ b/sphinx_needs/defaults.py @@ -273,6 +273,4 @@ def string_to_boolean(argument: str | None) -> bool | None: "constraints_results": directives.unchanged_required, } -NEEDEXTEND_NOT_ALLOWED_OPTIONS = ["id"] - NEEDS_PROFILING = [x.upper() for x in os.environ.get("NEEDS_PROFILING", "").split(",")] diff --git a/sphinx_needs/needs.py b/sphinx_needs/needs.py index 17a8cc7a5..86a33eea4 100644 --- a/sphinx_needs/needs.py +++ b/sphinx_needs/needs.py @@ -33,7 +33,6 @@ GRAPHVIZ_STYLE_DEFAULTS, LAYOUTS, NEED_DEFAULT_OPTIONS, - NEEDEXTEND_NOT_ALLOWED_OPTIONS, NEEDFLOW_CONFIG_DEFAULTS, ) from sphinx_needs.directives.list2need import List2Need, List2NeedDirective @@ -480,18 +479,16 @@ def load_config(app: Sphinx, *_args: Any) -> None: NeedserviceDirective.option_spec.update(extra_links) # Update NeedextendDirective with option modifiers. - for key, value in NEED_DEFAULT_OPTIONS.items(): - # Ignore options like "id" - if key in NEEDEXTEND_NOT_ALLOWED_OPTIONS: - continue - - NeedextendDirective.option_spec.update( - { - key: value, - f"+{key}": value, - f"-{key}": directives.flag, - } - ) + for key, _options in NeedsCoreFields.items(): + if _options.get("allow_extend"): + value = NEED_DEFAULT_OPTIONS[key] + NeedextendDirective.option_spec.update( + { + key: value, + f"+{key}": value, # TODO this doesn't make sense for non- str/list[str] fields + f"-{key}": directives.flag, + } + ) for key, value in extra_links.items(): NeedextendDirective.option_spec.update( @@ -502,6 +499,15 @@ def load_config(app: Sphinx, *_args: Any) -> None: } ) + # "links" is not part of the extra_links + NeedextendDirective.option_spec.update( + { + "links": NEED_DEFAULT_OPTIONS["links"], + "+links": NEED_DEFAULT_OPTIONS["links"], + "-links": directives.flag, + } + ) + for key, value in _NEEDS_CONFIG.extra_options.items(): NeedextendDirective.option_spec.update( { From 33d1742b90f7973544316321380cc81195fcea08 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Mon, 27 Jan 2025 10:09:40 +0100 Subject: [PATCH 2/2] Update sphinx_needs/data.py --- sphinx_needs/data.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sphinx_needs/data.py b/sphinx_needs/data.py index be7e7871d..7164048d0 100644 --- a/sphinx_needs/data.py +++ b/sphinx_needs/data.py @@ -138,7 +138,6 @@ class CoreFieldParameters(TypedDict): "schema": {"type": ["string", "null"], "default": None}, "show_in_layout": True, "exclude_external": True, - "allow_extend": True, }, "style": { "description": "Comma-separated list of CSS classes (all appended by `needs_style_`).",