Skip to content

generalize ODXLINK reference writing #420

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

andlaus
Copy link
Member

@andlaus andlaus commented Apr 29, 2025

writing ODXLINK references should now always work regardless of in which document fragments the reference and the target objects are located.

this works by providing three new "magical" global functions to the jinja macros for output:

  • set_category_docfrag(): Specify the document fragment for the ODX category which is applicable for all subsequent macro invocations.
  • set_layer_docfrag(): Specify the document fragment for the diagnostic layer which is applicable for all subsequent macro invocations (for DIAG-LAYER-CONTAINER).
  • make_ref_attribs(ref: OdxLinkRef): produces all necessary XML attributes required for an ODX link reference XML tag. (i.e., ID-REF, DOCREF and DOCTYPE)

internally, these functions require a dictionary parameter for storing "magic" global variables. On the jinja side, this is not necessary because lambda functions are used as wrappers.

Andreas Lauser <[email protected]>, on behalf of MBition GmbH.
Provider Information

writing ODXLINK references should now always work regardless of in
which document fragments the reference and the target objects are
located.

this works by providing three new "magical" global functions to the
jinja macros for output:

- `set_category_docfrag()`: Specify the document fragment for the ODX
  category which is applicable for all subsequent macro invocations.
- `set_layer_docfrag()`: Specify the document fragment for the
  diagnostic layer which is applicable for all subsequent macro
  invocations (for DIAG-LAYER-CONTAINER).
- `make_ref_attribs(ref: OdxLinkRef)`: produces all necessary XML
  attributes required for an ODX link reference XML tag. (i.e.,
  ID-REF, DOCREF and DOCTYPE)

internally, these functions require a dictionary parameter for storing
"magic" global variables. On the jinja side, this is not necessary
because lambda functions are used as wrappers.

Signed-off-by: Andreas Lauser <[email protected]>
Approved-by: Alexander Walz <[email protected]>
@andlaus andlaus requested a review from kayoub5 April 29, 2025 08:43

jinja_env.globals["set_category_docfrag"] = lambda cname, ctype: set_category_docfrag(
jinja_vars, cname, ctype)
jinja_env.globals["set_layer_docfrag"] = lambda lname: set_layer_docfrag(jinja_vars, lname)
Copy link
Collaborator

Choose a reason for hiding this comment

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

from functools import partial

Suggested change
jinja_env.globals["set_layer_docfrag"] = lambda lname: set_layer_docfrag(jinja_vars, lname)
jinja_env.globals["set_layer_docfrag"] = partial(set_layer_docfrag, jinja_vars)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this should stay with the lambdas because partial is much less known (I didn't know it) and it is IMO also less explicit...

andlaus added 2 commits April 29, 2025 13:06
thanks to [at]kayoub5

Signed-off-by: Andreas Lauser <[email protected]>
now, there should not be any global variables in this code and it
should thus be threadsafe...

Signed-off-by: Andreas Lauser <[email protected]>
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.

2 participants