Skip to content
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
2 changes: 1 addition & 1 deletion docs/_static/tutorial_needs.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions docs/ubproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ parse_variants = true

[needs.fields.my_extra_option]
description = "Custom extra option"
nullable = true

[needs.fields.another_option]
description = "Another custom option"
default = ""

[needs.fields.author]
description = "Author of the need"
nullable = true

[needs.fields.comment]
description = "Additional comments"
nullable = true

[needs.fields.amount]
description = "Amount value"
Expand All @@ -92,18 +96,23 @@ schema.type = "integer"

[needs.fields.image]
description = "Image reference"
nullable = true

[needs.fields.config]
description = "Configuration option"
nullable = true

[needs.fields.github]
description = "GitHub reference"
nullable = true

[needs.fields.value]
description = "General value field"
nullable = true

[needs.fields.unit]
description = "Unit specification"
nullable = true

[[needs.types]]
directive = "int"
Expand Down
24 changes: 22 additions & 2 deletions sphinx_needs/needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,14 +909,34 @@ def create_schema(app: Sphinx, env: BuildEnvironment, _docnames: list[str]) -> N

for name, field_data in _NEEDS_CONFIG.fields.items():
try:
back_compatible = field_data.source in {
"needs_extra_options",
"add_extra_option",
}
if (
not back_compatible
and field_data.schema is None
and field_data.default is None
and field_data.nullable is None
):
log_warning(
LOGGER,
f"Field {name!r} (from {field_data.source}) has no 'schema', 'nullable' or 'default' defined, "
"which defaults to a string schema with nullable=True and no default. "
"To aide with backward compatibility please define at least one.",
"config",
None,
)

