-
Notifications
You must be signed in to change notification settings - Fork 71
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
✨ NEW: Add NeedsLookUpTableBuilder
#961
base: master
Are you sure you want to change the base?
Changes from 42 commits
bdc4d77
37deab7
4095a0d
b144bc3
0af5175
c9a10fd
db592c0
99dc2dd
9452708
9d6badf
adfc885
02e65be
5199edc
d4e4f04
390dd36
7177c03
61dcbef
98030a8
25d42f0
994b6b1
4f5d185
78aedd7
e86bb39
3a0f270
c6f0c2d
4babb2d
4cec93b
09b14ca
0230f3d
271f6a6
036c723
d3e0f90
e144909
d229036
4ead31a
c6723ea
d0e7849
2faeec3
3d32679
de90ff2
569d5a6
830c12a
a93f75f
ff74834
b69da59
27bd083
c77162c
5fdcd3c
fd1f612
6649155
c3bb82c
0a20d81
4472aed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,3 +163,53 @@ or | |
.. hint:: | ||
|
||
As an alternative, you can set the config option :ref:`needs_build_needumls` to export the needumls files during each build. | ||
|
||
.. _needs_lut_builder: | ||
|
||
needs_lut | ||
--------- | ||
.. versionadded:: 1.4.0 | ||
|
||
The **needs_lut** builder exports all found needs to a single json file, which only include list of key ``id`` and value of ``docname`` or ``external_url``. | ||
|
||
The build creates file called **needs_lut.json** inside the given build-folder. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .. a file called |
||
Usage | ||
+++++ | ||
|
||
.. code-block:: bash | ||
|
||
sphinx-build -b needs_lut source_dir build_dir | ||
|
||
Format | ||
++++++ | ||
|
||
.. code-block:: python | ||
|
||
{ | ||
"extend_test_001": "directives/needextend", | ||
"extend_test_002": "directives/needextend", | ||
|
||
"req_arch_001": "directives/needarch", | ||
"req_arch_004": "directives/needarch", | ||
|
||
"spec_arch_001": "directives/needarch", | ||
"test_arch_001": "directives/needarch", | ||
"COMP_T_001": "directives/needarch", | ||
"COMP_T_002": "directives/needarch", | ||
|
||
"EX_REQ_1": "examples/index", | ||
"EX_REQ_2": "examples/index", | ||
|
||
"R_F4722": "examples/index", | ||
"OWN_ID_123": "examples/index", | ||
"IMPL_01": "examples/index", | ||
"T_C3893": "examples/index", | ||
"R_2A9D0": "filter", | ||
"R_22EB2": "filter", | ||
"S_D70B0": "filter", | ||
"S_01A67": "filter", | ||
"T_5CCAA": "filter", | ||
"R_17EB4": "filter", | ||
"req_flow_001": "directives/needflow", | ||
"spec_flow_001": "directives/needflow", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import json | ||
import os | ||
from typing import Iterable, Optional, Set | ||
|
||
|
@@ -157,3 +158,66 @@ def build_needumls_pumls(app: Sphinx, _exception: Exception) -> None: | |
needs_builder.set_environment(env) | ||
|
||
needs_builder.finish() | ||
|
||
|
||
class NeedsLookUpTableBuilder(Builder): | ||
danwos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name = "needs_lut" | ||
format = "needs" | ||
file_suffix = ".txt" | ||
links_suffix = None | ||
|
||
def write_doc(self, docname: str, doctree: nodes.document) -> None: | ||
pass | ||
|
||
def finish(self) -> None: | ||
env = unwrap(self.env) | ||
needs = env.needs_all_needs.values() | ||
needs_dict = {} | ||
for need in needs: | ||
if need["is_external"]: | ||
needs_dict[need["id"]] = need["external_url"] | ||
else: | ||
needs_dict[need["id"]] = need["docname"] | ||
|
||
try: | ||
fname = os.path.join(self.outdir, "needs_lut.json") | ||
with open(fname, "w", encoding="utf-8") as f: | ||
json.dump(needs_dict, f, indent=4) | ||
except Exception as e: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add this part (dict creation + json.dump) also to NeedsList as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should stay with |
||
log.error(f"Error during writing json file: {e}") | ||
else: | ||
log.info("Needs lookup table json successfully created") | ||
|
||
def get_outdated_docs(self) -> Iterable[str]: | ||
return [] | ||
|
||
def prepare_writing(self, _docnames: Set[str]) -> None: | ||
pass | ||
|
||
def write_doc_serialized(self, _docname: str, _doctree: nodes.document) -> None: | ||
pass | ||
|
||
def cleanup(self) -> None: | ||
pass | ||
|
||
def get_target_uri(self, _docname: str, _typ: Optional[str] = None) -> str: | ||
return "" | ||
|
||
|
||
def build_needs_look_up_json(app: Sphinx, _exception: Exception) -> None: | ||
env = unwrap(app.env) | ||
|
||
if not env.config.needs_lut_build_json: | ||
return | ||
|
||
# Do not create an additional look up table json, if builder is already in use. | ||
if isinstance(app.builder, NeedsLookUpTableBuilder): | ||
return | ||
|
||
try: | ||
needs_lut_builder = NeedsLookUpTableBuilder(app, env) | ||
except TypeError: | ||
needs_lut_builder = NeedsLookUpTableBuilder(app) | ||
needs_lut_builder.set_environment(env) | ||
|
||
needs_lut_builder.finish() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_app", [{"buildername": "needs_lut", "srcdir": "doc_test/doc_needs_builder"}], indirect=True | ||
) | ||
def test_doc_needs_id_builder(test_app): | ||
app = test_app | ||
app.build() | ||
|
||
needs_json = Path(app.outdir, "needs_lut.json") | ||
with open(needs_json) as needs_file: | ||
needs_file_content = needs_file.read() | ||
|
||
needs_list = json.loads(needs_file_content) | ||
assert needs_list["TC_NEG_001"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mention what
lut
stands for. Maybe:**needs_lut** (Needs Lookup Table
)