Skip to content

Commit fe96cd3

Browse files
Gareth Aneurin TribelloGareth Aneurin Tribello
authored andcommitted
cltool formatting can now deal with command line inputs that use plumed-runtime and mpirun
1 parent ed2be7d commit fe96cd3

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

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.109"
8+
version = "0.110"
99
description = "A package for creating prettified HTML for PLUMED files"
1010
authors = [{ name = "Gareth Tribello", email = "[email protected]" }]
1111
maintainers = [{ name = "Daniele Rapetti", email = "[email protected]" }]

src/PlumedToHTML/PlumedCLtoolLexer.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pygments.lexer import RegexLexer, bygroups, include
2-
from pygments.token import Text, Keyword, Name, String, Comment
2+
from pygments.token import Text, Keyword, Name, String, Comment, Literal
33

44
class PlumedCLtoolLexer(RegexLexer):
55
name = 'plumedcltool'
@@ -14,8 +14,16 @@ class PlumedCLtoolLexer(RegexLexer):
1414
(r'#DEFAULT plumed\n',Comment.Special),
1515
# Find the end of a default section
1616
(r'#ENDDEFAULT plumed\n',Comment.Special),
17+
# Find commands that use MPI and that take an input file
18+
(r'(^\s*mpirun\s+-np)(\s+[0-9]+\s+)(plumed)(\s+)(\S+\b)(\s*<\s*)(\S+\b)', bygroups(Literal, Text, String, Text, Keyword, Text, Name.Decorator)),
19+
# With plumed-runtime and MPI
20+
(r'(^\s*mpirun\s+-np)(\s+[0-9]+\s+)(plumed-runtime)(\s+)(\S+\b)', bygroups(Literal, Text, String, Text, Keyword)),
21+
# Find commands that use MPI
22+
(r'(^\s*mpirun\s+-np)(\s+[0-9]+\s+)(plumed)(\s+)(\S+\b)', bygroups(Literal, Text, String, Text, Keyword)),
1723
# Find commands that take an input file
1824
(r'(^\s*plumed)(\s+)(\S+\b)(\s*<\s*)(\S+\b)', bygroups(String, Text, Keyword, Text, Name.Decorator)),
25+
# Find the name of the command if we are using plumed-runtime
26+
(r'(^\s*plumed-runtime)(\s+)(\S+\b)', bygroups(String, Text, Keyword)),
1927
# Find the name of the command
2028
(r'(^\s*plumed)(\s+)(\S+\b)', bygroups(String, Text, Keyword)),
2129
# Deals with keywords with equals sign

src/PlumedToHTML/PlumedFormatter.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pygments.lexers.c_cpp import CppLexer
55
from pygments.formatters import HtmlFormatter
66
from requests.exceptions import InvalidJSONError
7+
import re
78
import html
89
import json
910

@@ -61,8 +62,11 @@ def format(self, tokensource, outfile):
6162
# Non PLUMED stuff
6263
outfile.write( value )
6364
elif ttype==Literal :
65+
# mpirun -np for command line tools
66+
if re.search("mpirun\s+-np", value ) :
67+
outfile.write('<span class="plumedtooltip">' + value + '<span class="right">Run instances of PLUMED on this number of MPI processes<i></i></span></span>')
6468
# __FILL__ for incomplete values
65-
if( value=="__FILL__" ) :
69+
elif( value=="__FILL__" ) :
6670
outfile.write('<span style="background-color:yellow">__FILL__</span>')
6771
# This is for vim syntax expression
6872
elif "vim:" in value :
@@ -188,6 +192,7 @@ def format(self, tokensource, outfile):
188192
elif ttype==String or ttype==String.Double :
189193
# Labels of actions
190194
if not self.broken and action!="" and label!="" and label!=value.strip() : raise Exception("label for " + action + " is not what is expected. Is " + label + " should be " + value.strip() )
195+
elif value.strip()=="plumed-runtime" : label = "plumed"
191196
elif label=="" : label = html.escape( value.strip() )
192197
valtype = "mix"
193198
if label in self.valuedict.keys() :
@@ -263,7 +268,7 @@ def format(self, tokensource, outfile):
263268
# Store name of action in set that contains all action names
264269
self.actions.add(action)
265270
if default_state!=0 or shortcut_state==1 :
266-
if label!="" and label!=act_label : raise Exception("mismatched label and act_label for shortcut/default")
271+
if label!="" and label!=act_label : raise Exception("mismatched label and act_label for shortcut/default label=" + label + " act_label=" + act_label )
267272
if notooltips :
268273
outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">This action is not part of PLUMED and was included by using a LOAD command <a href="' + self.keyword_dict["LOAD"]["hyperlink"] + '" style="color:green">More details</a><i></i></span></span>')
269274
elif shortcut_state==1 and default_state==1 :

