Skip to content

Commit

Permalink
Added option to reduce the amount of time PlumedToHTML spends checkin…
Browse files Browse the repository at this point in the history
…g output html
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed May 20, 2024
1 parent 8b4599a commit 8369007
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions PlumedToHTML/PlumedToHTML.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def manage_incomplete_inputs( inpt ) :
return complete, incomplete
return inpt, ""

def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, actions=set({}) ) :
def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxchecks=None, actions=set({}) ) :
"""
Generate the html representation of a PLUMED input file
Expand Down Expand Up @@ -259,15 +259,23 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, actio

# Check everything that is marked as a clickable value has something that will appear
# when you click it
soup = BeautifulSoup( html, "html.parser" )
nchecks, soup = 0, BeautifulSoup( html, "html.parser" )
for val in soup.find_all("b") :
if "onclick" in val.attrs.keys() :
vallabels = val.attrs["onclick"].split("\"")
nchecks, vallabels = nchecks + 1, val.attrs["onclick"].split("\"")
if maxchecks is not None and nchecks>maxchecks :
warnings.warn("Only checked the html for the first " + str(maxchecks) + " of the " + str(len(soup.find_all("b"))) + " labels in input file to reduce computational expense. The output is most likely fine but has not been checked as carefully as inputs with fewer values")
break
if not soup.find("span", {"id": vallabels[3]}) : warnings.warn("Problems with generated as label hidden box for label " + vallabels[3] + " is missing")
if not soup.find("div", {"id": "value_details_" + vallabels[1]}) : raise Exception("Generated html is invalid as there is no place to show data for " + vallabell[1])

# Now check the togglers
nchecks = 0
for val in soup.find_all(attrs={'class': 'toggler'}) :
nchecks = nchecks + 1
if maxchecks is not None and nchecks>maxchecks :
warnings.warn("Only checked the html for the first " + str(maxchecks) + " of the " + str(len(soup.find_all(attrs={'class': 'toggler'}))) + " shortcuts in the input file to reduce computational expense. The output is most likely fine but has not been checked as carefully as inputs with fewer shortcuts")
break
if "onclick" in val.attrs.keys() :
switchval = val.attrs["onclick"].split("\"")[1]
if not soup.find("span",{"id": switchval + "_long"} ) : raise Exception("Generated html is invalid as could not find " + switchval + "_long")
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.69',
version='0.70',
author="Gareth Tribello",
author_email="[email protected]",
description="A package for creating pretified HTML for PLUMED files",
Expand Down

0 comments on commit 8369007

Please sign in to comment.