Skip to content

Commit 947e58f

Browse files
cpolzer~chrstian polzerChristian Polzer
authored
🔧 Add sphinx-needs 8.0.0 compatibility (#133)
* 🔧 Add sphinx-needs 8.0.0 compatibility Replace deprecated add_extra_option() with add_field() for sphinx-needs >= 8.0.0, using a version-gated shim that falls back to add_extra_option() for older versions. Also adds sphinx-needs 8.0.0 to the CI and nox test matrices, fixes the warning check in tests to also inspect stderr (where Sphinx writes warnings), adds a test asserting the test-file need node renders correctly, and removes the broken taplo pre-commit hook (taplo 0.9.3 PyPI package fails to build on this platform). * 🔧 Restore taplo pre-commit hook * 🔧 Fix remaining sphinx-needs 8.0.0 warnings Add schema to string fields in _register_field (moved into use_schema branch for backwards compat with sphinx-needs < 6.0.0). Update all test fixture conf.py files to use needs_fields for sphinx-needs >= 8.0.0 instead of the deprecated needs_extra_options. * 🔧 Fix ruff linting errors in conf.py files Move sphinx_needs and Version imports to top of file (fixes E402) and drop incorrect _V alias for Version (fixes N814). * docs_build: handling update to sphinx-needs shimed * 🔧 Add proper field descriptions for sphinx-needs API * 🔧 Add explicit packaging dependency * 🔧 Enhance test to verify integer count fields are rendered * 🔧 Fix warning check logic in test * fix: Replace broken sphinx-needs.com links with ReadTheDocs --------- Co-authored-by: ~chrstian polzer <~c.polzer@hai-fai.de> Co-authored-by: Christian Polzer <Christian.Polzer@gmail.com>
1 parent 529246a commit 947e58f

15 files changed

Lines changed: 203 additions & 53 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
os: [ubuntu-latest]
1010
python-version: ["3.10", "3.12"] # No "3.10", as nose seem to have problems with it
1111
sphinx-version: ["5.0", "8.1.3"]
12-
sphinx_needs-version: ["2.1", "4.2", "5.1", "6.3.0"]
12+
sphinx_needs-version: ["2.1", "4.2", "5.1", "6.3.0", "8.0.0"]
1313
steps:
1414
- uses: actions/checkout@v2
1515
- name: Set Up Python ${{ matrix.python-version }}

‎docs/changelog.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ introduces several maintenance improvements.
107107
-----
108108
:Released: 26.09.2022
109109

110-
* Improvement: Supporting `Sphinx-Needs <https://www.sphinx-needs.com/>`__ ``>= 1.01`` only.
110+
* Improvement: Supporting `Sphinx-Needs <https://sphinx-needs.readthedocs.io/en/latest/>`__ ``>= 1.01`` only.
111111
* Improvement: Migrated nosetests to pytest.
112112

113113
0.3.7

‎docs/conf.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# import os
1818
import sys
1919

20+
import sphinx_needs
21+
from packaging.version import Version
22+
2023
sys.path.append(os.path.abspath("."))
2124

2225
from ub_theme.conf import html_theme_options
@@ -67,7 +70,13 @@
6770

6871
# Add any paths that contain templates here, relative to this directory.
6972
templates_path = ["_templates", "ub_theme/templates"]
70-
needs_extra_options = ["more_info"]
73+
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
74+
needs_fields = {
75+
"more_info": {"nullable": True},
76+
}
77+
else:
78+
needs_extra_options = ["more_info"]
79+
7180
tr_extra_options = ["more_info"]
7281
# Add a custom test report template. Please add a relative path from this conf.py
7382
# tr_report_template = "./custom_test_report_template.txt"

‎docs/index.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ In the last years, we have created additional information and extensions, which
9292

9393
.. grid-item-card::
9494
:columns: 12 6 6 6
95-
:link: https://sphinx-needs.com
95+
:link: https://sphinx-needs.readthedocs.io/en/latest/
9696
:img-top: /_static/sphinx-needs-card.png
9797
:class-card: border
9898

@@ -103,7 +103,7 @@ In the last years, we have created additional information and extensions, which
103103
Also, it is a good entry point to understand the benefits and get an idea about the complete ecosystem of Sphinx-Needs.
104104
+++
105105

106-
.. button-link:: https://sphinx-needs.com
106+
.. button-link:: https://sphinx-needs.readthedocs.io/en/latest/
107107
:color: primary
108108
:outline:
109109
:align: center

‎noxfile.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
PYTHON_VERSIONS = ["3.10", "3.12"]
55
SPHINX_VERSIONS = ["5.0", "7.2.5", "8.1.3"]
6-
SPHINX_NEEDS_VERSIONS = ["2.1", "4.2", "5.1", "6.0.0", "6.3.0"]
6+
SPHINX_NEEDS_VERSIONS = ["2.1", "4.2", "5.1", "6.0.0", "6.3.0", "8.0.0"]
77

88

99
def run_tests(session, sphinx, sphinx_needs):

‎pyproject.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ classifiers = [
2525
]
2626
keywords = ["sphinx", "documentation", "test-reports"]
2727
requires-python = ">=3.10"
28-
dependencies = ["sphinx>4.0", "lxml", "sphinx-needs>=1.0.1"]
28+
dependencies = ["sphinx>4.0", "lxml", "sphinx-needs>=1.0.1", "packaging>=20.0"]
2929

3030
[project.optional-dependencies]
3131
test = [
32+
"beautifulsoup4",
3233
"nox>=2025.2.9",
3334
"pytest-xdist",
3435
"pytest>=7.0",

‎sphinxcontrib/test_reports/test_reports.py‎

Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# fmt: off
2+
import inspect
23
import os
34

45
import sphinx
@@ -9,7 +10,7 @@
910
from sphinx.config import Config
1011

1112
# from docutils import nodes
12-
from sphinx_needs.api import add_dynamic_function, add_extra_option, add_need_type
13+
from sphinx_needs.api import add_dynamic_function, add_need_type
1314

1415
from sphinxcontrib.test_reports.directives.test_case import TestCase, TestCaseDirective
1516
from sphinxcontrib.test_reports.directives.test_env import EnvReport, EnvReportDirective
@@ -39,6 +40,46 @@
3940

4041
VERSION = "1.3.2"
4142

43+
# Field descriptions for better semantics
44+
FIELD_DESCRIPTIONS = {
45+
"file": "Test file name",
46+
"suite": "Test suite name",
47+
"case": "Test case name",
48+
"case_name": "Test case display name",
49+
"case_parameter": "Test case parameter",
50+
"classname": "Test class name",
51+
"time": "Test execution time",
52+
"suites": "Number of test suites",
53+
"cases": "Number of test cases",
54+
"passed": "Number of passed tests",
55+
"skipped": "Number of skipped tests",
56+
"failed": "Number of failed tests",
57+
"errors": "Number of test errors",
58+
"result": "Test result status",
59+
}
60+
61+
try:
62+
from sphinx_needs.api import add_field as _add_field
63+
64+
def _register_field(app, name, schema=None):
65+
description = FIELD_DESCRIPTIONS.get(name, name)
66+
_add_field(name, description, schema=schema)
67+
68+
except ImportError:
69+
from sphinx_needs.api import add_extra_option as _add_extra_option
70+
71+
_add_extra_option_supports_description = (
72+
"description" in inspect.signature(_add_extra_option).parameters
73+
)
74+
75+
def _register_field(app, name, schema=None):
76+
kwargs = {}
77+
if _add_extra_option_supports_description:
78+
kwargs["description"] = FIELD_DESCRIPTIONS.get(name, name)
79+
if schema is not None:
80+
kwargs["schema"] = schema
81+
_add_extra_option(app, name, **kwargs)
82+
4283

4384
def setup(app: Sphinx):
4485
"""
@@ -177,44 +218,41 @@ def sphinx_needs_update(app: Sphinx, config: Config) -> None:
177218
sphinx-needs configuration
178219
"""
179220

180-
# Check sphinx-needs version to determine if schema is needed
181-
try:
182-
needs_version = Version(sphinx_needs.__version__)
183-
use_schema = needs_version >= Version("6.0.0")
184-
except ImportError:
185-
# If we can't determine version, assume older version
186-
use_schema = False
187-
188-
# Extra options
189-
# For details read
190-
# https://sphinx-needs.readthedocs.io/en/latest/api.html#sphinx_needs.api.configuration.add_extra_option
191-
192-
add_extra_option(app, getattr(config, "tr_file_option", "file"))
193-
194-
add_extra_option(app, "suite")
195-
add_extra_option(app, "case")
196-
add_extra_option(app, "case_name")
197-
add_extra_option(app, "case_parameter")
198-
add_extra_option(app, "classname")
199-
# Add schema parameter conditionally based on sphinx-needs version
221+
needs_version = Version(sphinx_needs.__version__)
222+
use_schema = needs_version >= Version("6.0.0")
223+
200224
if use_schema:
201-
add_extra_option(app, "time", schema={"type": "string"})
202-
add_extra_option(app, "suites", schema={"type": "integer"})
203-
add_extra_option(app, "cases", schema={"type": "integer"})
204-
add_extra_option(app, "passed", schema={"type": "integer"})
205-
add_extra_option(app, "skipped", schema={"type": "integer"})
206-
add_extra_option(app, "failed", schema={"type": "integer"})
207-
add_extra_option(app, "errors", schema={"type": "integer"})
208-
add_extra_option(app, "result", schema={"type": "string"})
225+
_register_field(
226+
app, getattr(config, "tr_file_option", "file"), schema={"type": "string"}
227+
)
228+
_register_field(app, "suite", schema={"type": "string"})
229+
_register_field(app, "case", schema={"type": "string"})
230+
_register_field(app, "case_name", schema={"type": "string"})
231+
_register_field(app, "case_parameter", schema={"type": "string"})
232+
_register_field(app, "classname", schema={"type": "string"})
233+
_register_field(app, "time", schema={"type": "string"})
234+
_register_field(app, "suites", schema={"type": "integer"})
235+
_register_field(app, "cases", schema={"type": "integer"})
236+
_register_field(app, "passed", schema={"type": "integer"})
237+
_register_field(app, "skipped", schema={"type": "integer"})
238+
_register_field(app, "failed", schema={"type": "integer"})
239+
_register_field(app, "errors", schema={"type": "integer"})
240+
_register_field(app, "result", schema={"type": "string"})
209241
else:
210-
add_extra_option(app, "time")
211-
add_extra_option(app, "suites")
212-
add_extra_option(app, "cases")
213-
add_extra_option(app, "passed")
214-
add_extra_option(app, "skipped")
215-
add_extra_option(app, "failed")
216-
add_extra_option(app, "errors")
217-
add_extra_option(app, "result")
242+
_register_field(app, getattr(config, "tr_file_option", "file"))
243+
_register_field(app, "suite")
244+
_register_field(app, "case")
245+
_register_field(app, "case_name")
246+
_register_field(app, "case_parameter")
247+
_register_field(app, "classname")
248+
_register_field(app, "time")
249+
_register_field(app, "suites")
250+
_register_field(app, "cases")
251+
_register_field(app, "passed")
252+
_register_field(app, "skipped")
253+
_register_field(app, "failed")
254+
_register_field(app, "errors")
255+
_register_field(app, "result")
218256
# Extra dynamic functions
219257
# For details about usage read
220258
# https://sphinx-needs.readthedocs.io/en/latest/api.html#sphinx_needs.api.configuration.add_dynamic_function

‎tests/doc_test/basic_doc/conf.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import os
1919
import sys
2020

21+
import sphinx_needs
22+
from packaging.version import Version
23+
2124
sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))
2225

