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

Use chevron Instead of pystache for Templating #32

Merged
merged 1 commit into from
Aug 6, 2021

Conversation

mcdonnnj
Copy link
Member

@mcdonnnj mcdonnnj commented Aug 4, 2021

πŸ—£ Description

This PR replaces defunkt/pystache with noahmorrison/chevron for rendering mustache templates.

πŸ’­ Motivation and context

The pystache package's last release was 2014-05-12 while the chevron package's last release was 2021-01-02. This difference in continued development should be reason enough to change. In mustache/mustache.github.com#120 the recommended Python package for mustache templating was updated from pystache to chevron. As a last bonus:

"Chevron runs in less than half the time of pystache (Which is not even up to date on the spec). And in about 70% the time of Stache (A 'trimmed' version of mustache, also not spec compliant)."

This is a "test run" of transitioning to using chevron for any of our mustache templating. I think it will be beneficial to switch to a maintained package that is claimed to be substantially faster than our current package choice.

πŸ§ͺ Testing

Automated tests pass successfully. But wait, there's more!

Generate rendered files with Python

>>> import chevron
>>> template_data = {
...   "conflict_file_list": ["foo.py", "bar.sh"],
...   "lineage_id": "skeleton",
...   "local_branch": "develop",
...   "metadata": 'lineage:metadata:{"slayed":true}',
...   "pr_branch_name": "lineage/skeleton",
...   "remote_branch": "HEAD",
...   "remote_url": "https://github.com/cisagov/skeleton-python-library.git",
...   "repo_name": "action-lineage",
...   "ssh_url": "git@github.com:cisagov/action-lineage.git",
... }
>>> with open("src/lineage/templates/clean_template.md") as f:
...   clean_template = f.read()
...
>>> with open("src/lineage/templates/conflict_template.md") as f:
...   conflict_template = f.read()
...
>>> clean_body = chevron.render(clean_template, template_data)
>>> conflict_body = chevron.render(conflict_template, template_data)
>>> with open("clean_rendered.md", "w") as f:
...   f.write(clean_body)
...
792
>>> with open("conflict_rendered.md", "w") as f:
...   f.write(conflict_body)
...
2397
>>> import pystache
>>> clean_body = pystache.render(clean_template, template_data)
>>> conflict_body = pystache.render(conflict_template, template_data)
>>> with open("clean_rendered_pystache.md", "w") as f:
...   f.write(clean_body)
...
792
>>> with open("conflict_rendered_pystache.md", "w") as f:
...   f.write(conflict_body)
...
2397
>>>

Compare the rendered files

$ diff clean_rendered.md clean_rendered_pystache.md
$ diff conflict_rendered.md conflict_rendered_pystache.md

βœ… Checklist

  • This PR has an informative and human-readable title.
  • Changes are limited to a single goal - eschew scope creep!
  • All relevant type-of-change labels have been added.
  • I have read the CONTRIBUTING document.
  • These code changes follow cisagov code standards.
  • All new and existing tests pass.

@mcdonnnj mcdonnnj added the improvement This issue or pull request will add or improve functionality, maintainability, or ease of use label Aug 4, 2021
@mcdonnnj mcdonnnj self-assigned this Aug 4, 2021
@mcdonnnj mcdonnnj added this to In progress in Skeleton Maintenance via automation Aug 4, 2021
Copy link
Member

@dav3r dav3r left a comment

Choose a reason for hiding this comment

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

Seems promising! πŸ‘

Skeleton Maintenance automation moved this from In progress to Reviewer approved Aug 5, 2021
This replaces the pystache package with the chevron package for rendering
mustache templates.
@mcdonnnj mcdonnnj force-pushed the improvement/use_chevron_for_mustache_templating branch from 8e86b77 to 401802c Compare August 5, 2021 15:20
@mcdonnnj mcdonnnj merged commit e5bfd00 into develop Aug 6, 2021
Skeleton Maintenance automation moved this from Reviewer approved to Done Aug 6, 2021
@mcdonnnj mcdonnnj deleted the improvement/use_chevron_for_mustache_templating branch August 6, 2021 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement This issue or pull request will add or improve functionality, maintainability, or ease of use
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants