Skip to content

Commit be2a705

Browse files
authored
πŸš€ Release v6.0.0 (#1522)
1 parent fc765b4 commit be2a705

File tree

6 files changed

+259
-9
lines changed

6 files changed

+259
-9
lines changed

β€Ž.github/workflows/docker.yamlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
paths: ['docker/**']
1717

1818
env:
19-
NEEDS_VERSION: 5.1.0
19+
NEEDS_VERSION: 6.0.0
2020
DEPLOY_IMAGE: ${{ github.event_name != 'pull_request' }}
2121

2222
jobs:

β€Ždocs/changelog.rstβ€Ž

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,227 @@
1+
.. _ubCode: https://ubcode.useblocks.com/
2+
13
.. _changelog:
24

35
Changelog
46
=========
57

8+
6.0.0
9+
-----
10+
11+
:Released: 28.09.2025
12+
:Full Changelog: `v5.1.0...v6.0.0 <https://github.com/useblocks/sphinx-needs/compare/5.1.0...fc765b4ea6fdf79ad146cf2ce66e084178de3a9f>`__
13+
14+
This release introduces strong typing for extra option fields to the Sphinx-Needs codebase.
15+
This affects needs read from RST sources (or others like .md), but also imported/exported needs
16+
of needs.json files.
17+
18+
The default type for extra options is still ``string``, so existing configuration should work
19+
as before. Type errors are detected early once each need is fully resolved, i.e. after
20+
reading in the sources and evaluating :ref:`needs_global_options` (defaults),
21+
:ref:`needextend`, :ref:`variants <needs_variant_support>` and :ref:`dynamic_functions`.
22+
Errors in the typing system lead to needs not being created.
23+
24+
The release also introduces a new :ref:`schema_validation` system that integrates
25+
into the strong typing. It is JSON schema compliant in large parts with custom extensions
26+
to support network validation.
27+
28+
The core of Sphinx-Needs had to be refactored in large parts to enable these changes.
29+
The following are the main user-facing changes:
30+
31+
- ♻️ Allow for typed ``needs_extra_options`` fields :pr:`1516`
32+
33+
The ``needs_extra_options`` configuration option was extended to support schema information.
34+
The field ``schema.type`` globally sets the type for the field. Users can select between
35+
``string``, ``number`` (float), ``integer``, ``boolean`` and ``array``. For the ``array`` type
36+
another keyword ``schema.items.type`` defines the list items type.
37+
38+
Examples in TOML configuration:
39+
40+
.. code-block:: toml
41+
42+
[[needs.extra_options]]
43+
name = "priority"
44+
description = "Priority level, 1-5 where 1 is highest and 5 is lowest"
45+
schema.type = "integer"
46+
schema.minimum = 1
47+
schema.maximum = 5
48+
49+
[[needs.extra_options]]
50+
name = "asil"
51+
description = "Automotive Safety Integrity Level"
52+
schema.type = "string"
53+
schema.enum = ["QM", "A", "B", "C", "D"]
54+
55+
**Key Changes:**
56+
57+
- Strong typing for ``needs_extra_options`` with JSON schema validation
58+
- Delayed resolution for dynamic functions, needextend, defaults, and variants
59+
- Automatic type coercion from string inputs (directive options) to proper types
60+
- Missing fields are set to ``None`` (null in JSON)
61+
- needs.json import/export with type validation and coercion; empty ``""`` field values
62+
of existing needs.json files of type ``integer`` are coerced to ``0``, and for
63+
type ``number`` to ``0.0`` for backwards compatibility. Empty strings for ``boolean``
64+
fields are coerced to ``True`` as this is often used as a flag.
65+
- Integration with schema validation system. The same fields for :ref:`supported_data_types`
66+
can be set in the definition, so they are set globally for that field.
67+
68+
The implementation strives to be as backwards compatible as possible. See below for details.
69+
70+
- ✨ Schema validation :pr:`1467`
71+
72+
The PR adds a fast, declarative and versatile JSON schema based need validation.
73+
The schema is defined in the :ref:`needs_schema_definitions` configuration option or
74+
as JSON format passed via :ref:`needs_schema_definitions_from_json`.
75+
76+
**Key Features:**
77+
78+
- JSON Schema standard compliance using ``$defs`` and ``$ref`` for reusable sub-schemas
79+
- Fully typed implementation with runtime validation of schema definitions
80+
- Auto-injection of default string type when not specified
81+
- Select mechanism, comparable to database queries to select need nodes for validation.
82+
- Root ``validate`` key with ``local`` and ``network`` sub-sections for validation types.
83+
The split enables IDE extensions such as `ubCode`_ to validate-on-type for need-local
84+
changes and also run network validation once the index is fully built.
85+
- Debug mechanism using :ref:`needs_schema_debug_active` to check why validations pass or fail.
86+
4 files are written per validation: original need, reduced need, applied schema and
87+
a result file with user and validation message. File naming pattern is
88+
``<need_id>__<schema_path>__<validation_rule>.<json|txt>``. Nested graph-validations are also
89+
dumped.
90+
- String regex pattern constraints with cross-engine compatibility
91+
- Semantic equivalence to JSON Schema spec for array ``items``, ``minItems``, ``maxItems``,
92+
``contains``, ``minContains``, and ``maxContains``
93+
94+
The new validation can replace :ref:`needs_warnings`, :ref:`needs_constraints`,
95+
:ref:`needs_id_regex`, :ref:`needs_statuses`, and :ref:`needs_tags` in the future.
96+
97+
The implementation of the new strong typing and schema validation into `ubCode`_ is on the
98+
immediate roadmap.
99+
100+
- πŸ‘Œ Write schema violations into a JSON file :pr:`1503`
101+
102+
Schema validation violations are now exported to a JSON file (``schema_violations.json``)
103+
for external tooling integration and automated quality assurance workflows. This enables
104+
CI/CD systems and external analysis tools to programmatically process validation results.
105+
106+
- Always generate schema violations.json report file :pr:`1511`
107+
108+
**These PRs were part of the internal changes:**
109+
110+
- πŸ§ͺ Move to snapshot testing for test_schema :pr:`1519`
111+
- πŸ”§ Add ``VariantFunctionParsed`` dataclass :pr:`1515`
112+
- πŸ”§ Add ``DynamicFunctionParsed`` dataclass :pr:`1514`
113+
- ♻️ Auto-compute certain need fields :pr:`1496`
114+
- ♻️ Set some core need fields to nullable :pr:`1488`
115+
- πŸ”§ Split import item filtering to separate function :pr:`1484`
116+
- ♻️ Lazily assess directive options :pr:`1482`
117+
- πŸ§ͺ Improve test for need parts :pr:`1507`
118+
- πŸ‘Œ Improve need part processing :pr:`1469`
119+
- πŸ”§ Centralise allowed variant core need fields :pr:`1424`
120+
- ✨ Add ``is_import`` need field :pr:`1429`
121+
122+
New field to identify needs that were imported from external sources.
123+
124+
**Breaking Changes**
125+
126+
- :ref:`Variants <needs_variant_support>` have to be wrapped with ``<< >>``. This allows
127+
for a safer parsing strategy and support for usage in array elements.
128+
- The variant delimiter has changed to only allow ``,``. Formerly also ``;`` was possible.
129+
- πŸ› Fix: disallow need variants for list type fields :pr:`1489`
130+
131+
Variants no longer supported in list-type fields due to parsing instability.
132+
This feature might be re-introduced in future.
133+
The new syntax ``<< >>`` would make this much easier.
134+
135+
- ‼️ remove parsing of deprecated ``needs_global_options`` format :pr:`1517`
136+
137+
Removes support for the deprecated legacy format of
138+
``needs_global_options``. The system now only accepts the dictionary format
139+
introduced in version 5.1.0. Projects using the old format will receive a warning
140+
that the configuration is not a ``dict`` and the parsing will be skipped entirely.
141+
Users must migrate to the new explicit format for global options to continue working.
142+
143+
- ‼️ Improve needs default field application (via needs_global_options) :pr:`1478`
144+
145+
Previously defaults would be applied to any fields of a need with a "falsy" value,
146+
e.g. ``None``, ``False``, ``0``, ``""``, ``[]``. This is an issue if the user wants to
147+
specifically set fields to these values, without them being overridden by defaults.
148+
Therefore, now defaults are only applied to fields with a missing or None value.
149+
150+
- ‼️ Disallow ``add_extra_option`` overriding an internal field :pr:`1477`
151+
152+
Needs are stored in a flat dictionary as of now, so they cannot overlap.
153+
154+
- ♻️ Store needs as ``NeedItem`` / ``NeedPartItem``, rather than standard ``dict`` :pr:`1485`
155+
156+
Replaces standard dictionary storage with specialized ``NeedItem`` and ``NeedPartItem`` classes.
157+
This allows better encapsulation and control over data mutation.
158+
159+
This is breaking for any users doing "non-API" modifications or additions to the needs data,
160+
i.e. directly adding dict items.
161+
It should not change interactions with standard APIs like ``add_need`` or filter strings.
162+
163+
These PRs are also related:
164+
165+
- ♻️ Improve storage of part data on NeedItem :pr:`1509`
166+
- πŸ”§ Improve storage of content generation on ``NeedItem`` :pr:`1506`
167+
- πŸ”§ Improve storage of constraint results on ``NeedItem`` :pr:`1504`
168+
- πŸ‘Œ Capture more information about modifications on ``NeedItem`` :pr:`1502`
169+
- ♻️ split off ``source`` fields in ``NeedItem`` internal data :pr:`1491`
170+
- ♻️ split ``NeedItem`` internal data into core, extras, links and backlinks :pr:`1490`
171+
172+
- ⬆️ Drop Python 3.9 :pr:`1468`
173+
- ⬆️ Drop Sphinx<7.4, test against Python 3.13 :pr:`1447`
174+
175+
**Further improvements and fixes**
176+
177+
- πŸ”§ Improve plantuml check + add tests :pr:`1521`
178+
179+
PlantUML extension detection now uses ``app.extensions`` for better compatibility with dynamic
180+
registration. Thanks to @AlexanderLanin for the initial implementation.
181+
182+
- ♻️ Warn for missing needimport files :pr:`1510`
183+
184+
Missing :ref:`needimport` files now emit warnings instead of throwing exceptions, making
185+
it possible to ignore the problem for specific use cases.
186+
187+
- πŸ› Avoid leaking auth credentials for ext. need warnings :pr:`1512`
188+
- ♻️ Exclude ``is_need`` / ``is_part`` from ``needs.json`` output :pr:`1505`
189+
190+
It doesn't make sense to have these, since only needs are written, not parts.
191+
Also, these fields are "thrown away" when passing in external/import needs.json.
192+
193+
These fields are only really used during processing, within filter contexts, when filtering
194+
across both needs and parts.
195+
196+
- πŸ‘Œ Reset directive option specs at start of build :pr:`1448`
197+
198+
Internal fix to reset directive options for consistent builds & testing.
199+
200+
- πŸ› Warn on dynamic function with surrounding text :pr:`1426`
201+
202+
Added warning when dynamic functions are used for a list type with surrounding text
203+
as the surrounding text will be silently ignored.
204+
205+
- Allow ``collapse`` and ``hide`` in ``needs_global_options`` :pr:`1456`
206+
- πŸ”§ Allow template global_options :pr:`1454`
207+
- πŸ‘Œ Re-allow dynamic functions for ``layout`` field :pr:`1423`
208+
- πŸ”§ Allow pre/post template ``global_options`` :pr:`1428`
209+
210+
**Minor documentation updates**
211+
212+
- πŸ“š Clarify c.this_doc() for needextend :pr:`1475`
213+
- πŸ“š Fix needs_extra_links name :pr:`1501`
214+
- πŸ“š Format configuration.rst :pr:`1473`
215+
- πŸ“š Fix escape sequences :pr:`1470`
216+
217+
**Infrastructure**
218+
219+
- πŸ”§ benchmark group non win32 :pr:`1450`
220+
- πŸ› Fix cyclic imports :pr:`1443`
221+
- πŸ”§ Added yamlfmt pre-commit :pr:`1446`
222+
- πŸ”§ Use ubuntu-latest in CI :pr:`1439`
223+
- πŸ“š update tox version to py39 :pr:`1438`
224+
6225
5.1.0
7226
-----
8227

β€Ždocs/configuration.rstβ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ And use it like:
293293
}
294294
]
295295
296-
See :ref:`schema_validation` for more.
296+
The same fields for the :ref:`supported_data_types` as in the :ref:`schema_validation`
297+
are accepted. If ``schema`` is given, ``type`` is required. All the other keys can also
298+
be defined via :ref:`needs_schema_definitions` or in the file passed via
299+
:ref:`needs_schema_definitions_from_json`. If specified via ``needs_extra_options``,
300+
the constraints are applied to *all* usages of the option.
297301