src/PlumedToHTML/PlumedToHTML.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,20 @@ def get_cltoolarg_html( inpt, name, plumedexe ) :
231231
"""
232232
# Get the cltool that we are using
233233
pl, tool = inpt.split()[0], inpt.split()[1]
234-
if pl!="plumed" :
235-
raise Exception("first word in the command should be plumed")
234+
if re.search("^mpirun\s+-np\s+[0-9]+\s+plumed",inpt) :
235+
tool = inpt.split()[4]
236+
elif pl!="plumed" and pl!="plumed-runtime" :
237+
raise Exception("first word in the command should be plumed or plumed-runtime")
236238
# Create the lexer that will generate the pretty plumed input
237239
lexerfile = os.path.join(os.path.dirname(__file__),"PlumedCLtoolLexer.py")
238240
plumed_lexer = load_lexer_from_file(lexerfile, "PlumedCLtoolLexer" )
239241
# Get the plumed syntax file
240242
defstr, keyword_dict = inpt, getPlumedSyntax( plumedexe )
241243
# Find the default values in the dictionary
242-
if inpt.split()[2]!="-h" and inpt.split()[2]!="--help" and keyword_dict["cltools"][tool]["inputtype"]!="file" :
244+
ishelp = False
245+
if len(inpt.split())>2 and (inpt.split()[2]=="-h" or inpt.split()[2]=="--help") :
246+
ishelp = True
247+
if not ishelp and keyword_dict["cltools"][tool]["inputtype"]!="file" :
243248
for key, dicti in keyword_dict["cltools"][tool]["syntax"].items() :
244249
if "default" not in dicti.keys() or dicti["default"]=="off" or key in inpt : continue
245250
defstr += " " + key + " " + dicti["default"]
@@ -669,6 +674,7 @@ def processMarkdownString( inp, filename, plumedexe, plumed_names, actions, ofil
669674
cltoolregexps, clfileregexps = [], []
670675
for key, data in plumed_syntax["cltools"].items() :
671676
cltoolregexps.append("plumed\s+" + key )
677+
cltoolregexps.append("plumed-runtime\s+" + key )
672678
if data["inputtype"]=="file" :
673679
clfileregexps.append( "#TOOL\s*=\s*" + key )
674680

tdata/cltooltests.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@
3535
"index": 5,
3636
"output": "<div class=\"highlight\"><pre><span></span><span class=\"s\">plumed</span> <span class=\"k\">simplemd</span> &lt; <span class=\"nd\">in</span>\n</pre></div>\n",
3737
"tooltips": ["simplemd", "in"]
38-
}
38+
},
39+
{
40+
"input": "plumed-runtime benchmark --kernel /path/to/lib/libplumedKernel.so",
41+
"index": 6,
42+
"output": "<div class=\"highlight\"><pre><span></span><span class=\"s\">plumed-runtime</span> <span class=\"k\">benchmark</span> <span class=\"na\">--kernel</span> /path/to/lib/libplumedKernel.so\n</pre></div>\n",
43+
"tooltips": ["benchmark", "--kernel", "benchmark", "--kernel", "--plumed", "--natoms", "--nsteps", "--maxtime", "--sleep", "--atom-distribution"]
44+
},
45+
{
46+
"input": "plumed benchmark",
47+
"index": 7,
48+
"output": "<div class=\"highlight\"><pre><span></span><span class=\"s\">plumed</span> <span class=\"k\">benchmark</span>\n</pre></div>\n",
49+
"tooltips": ["benchmark", "benchmark", "--plumed", "--kernel", "--natoms", "--nsteps", "--maxtime", "--sleep", "--atom-distribution"]
50+
},
51+
{
52+
"input": "mpirun -np 4 plumed-runtime benchmark",
53+
"index": 8,
54+
"output": "<div class=\"highlight\"><pre><span></span><span class=\"l\">mpirun -np</span> 4 <span class=\"s\">plumed-runtime</span> <span class=\"k\">benchmark</span>\n</pre></div>\n",
55+
"tooltips": ["mpirun -np", "benchmark", "mpirun -np", "benchmark", "--plumed", "--kernel", "--natoms", "--nsteps", "--maxtime", "--sleep", "--atom-distribution"]
56+
}
3957
]
4058
}

0 commit comments

Comments
 (0)