Repository navigation
✨ Add the dynamic function links_from_filter - #1984
Open
PhilipPartsch wants to merge 2 commits into
Open
PhilipPartsch wants to merge 2 commits into
PhilipPartsch wants to merge 2 commits into
Conversation
links_from_filter links a need to every need that passes a filter string. The need that contains the call, and its own parts, are left out unless include_self=True; parts are only searched with include_parts=True. An empty result emits a needs.links_from_filter warning unless allow_empty=True. Also fixes three bugs found on the way: - copy with upper/lower now cases a list option item by item, instead of casing the list's printed form into one value. - c.this_doc() now works in copy's filter: the filter is evaluated with the document of the current need. - ndf shows the links a dynamic function returns as need IDs, not as NeedLink(...) reprs.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a built-in dynamic function,
links_from_filter, which links a need to every need that passes a filter string, and fixes three bugs found while writing it.links_from_filterinclude_parts=Truealso every need's parts. A matching part is linked as<need>.<part>.include_self=True.needs.links_from_filterwarning is emitted, unlessallow_empty=True. It has its own subtype so a project can suppress it without hidingneeds.dynamic_functionfailures. If only the calling need matched, the message says it was excluded and namesinclude_self=True.needs.dynamic_function), because it would otherwise link to every need in the project.current_need[...]andc.this_doc()work in the filter. For example,c.this_doc() and sections == current_need["sections"]links to the needs in the same chapter of the same file.The docstring is the user documentation, rendered in
docs/dynamic_functions.rst, with asyntax-example.Bug fixes
copywithupper=Trueorlower=Trueon a list option cased the list's printed form.copy("tags", "SRC_1", upper=True)on tagsalpha, betagave one tag,"['ALPHA', 'BETA']". It now givesALPHAandBETA. This changes output, and the changelog marks it so.c.this_doc()incopy's filter always failed withthis_doc can not be used in this context.copythen silently copied from the current need instead. The filter now gets the current need's document asorigin_docname, aslinks_from_filterdoes.:ndf:with a function that returns links (links_from_content, and nowlinks_from_filter) printedNeedLink(id='REQ_1', part=None, condition=None). It now printsREQ_1, orREQ_1.p1for a part.Tests
All in
tests/test_dynamic_functions.py, as inline projects:links_from_filter:include_self;include_parts, including the calling need's own parts;allow_empty;:ndf:output.c.this_doc().copy: casing a list, andc.this_doc()in its filter.Checks
uv run poe test-needs -n 4: 1812 passed, 11 skipped; snapshots unchangedUV_PYTHON=3.12 uv run --no-sync poe test-needs-sphinx9 tests/schema: 182 passeduv run poe lint: passeduv run poe typecheck: passeduv run poe docs-needs -E: exit 0