298302
.. _`needs_global_options`:
299303
.. _`global_option_filters`:

β€Ždocs/schema/index.rstβ€Ž

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _ubcode: https://ubcode.useblocks.com/
1+
.. _ubCode: https://ubcode.useblocks.com/
22
.. _`schema_validation`:
33

44
Schema validation
@@ -694,6 +694,8 @@ Schema violations are also stored in a ``schema_violations.json`` file under the
694694
}
695695
}
696696
697+
.. _supported_data_types:
698+
697699
Supported Data Types
698700
--------------------
699701

@@ -717,8 +719,13 @@ String fields store textual data with optional format validation:
717719
}
718720
}
719721
720-
**Runtime Behavior**: String values are stored as Python ``str`` objects and exported
721-
as JSON strings, maintaining full Unicode support.
722+
The following schema constraints are supported for ``string`` fields:
723+
724+
- ``minLength`` / ``maxLength``: Minimum and maximum length of the string
725+
- ``pattern``: Regex pattern that the string must match
726+
- ``format``: Predefined string formats (see below)
727+
- ``enum``: Enumerated set of allowed string values
728+
- ``const``: Exact allowed string value
722729

723730
**String Formats**
724731

@@ -737,7 +744,7 @@ String fields can be validated against specific formats using the ``format`` pro
737744
}
738745
}
739746
740-
**Communication Formats**
747+
**Communication formats**
741748

