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 NeedsPerPageBuilder #962

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

Conversation

nhatnamnguyengtvthcm
Copy link
Contributor

  1. Create a new builder in builde.py called: NeedsPerPageBuilder
    2 . run: make-html-fast -> the need_per_page folder will be gened which has seperated the need with same docs_name

haiyangToAI and others added 22 commits August 22, 2023 15:32
* 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 <daniel.woste@useblocks.com>
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] <support@github.com>
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 <daniel.woste@useblocks.com>
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.

Some finding, but overall the code looks okay.

However, with Needsfile there is a generic Need-Builder class, which cares about setting everything up the right way.
And I think we should use this and just extend it by a function to store the data in a specific way.
https://github.com/useblocks/sphinx-needs/blob/master/sphinx_needs/needsfile.py

Your code doubles a lot of functions, like filtering, data preparation, and some magic configurations.
That's hard to maintain in the future.

What do you think, is updating Needsfile possible?



Format with file name: configuration.json
++++++
Copy link
Member

Choose a reason for hiding this comment

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

What does this syntax do?

Please build the docs and check for errors before submitting.
A make docs-html is now enough, as I fixed the doc-build and made it much easier.


Format with file name: configuration.json
++++++
.. code-block:: python
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this to a json file and present it here via .. literalinclude::?
Much easier to maintain.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe just remove this and use the testing snapshots.
The problem with having it "statically" in the documentation, is that it is prone to become out-of-date with the actual code


Build list of ``json`` files that contain all found needs with the same ``docname``. The name of each file should match the ``docname``.

This option works like needs_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.

Please use :ref: to reference other documentation objects.


.. versionadded:: 1.4.0

This option sets the location of list of ``json`` files that contain all found needs with the same ``docname``.
Copy link
Member

Choose a reason for hiding this comment

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

Is this a folder or a file name?
Is it relative to the build folder or to the documentation root?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is name of folder


This option sets the location of list of ``json`` files that contain all found needs with the same ``docname``.

Default value: need_per_page
Copy link
Member

Choose a reason for hiding this comment

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

Please highlight path information like need_per_page.
Add also a / if it is a folder

needs_per_page_dir = os.path.join(self.outdir, needs_per_page_build_path)
needs_per_page_data = {}
if not os.path.exists(needs_per_page_dir):
os.mkdir(needs_per_page_dir)
Copy link
Member

Choose a reason for hiding this comment

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

This does not work, if there are multiple new folders in the path, e.g. needs/pages/examples/.

Use instead:
https://docs.python.org/3/library/os.html#os.makedirs

os.mkdir(needs_per_page_dir)

needs_per_page_data_key = []
for need in filtered_needs:
Copy link
Member

Choose a reason for hiding this comment

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

Some more comments would be good, especially if you have such much code in a single function and haven't it broken down to some sub functions.

At least for-loops with multiple lines should get a comment, so that you know in advance what the goal of the for loop is before reading all code line.
Something like sorting needs into docname-based dict would be helpful.

format = "needs"
file_suffix = ".txt"
links_suffix = None
LIST_KEY_EXCLUSIONS_NEEDS = ["content_node"]
Copy link
Member

Choose a reason for hiding this comment

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

This is not Builder specific and is shared information that each builder must follow.
So if we need to extend it, we must touch multiple locations. That's not good.

That's one of the reasons why a central ``Needsfile` class was created to deal with such common configs.
https://github.com/useblocks/sphinx-needs/blob/master/sphinx_needs/needsfile.py

tests/test_needs_per_page_builder.py Outdated Show resolved Hide resolved
tests/test_needs_per_page_builder.py Outdated Show resolved Hide resolved
@nhatnamnguyengtvthcm
Copy link
Contributor Author

nhatnamnguyengtvthcm commented Aug 24, 2023

Some finding, but overall the code looks okay.

However, with Needsfile there is a generic Need-Builder class, which cares about setting everything up the right way. And I think we should use this and just extend it by a function to store the data in a specific way. https://github.com/useblocks/sphinx-needs/blob/master/sphinx_needs/needsfile.py

Your code doubles a lot of functions, like filtering, data preparation, and some magic configurations. That's hard to maintain in the future.

What do you think, is updating Needsfile possible?

I wonder do you want the format of the JSON file generated the same needs.json. should It generate by function in needsfile?

@chrisjsewell chrisjsewell changed the title Namnn/need per page json ✨ NEW: Add NeedsPerPageBuilder Sep 12, 2023
@@ -361,6 +361,9 @@ def custom_defined_func():
# build needs.json to make permalinks work
needs_build_json = True

# build json file include needs with the same docs_name
needs_per_page = True
Copy link
Member

Choose a reason for hiding this comment

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

This option name should be consistent with the other builders (build_json, build_json_per_id), i.e. build_json_per_page

Thinking holistically, with there now being numerous data writers, and more on the way, maybe it makes sense to have some form of unified configuration option.

For example:

needs_data_writers = ["json", "json_per_id", "json_per_page"]

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

LGTM. Approved for contribution.

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