2326
# -- General configuration ------------------------------------------------
@@ -69,7 +72,10 @@
6972
# directories to ignore when looking for source files.
7073
# This patterns also effect to html_static_path and html_extra_path
7174
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
72-
needs_extra_options = ["more_info"]
75+
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
76+
needs_fields = {"more_info": {"nullable": True}}
77+
else:
78+
needs_extra_options = ["more_info"]
7379
tr_extra_options = ["more_info"]
7480

7581
# The name of the Pygments (syntax highlighting) style to use.

‎tests/doc_test/doc_test_ctest_file/conf.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import os
1919
import sys
2020

21+
import sphinx_needs
22+
from packaging.version import Version
23+
2124
sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))
2225

2326
# -- General configuration ------------------------------------------------
@@ -75,7 +78,14 @@
7578
# The master toctree document.
7679
master_doc = "index"
7780

78-
needs_extra_options = ["asil", "uses_secure", "more_info"]
81+
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
82+
needs_fields = {
83+
"asil": {"nullable": True},
84+
"uses_secure": {"nullable": True},
85+
"more_info": {"nullable": True},
86+
}
87+
else:
88+
needs_extra_options = ["asil", "uses_secure", "more_info"]
7989
tr_extra_options = ["more_info"]
8090

8191
# General information about the project.

‎tests/doc_test/doc_test_file/conf.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import os
1919
import sys
2020

21+
import sphinx_needs
22+
from packaging.version import Version
23+
2124
sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))
2225

2326
# -- General configuration ------------------------------------------------
@@ -75,7 +78,14 @@
7578
# The master toctree document.
7679
master_doc = "index"
7780

78-
needs_extra_options = ["asil", "uses_secure", "more_info"]
81+
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
82+
needs_fields = {
83+
"asil": {"nullable": True},
84+
"uses_secure": {"nullable": True},
85+
"more_info": {"nullable": True},
86+
}
87+
else:
88+
needs_extra_options = ["asil", "uses_secure", "more_info"]
7989
tr_extra_options = ["more_info"]
8090

8191
# General information about the project.

0 commit comments

Comments
 (0)