-
Notifications
You must be signed in to change notification settings - Fork 71
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
How-to use needs-render-context with a function without getting an unpickable warning #1206
Comments
<deprecated, nevermind> :D The trouble is sphinx-needs takes a str() of the parameter. Which is a dynamic address for functions. So what I did so far was wrap the functions in a class, but this has stopped working (not sure which version). Now we run into pickle trouble when we inject a class in that way.
|
I tried injecting into jinja2uml instead of render_context. It's not the best API, but very first attempts look promising.... def add_custom_uml_functions(functions: dict[str, Callable]):
orig_jinja2uml = sphinx_needs.directives.needuml.jinja2uml
def wrapper( # noqa: PLR0913
app: sphinx.application.Sphinx,
fromdocname: None | str,
uml_content: str,
parent_need_id: str,
key: str,
processed_need_ids: dict,
kwargs: dict[str, Any],
) -> tuple[str, dict]:
# inject functions into kwargs, which will be appended to data
kwargs.update(functions)
return orig_jinja2uml(
app,
fromdocname,
uml_content,
parent_need_id,
key,
processed_need_ids,
kwargs,
)
frame = inspect.currentframe()
assert frame
name_of_this_function = frame.f_code.co_name
is_replaced = str(orig_jinja2uml).find(name_of_this_function) != -1
if not is_replaced:
# print("custom uml functions added")
sphinx_needs.directives.needuml.jinja2uml = wrapper And in setup() or somewhere: add_custom_uml_functions(
{
"puml_participant": puml_participant,
}
) edit 10 hours later: now it's failing :(
|
I try to use needs-render-context and get
Is there an option, to configure it without getting the warning?
I have set:
suppress_warnings = ["config.cache"]
inconf.py
, but this is only a work around.The text was updated successfully, but these errors were encountered: