Skip to content
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

Open
wants to merge 53 commits into
base: master
Choose a base branch
from

Conversation

nhatnamnguyengtvthcm
Copy link
Contributor

  1. add builder called NeedsLookUpTableBuilder
  2. Builder NeedsLookUpTableBuilder generates needs_lut.json file include {id: docs_name_path}

Copy link
Member

@danwos danwos left a 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
Copy link
Member

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 Show resolved Hide resolved
.. __needs_lut_build_json:

needs_lut_build_json
~~~~~~~~~~~~~~~~~~~~~~~
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headline too long

docs/configuration.rst Outdated Show resolved Hide resolved
sphinx_needs/builder.py Show resolved Hide resolved
sphinx_needs/builder.py Outdated Show resolved Hide resolved
@@ -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")
Copy link
Member

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?

sphinx_needs/templates/permalink.html Outdated Show resolved Hide resolved
haiyangToAI and others added 14 commits August 22, 2023 13:23
* 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)
Copy link
Member

@danwos danwos left a 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.

---------
.. 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``.
Copy link
Member

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)


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.
Copy link
Member

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:
Copy link
Member

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.

Copy link
Member

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.

@chrisjsewell chrisjsewell changed the title Namnn/needs lookup ✨ NEW: Add NeedsLookUpTableBuilder Sep 7, 2023
Copy link
Member

@chrisjsewell chrisjsewell left a 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:

assert needs_list == snapshot(exclude=props("created"))

@@ -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,)})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Member

@danwos danwos left a 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.

@@ -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:
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor

@r-o-b-e-r-t-o r-o-b-e-r-t-o Sep 22, 2023

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:
Copy link
Member

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.

@r-o-b-e-r-t-o
Copy link
Contributor

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants