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

👌 Optimize needextend filter_needs usage #1030

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ Released: under development
-----
Released: under development
* Improvement: Added Builder :ref:`needs_id_builder` added and config option :ref:`needs_build_json_per_id` in `conf.py`.

* Improvement: Reduce document build time, by memoizing the inline parse in ``build_need`` (`#968 <https://github.com/useblocks/sphinx-needs/pull/968>`_)

* Change `NeedsBuilder` format to `needs` (`#978 <https://github.com/useblocks/sphinx-needs/pull/978>`_)

* Improvement: Suffix all warnings with ``[needs]``, and allow them to be suppressed (`#975 <https://github.com/useblocks/sphinx-needs/pull/975>`_)
* Improvement: Reduce document build time, by memoizing the inline parse in ``build_need``
(`#968 <https://github.com/useblocks/sphinx-needs/pull/968>`_)
* Change `NeedsBuilder` format to `needs`
(`#978 <https://github.com/useblocks/sphinx-needs/pull/978>`_)
* Improvement: Suffix all warnings with ``[needs]``, and allow them to be suppressed
(`#975 <https://github.com/useblocks/sphinx-needs/pull/975>`_)
* Improvement: :ref:`needextend` for single needs is much faster.

1.3.0
-----
Expand Down
15 changes: 8 additions & 7 deletions sphinx_needs/directives/needextend.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def process_needextend(app: Sphinx, doctree: nodes.document, fromdocname: str) -
# In this case create the needed filter string
need_filter = current_needextend["filter"]
if need_filter in all_needs:
need_filter = f'id == "{need_filter}"'
found_needs = [all_needs[need_filter]]
# If it looks like a need id, but we haven't found one, raise an exception
elif need_filter is not None and re.fullmatch(needs_config.id_regex, need_filter):
error = f"Provided id {need_filter} for needextend does not exist."
Expand All @@ -106,12 +106,13 @@ def process_needextend(app: Sphinx, doctree: nodes.document, fromdocname: str) -
else:
logger.info(error)
continue
try:
found_needs = filter_needs(app, all_needs.values(), need_filter)
except NeedsInvalidFilter as e:
raise NeedsInvalidFilter(
f"Filter not valid for needextend on page {current_needextend['docname']}:\n{e}"
)
else:
try:
found_needs = filter_needs(app, all_needs.values(), need_filter)
except NeedsInvalidFilter as e:
raise NeedsInvalidFilter(
f"Filter not valid for needextend on page {current_needextend['docname']}:\n{e}"
)

for found_need in found_needs:
# Work in the stored needs, not on the search result
Expand Down