Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Centralise extendable core need fields #1388

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sphinx_needs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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.",
Expand All @@ -138,6 +144,7 @@ class CoreFieldParameters(TypedDict):
"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.",
Expand Down Expand Up @@ -292,6 +299,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.",
Expand Down
2 changes: 0 additions & 2 deletions sphinx_needs/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")]
32 changes: 19 additions & 13 deletions sphinx_needs/needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
{
Expand Down
Loading