-
Notifications
You must be signed in to change notification settings - Fork 67
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?
✨ NEW: Add NeedsLookUpTableBuilder
#961
Conversation
nhatnamnguyengtvthcm
commented
Aug 4, 2023
- add builder called NeedsLookUpTableBuilder
- Builder NeedsLookUpTableBuilder generates needs_lut.json file include {id: docs_name_path}
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.
Thanks for the PR.
The idea is good and the implementation is promising.
Unfortunately, I have some findings:
I'm missing any documentation of the new builder in the buiders.rst
file.
This should also contain an example of how the final file looks like.
Also a test case is missing for the javascript part.
You can find examples of it inside /tests/js_test
:
https://github.com/useblocks/sphinx-needs/tree/master/tests/js_test
docs/conf.py
Outdated
@@ -380,6 +380,9 @@ def custom_defined_func(): | |||
# build needs.json to make permalinks work | |||
needs_build_json = True | |||
|
|||
# build needs_lut.json to make permalinks work | |||
needs_lut_build_json = True |
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.
I think this is not needed for our Sphinx-Needs docs?
docs/configuration.rst
Outdated
.. __needs_lut_build_json: | ||
|
||
needs_lut_build_json | ||
~~~~~~~~~~~~~~~~~~~~~~~ |
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.
headline too long
sphinx_needs/needs.py
Outdated
@@ -279,6 +284,7 @@ def setup(app: Sphinx) -> Dict[str, Any]: | |||
# | |||
app.add_config_value("needs_debug_measurement", False, "html", types=[dict]) | |||
|
|||
app.add_config_value("needs_permalink_url", None, "html") |
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.
Where is this used and documented?
* Added config allow unsafe filter for filter_func * Fixed review * Updated sphinx-immaterial to fix CI * Fix linkcheck anchor issue --------- Co-authored-by: Daniel Woste <[email protected]>
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.3.0 to 3.5.3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v3.3.0...v3.5.3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]>
Inside the LaTeX generator, it looks for the attributes ids and refid for creating link targets. When a new layer with a <container> wrapper was added in commit e51fc1f, for an unknown reason this triggered these additional IDs to generate links within the LaTeX output. A test case has been added to ensure only one hyperref within LaTeX is encountered as well. (useblocks#808)
Co-authored-by: Daniel Woste <[email protected]>
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.
This PR needs to be updated to the latest changes for 1.4.0 (master).
Especially the way of option registration has changed.
- some other minor findings.
docs/builders.rst
Outdated
--------- | ||
.. 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``. |
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
)
docs/builders.rst
Outdated
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
.. a file called
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 comment
The 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 write_json_lut
?
It's easier to maintain if all storage functions are defined in one place.
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.
I think we should stay with add_need
(instead of add_lut_need
) and transform the needed data in a special writer function write_json_lut
.
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.
Heya @nhatnamnguyengtvthcm, as you can see in #1019 I added snapshot testing, to provide snapshots of the expected data.
Perhaps you could add this to your test_doc_needs_lut_builder
As an example, see:
sphinx-needs/tests/test_needs_builder.py
Line 14 in 09277e3
assert needs_list == snapshot(exclude=props("created")) |
sphinx_needs/config.py
Outdated
@@ -252,6 +252,7 @@ def __setattr__(self, name: str, value: Any) -> None: | |||
# add config for needs_id_builder | |||
build_json_per_id: bool = field(default=False, metadata={"rebuild": "html", "types": (bool,)}) | |||
build_json_per_id_path: str = field(default="needs_id", metadata={"rebuild": "html", "types": (str,)}) | |||
lut_build_json: bool = field(default=False, metadata={"rebuild": "html", "types": (bool,)}) |
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.
lut_build_json: bool = field(default=False, metadata={"rebuild": "html", "types": (bool,)}) | |
build_json_lut: bool = field(default=False, metadata={"rebuild": "html", "types": (bool,)}) |
This would be consistent with build_json
and build_json_per_id
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.
Thankas for the changes.
I think the builder is more complex as it should be, just see my comment.
I also like the snapshot idea from Chris for the tests.
sphinx_needs/needsfile.py
Outdated
@@ -131,6 +131,9 @@ def load_json(self, file: str) -> None: | |||
|
|||
self.log.debug(f"needs.json file loaded: {file}") | |||
|
|||
def add_lut_need(self, version: str, needs_lut: Dict[str, Any]) -> None: |
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.
My idea was a little different.
Instead of adding a custom data structure and use the same writer-function, we could keep the data structure with add_need()
and just do the output specific formating in a new writer function like write_lut_json
.
In this case all the code is the same, till it comes to write it to the harddisk.
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.
I wonder if we keep formatting JSON and only map need["docname"] = need["external_url"] if need["is_external"] = True, It is easy to reuse flow generate need_lut.json like need.json. Otherwise, I will continue change formatting in write_lut_json like {[id] : [docname] or [external_url]}
@r-o-b-e-r-t-o @danwos
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.
@nhatnamnguyengtvthcm Not sure if I got your point. But I think we must have a mapping for internal and external needs because otherwise you would not be redirected correctly by permalink.html in case an external need is referenced.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should stay with add_need
(instead of add_lut_need
) and transform the needed data in a special writer function write_json_lut
.
LGTM. Approved for contribution. |
Instead of using `filter_needs()` for a single need (`id == ""XY`) , the need is taken directly from `all_needs`, so that we do not need to perform any filtering.
0796b94
to
6649155
Compare