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

👌 Allow needextend to use dynamic functions #1052

Merged
merged 5 commits into from
Oct 27, 2023

Conversation

chrisjsewell
Copy link
Member

closes #970 (cc @arwedus)

One key change here, which I think makes sense but should be agreed on,
is that we alter the needs data post-processing order, to extend the needs, before processing dynamic values, links and constraints.

This did not break any of the tests, and I feel should not breaking any existing users, unless they are doing something very exotic 😅

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.

Looks good and thanks for the work 👍

@chrisjsewell chrisjsewell merged commit d8b0a28 into master Oct 27, 2023
11 checks passed
@chrisjsewell chrisjsewell deleted the extends-dynamic-functions branch October 27, 2023 08:49
return filtered_needs


needs_functions = [get_matching_need_ids]
Copy link
Contributor

Choose a reason for hiding this comment

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

should be added with the sphinx API, as in practical use cases (to avoid messing up the incremental build)

@wuhuhit
Copy link

wuhuhit commented Nov 14, 2023

Hi man, I see that currently we can use dynamic functions in need_extend directive. And I want to know can we use the dynammic funcitions in need_flow, need_bar, need_pie?

@danwos
Copy link
Member

danwos commented Nov 14, 2023

No, you can't. Mostly because I see no use case for this.
Dynamic functions are used to set meta-data of a need, what you are not doing with needflow and co.

But maybe the filter-function feature covers your use case?
https://sphinx-needs.readthedocs.io/en/latest/filter.html#filter-function

@wuhuhit
Copy link

wuhuhit commented Nov 14, 2023

Thanks for your repy, I want to collect the needs info during sphinx build with dynamic functions for the need_flow, need_bar, need_pie directives. You know then I can dynamic filter the directives with the specify needs id. that's quiet convenient.
As you said, I found that need-pie support filter-func and it perhaps can solve my problem, does need_flow and need_bar also support filter-func?

@danwos
Copy link
Member

danwos commented Nov 14, 2023

Mhh that sounds a little bit like a misuse of dynamic functions.
The need info and all data from the Sphinx-Needs directive are available in the Sphinx app/env object, so for such functions, you should register a handler for one of the Sphinx events.

But to be honest, I haven't understood your use case 100%.
Why do you need the internal data of needbar, needpie and co?

@wuhuhit
Copy link

wuhuhit commented Nov 15, 2023

sorry, perhaps what I said was not detaild enough.
take need_flow directive as an example, as below:
..needflow::
:filter: id in [...]
I wang to use dynamic functions or filter funcitons to fill in the special needs info here,during the sphinx build process. Then I can dynamic adjust the filter value based on the latest sphinx result. And the similar method for needbar and needpie.
Do you have some good ideas about this? many thx

@danwos
Copy link
Member

danwos commented Nov 15, 2023

Ok, this specific way is not supported, but filter-code/function should do the trick.
Sphinx-Jinja could also be used here and variables could be set by conf.py.

@wuhuhit
Copy link

wuhuhit commented Nov 15, 2023

you know, you guys has said in the filter-function discription that needpie directive support filter-code, and I want to know whether needflow and needbar also support filter function? And I plan to do some testwith filter code.
Besides, Sphinx-Jinjia seems also work, But I'm sorry I'm not very clear about the sphinx-jinjia solution. could you please provide the sphinx-jinjia solution in more detail for me? And I will also try it.
Thank you very much

@wuhuhit
Copy link

wuhuhit commented Nov 16, 2023

Hi Danwos, Thank you for your great suggestions.
I have tried the special directives successfully with filter-code/filter fuction.

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.

needextend shall support dynamic functions
4 participants