_schema = (
deepcopy(field_data.schema) # type: ignore[arg-type]
if field_data.schema is not None
else {"type": "string"}
)
nullable = True
if field_data.nullable is not None:
nullable = field_data.nullable
else:
elif back_compatible:
# follows that of legacy (pre-schema) extra option,
# i.e. nullable if schema is defined
nullable = field_data.schema is not None
Expand All @@ -936,7 +956,7 @@ def create_schema(app: Sphinx, env: BuildEnvironment, _docnames: list[str]) -> N
# note, default follows that of legacy (pre-schema) extra option,
# i.e. default to "" only if no schema is defined
default=None
if field_data.schema is not None
if not back_compatible or field_data.schema is not None
else FieldLiteralValue(""),
allow_defaults=True,
allow_extend=True,
Expand Down
5 changes: 4 additions & 1 deletion tests/__snapshots__/test_api_usage.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@
'default': 'hallo',
'description': 'My extra field',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'params': dict({
'default': None,
Expand Down
7 changes: 5 additions & 2 deletions tests/__snapshots__/test_dynamic_functions.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,13 @@
]),
}),
'test_func': dict({
'default': '',
'default': None,
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'title': dict({
'description': 'Title of the need.',
Expand Down
14 changes: 10 additions & 4 deletions tests/__snapshots__/test_external.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -767,16 +767,22 @@
]),
}),
'extra1': dict({
'default': '',
'default': None,
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'extra2': dict({
'default': '',
'default': None,
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'has_dead_links': dict({
'default': False,
Expand Down
21 changes: 15 additions & 6 deletions tests/__snapshots__/test_extra_options.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,22 @@
]),
}),
'impacts': dict({
'default': '',
'default': None,
'description': 'What is the impact of this need?',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'introduced': dict({
'default': '',
'default': None,
'description': 'When was this need introduced?',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'is_external': dict({
'default': False,
Expand Down Expand Up @@ -312,10 +318,13 @@
'type': 'integer',
}),
'modified': dict({
'default': '',
'default': None,
'description': 'When was this need last modified?',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'params': dict({
'default': None,
Expand Down
48 changes: 35 additions & 13 deletions tests/__snapshots__/test_field_defaults.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@
]),
}),
'bad_value_type': dict({
'default': '',
'default': None,
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'closed_at': dict({
'default': None,
Expand Down Expand Up @@ -457,30 +460,46 @@
'default': 'test_global',
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'option_2': dict({
'default': None,
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'option_3': dict({
'default': '',
'default': None,
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'option_4': dict({
'default': 'STATUS_UNKNOWN',
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'option_5': dict({
'default': 'final',
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'params': dict({
'default': None,
Expand Down Expand Up @@ -673,10 +692,13 @@
'type': 'string',
}),
'too_many_params': dict({
'default': '',
'default': None,
'description': 'Added by needs_fields config',
'field_type': 'extra',
'type': 'string',
'type': list([
'string',
'null',
]),
}),
'type': dict({
'default': '',
Expand Down Expand Up @@ -741,7 +763,7 @@
),
}),
'bad_value_type': dict({
'default': FieldLiteralValue(value=''),
'default': None,
'predicate_defaults': tuple(
),
}),
Expand Down Expand Up @@ -839,7 +861,7 @@
),
}),
'option_3': dict({
'default': FieldLiteralValue(value=''),
'default': None,
'predicate_defaults': tuple(
tuple(
'status == "implemented"',
Expand Down Expand Up @@ -943,7 +965,7 @@
),
}),
'too_many_params': dict({
'default': FieldLiteralValue(value=''),
'default': None,
'predicate_defaults': tuple(
),
}),
Expand Down
6 changes: 3 additions & 3 deletions tests/doc_test/add_sections_sigs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
needs_json_remove_defaults = True

needs_fields = {
"introduced": {},
"updated": {},
"impacts": {},
"introduced": {"nullable": True},
"updated": {"nullable": True},
"impacts": {"nullable": True},
}

needs_template_collapse = """
Expand Down
2 changes: 1 addition & 1 deletion tests/doc_test/doc_df_check_linked_values/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
},
]

needs_fields = {"test_func": {}, "hours": {}}
needs_fields = {"test_func": {"nullable": True}, "hours": {"nullable": True}}
2 changes: 1 addition & 1 deletion tests/doc_test/doc_df_user_functions/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
]

needs_fields = {"test_func": {}, "hours": {}}
needs_fields = {"test_func": {"nullable": True}, "hours": {"nullable": True}}


def my_own_function(app, need, needs):
Expand Down
2 changes: 1 addition & 1 deletion tests/doc_test/doc_dynamic_functions/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
]

needs_fields = {"test_func": {}}
needs_fields = {"test_func": {"nullable": True}}

needs_build_json = True
needs_json_remove_defaults = True
7 changes: 5 additions & 2 deletions tests/doc_test/doc_field_defaults/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
"layout": {"default": "clean_l"},
"option_1": {"default": "test_global"},
"option_2": {"default": "[[copy('id')]]"},
"option_3": {"predicates": [('status == "implemented"', "STATUS_IMPL")]},
"option_3": {
"nullable": True,
"predicates": [('status == "implemented"', "STATUS_IMPL")],
},
"option_4": {
"default": "STATUS_UNKNOWN",
"predicates": [('status == "closed"', "STATUS_CLOSED")],
Expand All @@ -59,7 +62,7 @@
"default": "final",
},
"bad_value_type": {"default": 1.27},
"too_many_params": {"predicates": [("a", "b", "c", "d")]},
"too_many_params": {"nullable": True, "predicates": [("a", "b", "c", "d")]},
}

needs_build_json = True
Expand Down
14 changes: 7 additions & 7 deletions tests/doc_test/doc_global_options/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
]

needs_fields = {
"option_1": {},
"option_2": {},
"option_3": {},
"option_4": {},
"option_5": {},
"bad_value_type": {},
"too_many_params": {},
"option_1": {"nullable": True},
"option_2": {"nullable": True},
"option_3": {"nullable": True},
"option_4": {"nullable": True},
"option_5": {"nullable": True},
"bad_value_type": {"nullable": True},
"too_many_params": {"nullable": True},
}

needs_global_options = {
Expand Down
2 changes: 1 addition & 1 deletion tests/doc_test/doc_layout/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
]

needs_fields = {"author": {}, "author_image": {}}
needs_fields = {"author": {"nullable": True}, "author_image": {"nullable": True}}


needs_layouts = {
Expand Down
2 changes: 1 addition & 1 deletion tests/doc_test/doc_needpie/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
},
]

needs_fields = {"author": {}}
needs_fields = {"author": {"nullable": True}}
2 changes: 1 addition & 1 deletion tests/doc_test/doc_needreport/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extensions = ["sphinx_needs"]
needs_fields = {"other": {}}
needs_fields = {"other": {"nullable": True}}
needs_render_context = {
"report_directive": "admonition",
}
Loading