742749
.. code-block:: json
743750
@@ -780,6 +787,14 @@ Integer fields store whole numbers with optional range constraints:
780787
}
781788
}
782789
790+
The following schema constraints are supported for ``integer`` fields:
791+
792+
- ``minimum`` / ``maximum``: Minimum and maximum value of the integer
793+
- ``exclusiveMinimum`` / ``exclusiveMaximum``: Exclusive minimum and maximum value
794+
- ``multipleOf``: Value must be a multiple of this integernumber
795+
- ``enum``: Enumerated set of allowed integer values
796+
- ``const``: Exact allowed integer value
797+
783798
Number Type
784799
~~~~~~~~~~~
785800

@@ -797,6 +812,13 @@ Number fields store floating-point values:
797812
}
798813
}
799814
815+
The following schema constraints are supported for ``number`` fields:
816+
817+
- ``minimum`` / ``maximum``: Minimum and maximum value of the number
818+
- ``exclusiveMinimum`` / ``exclusiveMaximum``: Exclusive minimum and maximum value
819+
- ``multipleOf``: Value must be a multiple of this number
820+
- ``enum``: Enumerated set of allowed number values
821+
- ``const``: Exact allowed number value
800822

801823
Boolean Type
802824
~~~~~~~~~~~~
@@ -849,9 +871,12 @@ Array fields store lists of homogeneous typed values:
849871
850872
**Array Properties**:
851873

852-
- ``items``: Schema for all array elements
874+
- ``items``: Schema for all array elements (required).
875+
The dictionary can contain any of the basic type schemas outlined above.
876+
The ``items.type`` field is required.
853877
- ``minItems`` / ``maxItems``: Array size constraints
854-
- ``contains`` Schema for some elements in the array
878+
- ``contains`` Schema for some elements in the array.
879+
The dictionary can contain any of the basic type schemas outlined above.
855880
- ``minContains`` / ``maxContains``: Constraints on number of elements matching ``contains``;
856881

857882
- If ``minContains`` is not given, it defaults to 1 when ``contains`` is present.

β€Žsphinx_needs/__init__.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Sphinx needs extension for managing needs/requirements and specifications"""
22

3-
__version__ = "5.1.0"
3+
__version__ = "6.0.0"
44

55

66
def setup(app): # type: ignore[no-untyped-def]

β€Žsphinx_needs/schema/config.pyβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040

4141
class ExtraOptionStringSchemaType(TypedDict):
42+
"""String extra option schema."""
43+
4244
type: Literal["string"]
4345
"""Extra option string type."""
4446
minLength: NotRequired[int]

0 commit comments

Comments
Β (0)