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

feat(author-jinja): load jinja extensions from plugins #1710

Merged
merged 13 commits into from
Oct 22, 2024

Conversation

rahearn
Copy link
Contributor

@rahearn rahearn commented Sep 25, 2024

Types of changes

  • Hot fix (emergency fix and release)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation (change which affects the documentation site)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Release (develop -> main)

Quality assurance (all should be covered).

  • My code follows the code style of this project.
  • Documentation for my change is up to date?
  • My PR meets testing requirements.
  • All new and existing tests passed.
  • All commits are signed-off.

Summary

Builds on the proof of concept at #1684 and:

  • moves the methods in the previously new ssp_interface into a set of jinja filters. Example switch in use:

{% for party in ssp_interface.get_parties_for_role(ssp.metadata.responsible_parties, "prepared-by") %} becomes
{% for party in ssp.metadata.responsible_parties | parties_for_role("prepared-by", ssp) %}

{{ ssp_interface.safe_retrieval(address, 'addr_lines', []) | join(' ') }} becomes {{ address.addr_lines | as_list | join(' ') }}

  • refactors the jinja code into a module to better organize it and avoid some circular dependencies
  • enables loading extensions from plugins, searching under: trestle_{plugin_name}.jinja_ext
  • updates plugin docs

Key links:

Before you merge

  • Ensure it is a 'squash commit' if not a release.
  • Ensure CI is currently passing
  • Check sonar. If you are working for a fork a maintainer will reach out, if required.

Signed-off-by: Ryan Ahearn <ryan.ahearn@gsa.gov>
Signed-off-by: Ryan Ahearn <ryan.ahearn@gsa.gov>
Signed-off-by: Ryan Ahearn <ryan.ahearn@gsa.gov>
Signed-off-by: Ryan Ahearn <ryan.ahearn@gsa.gov>
fix some other random typos

Signed-off-by: Ryan Ahearn <ryan.ahearn@gsa.gov>
@rahearn rahearn changed the title feat(author-jinja): Load jinja extensions from plugins feat(author-jinja): load jinja extensions from plugins Sep 25, 2024
@butler54
Copy link
Collaborator

butler54 commented Oct 2, 2024

Hi @rahearn - sorry for the delay. I'll look at this in the next few days :).

@jpower432 jpower432 added this to the v3.5.0 milestone Oct 8, 2024
Signed-off-by: Ryan Ahearn <ryan.ahearn@gsa.gov>
Copy link
Member

@jpower432 jpower432 left a comment

Choose a reason for hiding this comment

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

@rahearn Thanks for this submission! Wanted to add some early feedback here. Requesting new source code files (the newly created jinja package in this case) have the updated copyright info. I added a suggestion on one of the files to what this should be updated to.

tests/trestle/core/jinja/filters_test.py Outdated Show resolved Hide resolved
@jpower432 jpower432 linked an issue Oct 8, 2024 that may be closed by this pull request
3 tasks
Signed-off-by: Ryan Ahearn <ryan.ahearn@gsa.gov>
Copy link
Collaborator

@butler54 butler54 left a comment

Choose a reason for hiding this comment

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

LGTM - This is really great work. @jpower432's picked up one comment otherwise the only thing that i've seen here which needs to be tidied here is a dangling comment.

}


def discovered_plugins(search_module: str) -> Iterator[Tuple[str, Any]]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a nice improvement :)

class TrestleJinjaExtension(Extension):
"""Class to define common methods to be inherited from for use in trestle."""

# This
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think #this needs to be cleaned up.

Copy link
Member

@jpower432 jpower432 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the contribution @rahearn!

@jpower432 jpower432 modified the milestones: v3.6.0, v3.5.0 Oct 22, 2024
@jpower432
Copy link
Member

@rahearn Your branch needs to be up to date with the base branch and then it should be good to merge.

@jpower432 jpower432 merged commit f7b63ad into oscal-compass:develop Oct 22, 2024
14 checks passed
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.

Add ability to extend jinja functionality with plugins
3 participants