Skip to content

Commit

Permalink
Added functionality to create list of actions used within plumed inpu…
Browse files Browse the repository at this point in the history
…t file that can be accessed by function that calls get_html
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed Jan 23, 2024
1 parent e4fce40 commit 4f6146f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
3 changes: 3 additions & 0 deletions PlumedToHTML/PlumedFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, **options) :
self.egname=options["input_name"]
self.hasload=options["hasload"]
self.broken=options["broken"]
self.actions=options["actions"]

def format(self, tokensource, outfile):
action, label, all_labels, keywords, shortcut_state, shortcut_depth, default_state, notooltips, expansion_label = "", "", [], [], 0, 0, 0, False, ""
Expand Down Expand Up @@ -163,6 +164,8 @@ def format(self, tokensource, outfile):
elif ttype==Keyword :
# Name of action
action, notooltips = value.strip().upper(), False
# Store name of action in set that contains all action names
self.actions.add(action)
if action not in self.keyword_dict :
if self.hasload or self.broken : notooltips = True
else : raise Exception("no action " + action + " in dictionary")
Expand Down
9 changes: 5 additions & 4 deletions PlumedToHTML/PlumedToHTML.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def cd(newdir):
finally:
os.chdir(prevdir)

def test_and_get_html( inpt, name ) :
def test_and_get_html( inpt, name, actions=set({}) ) :
"""
Test if the plumed input is broken and generate the html syntax
Expand All @@ -51,7 +51,7 @@ def test_and_get_html( inpt, name ) :
# Now do the test
broken = test_plumed( "plumed", filename, header="", shortcutfile=name + '.json' )
# Retrieve the html that is output by plumed
html = get_html( inpt, name, name, ("master",), (broken,), ("plumed",) )
html = get_html( inpt, name, name, ("master",), (broken,), ("plumed",), actions )
# Remove the tempory files that we created
if not keepfile : os.remove(filename)

Expand Down Expand Up @@ -145,7 +145,7 @@ def manage_incomplete_inputs( inpt ) :
return complete, incomplete
return inpt, ""

def get_html( inpt, name, outloc, tested, broken, plumedexe ) :
def get_html( inpt, name, outloc, tested, broken, plumedexe, actions=set({}) ) :
"""
Generate the html representation of a PLUMED input file
Expand All @@ -161,6 +161,7 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe ) :
tested -- The versions of plumed that were testd
broken -- The outcome of running test plumed on the input
plumedexe -- The plumed executibles that were used. The first one is the one that should be used to create the input file annotations
actions -- Set to store all the actions that have been used in the input
"""

# If we find the fill command then split up the input file to find the solution
Expand Down Expand Up @@ -193,7 +194,7 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe ) :
plumed_info = subprocess.run(cmd, capture_output=True, text=True )
keyfile = plumed_info.stdout.strip() + "/json/syntax.json"
formatfile = os.path.join(os.path.dirname(__file__),"PlumedFormatter.py")
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_file=keyfile, input_name=name, hasload=found_load, broken=any(broken) )
plumed_formatter = load_formatter_from_file(formatfile, "PlumedFormatter", keyword_file=keyfile, input_name=name, hasload=found_load, broken=any(broken), actions=actions )

# Now generate html of input
html = '<div style="width: 100%; float:left">\n'
Expand Down
6 changes: 4 additions & 2 deletions PlumedToHTML/tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ def testBasicOutput(self) :
# Now run over all the inputs in the json
for item in tests["regtests"] :
with self.subTest(item=item):
out = PlumedToHTML.test_and_get_html( item["input"], "plinp" + str(item["index"]) )
actions = set({})
out = PlumedToHTML.test_and_get_html( item["input"], "plinp" + str(item["index"]), actions=actions )
print( item["input"] )
print( actions, item["actions"] )
data = {}
data["out"] = out
print( json.dumps( data, indent=3 ) )
self.assertTrue( out==item["output"] )
self.assertTrue( out==item["output"] and actions==set(item["actions"]) )

def testHeader(self) :
headerfilename = os.path.join(os.path.dirname(__file__),"../assets/header.html")
Expand Down
2 changes: 1 addition & 1 deletion PlumedToHTML/tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def testSimple(self) :
keyfile = plumed_info.stdout.strip() + "/json/syntax.json"

# Setup a plumed formatter
f = PlumedFormatter( keyword_file=keyfile, input_name="testout", hasload=False, broken=False )
f = PlumedFormatter( keyword_file=keyfile, input_name="testout", hasload=False, broken=False, actions=set({}) )

# Now run over all the inputs in the json
for item in tests["regtests"] :
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name='PlumedToHTML',
version='0.52',
version='0.53',
author="Gareth Tribello",
author_email="[email protected]",
description="A package for creating pretified HTML for PLUMED files",
Expand Down
Loading

0 comments on commit 4f6146f

Please sign in to comment.