Skip to content

Commit 41be3d8

Browse files
Gareth Aneurin TribelloGareth Aneurin Tribello
authored andcommitted
Added functionality to track keywords used in a particular action on a markdown page
1 parent 8fc43a4 commit 41be3d8

4 files changed

Lines changed: 25 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "PlumedToHTML"
8-
version = "0.116"
8+
version = "0.117"
99
description = "A package for creating prettified HTML for PLUMED files"
1010
authors = [{ name = "Gareth Tribello", email = "gareth.tribello@gmail.com" }]
1111
maintainers = [{ name = "Daniele Rapetti", email = "iximiel@gmail.com" }]

src/PlumedToHTML/PlumedFormatter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def __init__(self, **options) :
2121
self.auxinputlines=options["auxinputlines"]
2222
self.valuedict=options["valuedict"]
2323
self.actions=options["actions"]
24+
self.checkaction=options["checkaction"]
25+
self.checkaction_keywords = set({})
2426
self.valcolors = {
2527
"scalar": "black",
2628
"atoms": "violet",
@@ -301,6 +303,9 @@ def format(self, tokensource, outfile):
301303
outfile.write('</pre>')
302304

303305
def writeValuesData( self, outfile, action, label, keywords, outdict ) :
306+
if action==self.checkaction :
307+
for key in keywords :
308+
self.checkaction_keywords.add( key )
304309
# Some header stuff
305310
outfile.write('<span style="display:none;" id="' + self.egname + label + r'">')
306311
outfile.write('The ' + action + ' action with label <b>' + label + '</b>')
@@ -337,4 +342,7 @@ def writeValueInfo( self, outfile, label, span_label, valinfo ) :
337342
outfile.write('<tr><td width="5%">' + key + '</td><td width="5%"><font color="' + self.valcolors[value["type"]] +'">' + value["type"] + '</font></td><td>' + value["description"] + '</td></tr>')
338343
outfile.write('</table>')
339344
outfile.write('</span>')
345+
346+
def getCheckActionKeywords( self ) :
347+
return self.checkaction_keywords
340348

src/PlumedToHTML/PlumedToHTML.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def get_cltoolfile_html( inpt, name, plumedexe ) :
214214
# Setup the formatter
215215
formatfile = os.path.join(os.path.dirname(__file__),"PlumedFormatter.py")
216216
valuedict, actions = {}, set()
217-
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_dict=keyword_dict["cltools"], input_name=name, hasload=False, broken=False, auxinputs=[], auxinputlines=[], valuedict=valuedict, actions=actions )
217+
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_dict=keyword_dict["cltools"], input_name=name, hasload=False, broken=False, auxinputs=[], auxinputlines=[], valuedict=valuedict, actions=actions, checkaction="" )
218218
return highlight( inpt, plumed_lexer, plumed_formatter )
219219

220220
def get_cltoolarg_html( inpt, name, plumedexe ) :
@@ -258,10 +258,10 @@ def get_cltoolarg_html( inpt, name, plumedexe ) :
258258
# Setup the formatter
259259
formatfile = os.path.join(os.path.dirname(__file__),"PlumedFormatter.py")
260260
valuedict, actions = {}, set()
261-
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_dict=keyword_dict["cltools"], input_name=name, hasload=False, broken=False, auxinputs=[], auxinputlines=[], valuedict=valuedict, actions=actions )
261+
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_dict=keyword_dict["cltools"], input_name=name, hasload=False, broken=False, auxinputs=[], auxinputlines=[], valuedict=valuedict, actions=actions, checkaction="" )
262262
return highlight( inpt, plumed_lexer, plumed_formatter )
263263

264-
def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxchecks=None, actions=set({}), ghmarkdown=True ) :
264+
def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxchecks=None, actions=set({}), ghmarkdown=True, checkaction="", checkactionkeywords=set({}) ) :
265265
"""
266266
Generate the html representation of a PLUMED input file
267267
@@ -355,7 +355,7 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxch
355355
keyword_dict = getPlumedSyntax( plumedexe )
356356
# Setup the formatter
357357
formatfile = os.path.join(os.path.dirname(__file__),"PlumedFormatter.py")
358-
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_dict=keyword_dict, input_name=name, hasload=found_load, broken=any(broken), auxinputs=inputfiles, auxinputlines=inputfilelines, valuedict=valuedict, actions=actions )
358+
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_dict=keyword_dict, input_name=name, hasload=found_load, broken=any(broken), auxinputs=inputfiles, auxinputlines=inputfilelines, valuedict=valuedict, actions=actions, checkaction=checkaction )
359359

360360
# Now generate html of input
361361
html = '<div class="plumedpreheader">\n'
@@ -404,6 +404,13 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxch
404404
else :
405405
# html += highlight( final_inpt, plumed_lexer, HtmlFormatter() )
406406
html += highlight( final_inpt, plumed_lexer, plumed_formatter )
407+
408+
# Now remove keywords that appear in examples
409+
mykeywords = plumed_formatter.getCheckActionKeywords()
410+
for key in mykeywords :
411+
if key in checkactionkeywords :
412+
checkactionkeywords.remove(key)
413+
407414
# Test output is valid parsable html
408415
try :
409416
etree.parse(StringIO(html), etree.HTMLParser(recover=False))
@@ -669,7 +676,7 @@ def processMarkdown( filename, plumedexe, plumed_names, actions, jsondir="./", g
669676
ninputs, nfail = processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofile, jsondir, ghmarkdown )
670677
return ninputs, nfail
671678

672-
def processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofile, jsondir="./", ghmarkdown=True ) :
679+
def processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofile, jsondir="./", ghmarkdown=True, checkaction="ignore", checkactionkeywords=set({}) ) :
673680
"""
674681
Process a string of markdown that contains LUMED input files using PlumedtoHTML
675682
@@ -789,7 +796,9 @@ def processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofil
789796
plumedexe,
790797
usejson=(not success[-1]),
791798
actions=actions,
792-
ghmarkdown=ghmarkdown )
799+
ghmarkdown=ghmarkdown,
800+
checkaction=checkaction,
801+
checkactionkeywords=checkactionkeywords )
793802
# Print the html for the solution
794803
if ghmarkdown : ofile.write( "{% raw %}\n" + html + "\n {% endraw %} \n" )
795804
else : ofile.write( html )

tests/test_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def testSimple(self) :
2121
keydict = getPlumedSyntax( ("plumed",) )
2222

2323
# Setup a plumed formatter
24-
f = PlumedFormatter( keyword_dict=keydict, input_name="testout", hasload=False, broken=False, actions=set({}), valuedict=dict({}), auxinputs=[], auxinputlines=[] )
24+
f = PlumedFormatter( keyword_dict=keydict, input_name="testout", hasload=False, broken=False, actions=set({}), valuedict=dict({}), auxinputs=[], auxinputlines=[], , actions=actions, checkaction="" )
2525

2626
# Now run over all the inputs in the json
2727
for item in tests["regtests"] :

0 commit comments

Comments
 (0)