Skip to content

Commit

Permalink
Replace pystache with chevron (kerrickstaley#93)
Browse files Browse the repository at this point in the history
pystache has been unmaintained for a long time, with the [last commit]
to [defunkt/pystache] being from September 2014. By now it is not
installable with up-to-date setuptools.
Luckily, genanki uses only the most basic of mustache API, and [chevron]
fills the gap nicely. Tests are passing for me again.

[chevron]: https://github.com/noahmorrison/chevron
[defunkt/pystache]: https://github.com/defunkt/pystache
[last commit]: defunkt/pystache@17a5dfd
  • Loading branch information
black-puppydog authored Nov 16, 2021
1 parent 73d3cbf commit 9319f34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions genanki/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from copy import copy
from cached_property import cached_property
import pystache
import chevron
import yaml

class Model:
Expand Down Expand Up @@ -41,7 +41,7 @@ def _req(self):
"""
List of required fields for each template. Format is [tmpl_idx, "all"|"any", [req_field_1, req_field_2, ...]].
Partial reimplementation of req computing logic from Anki. We use pystache instead of Anki's custom mustache
Partial reimplementation of req computing logic from Anki. We use chevron instead of Anki's custom mustache
implementation.
The goal is to figure out which fields are "required", i.e. if they are missing then the front side of the note
Expand All @@ -57,7 +57,7 @@ def _req(self):
field_values = {field: sentinel for field in field_names}
field_values[field] = ''

rendered = pystache.render(template['qfmt'], field_values)
rendered = chevron.render(template['qfmt'], field_values)

if sentinel not in rendered:
# when this field is missing, there is no meaningful content (no field values) in the question, so this field
Expand All @@ -73,7 +73,7 @@ def _req(self):
field_values = {field: '' for field in field_names}
field_values[field] = sentinel

rendered = pystache.render(template['qfmt'], field_values)
rendered = chevron.render(template['qfmt'], field_values)

if sentinel in rendered:
# when this field is present, there is meaningful content in the question
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
install_requires=[
'cached-property',
'frozendict',
'pystache',
'chevron',
'pyyaml',
],
setup_requires=[
Expand Down

0 comments on commit 9319f34

Please sign in to comment.