Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ name: CI
on: [push, pull_request]

jobs:
check-code:
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
check: ["linting", "check-format"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Check ${{ matrix.check }}
run: python -m tox -e ${{ matrix.check }}
#this is setting up a new "test workflow" following the one we use for the plumed-testcenter
setup-plumed:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -117,7 +140,6 @@ jobs:
python -m pip install tox
- name: Run tests
run: |
#as now we do not want to be insulted by ruff, so only tests:
python -m tox -e tests

- name: Upload Coverage to Codecov
Expand Down
126 changes: 77 additions & 49 deletions check_inputs/create_inputs.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,113 @@
from pygments.styles import get_style_by_name
from pygments.formatters import HtmlFormatter
import os
import json
import PlumedToHTML

# Output css file for codehighlighting
ofile = open("codehilite.css", "w+")
ofile.write( HtmlFormatter(cssclass="codehilite", style='colorful').get_style_defs() )
ofile.write(HtmlFormatter(cssclass="codehilite", style="colorful").get_style_defs())
ofile.close()

print("<html>")
print('<meta charset="utf-8">')
print('<link rel="stylesheet" type="text/css" href="./codehilite.css">')
print('<meta name="viewport" content="width=device-width">')
print('<title>Example tutorial</title>')
print("<title>Example tutorial</title>")
print('<meta name="description" content="PLUMED website"/>')
print('<meta name="viewport" content="width=device-width, initial-scale=1">')
print('<meta name="theme-color" content="#157878">')
print('<link href=\'https://fonts.googleapis.com/css?family=Open+Sans:400,700\' rel=\'stylesheet\' type=\'text/css\'>')
print('<link rel="stylesheet" href="https://www.plumed.org//assets/css/style.css?v=9dd2bd3d9ee4823fb5d3485bda969afbaa1ba8d4">')
print('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">')
print('<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.18/b-1.5.6/b-flash-1.5.6/b-html5-1.5.6/datatables.min.css"/>')
print('<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.3.1/jszip-2.5.0/dt-1.10.18/b-1.5.6/b-flash-1.5.6/b-html5-1.5.6/datatables.min.css"/>')
print('<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>')
print('<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>')
print('<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.3.1/jszip-2.5.0/dt-1.10.18/b-1.5.6/b-flash-1.5.6/b-html5-1.5.6/datatables.min.js"></script>')
print(
"<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>"
)
print(
'<link rel="stylesheet" href="https://www.plumed.org//assets/css/style.css?v=9dd2bd3d9ee4823fb5d3485bda969afbaa1ba8d4">'
)
print(
'<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">'
)
print(
'<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.18/b-1.5.6/b-flash-1.5.6/b-html5-1.5.6/datatables.min.css"/>'
)
print(
'<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.3.1/jszip-2.5.0/dt-1.10.18/b-1.5.6/b-flash-1.5.6/b-html5-1.5.6/datatables.min.css"/>'
)
print(
'<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>'
)
print(
'<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>'
)
print(
'<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.3.1/jszip-2.5.0/dt-1.10.18/b-1.5.6/b-flash-1.5.6/b-html5-1.5.6/datatables.min.js"></script>'
)
print('<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>')
print('<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>')
print('</head>')
print('<body>')
print("</head>")
print("<body>")
print('<section class="page-header">')
print('<a href="https://github.com/plumed/plumed2"><img style="position:absolute; top:10px; right:100px; width:50px" src="https://www.plumed.org//Octocat.png" title="Get development version"></a>')
print('<a href="https://github.com/plumed/plumed2/releases/download/v2.8.0/plumed-2.8.0.tgz"><img style="position:absolute; top:10px; right:40px; width:40px" src="https://www.plumed.org//arrow.png" title="Get latest release"></a>')
print('<a class="site-title" href="http://www.plumed.org"><img width="220" src="pigeon-teacher.png"></a>')
print(
'<a href="https://github.com/plumed/plumed2"><img style="position:absolute; top:10px; right:100px; width:50px" src="https://www.plumed.org//Octocat.png" title="Get development version"></a>'
)
print(
'<a href="https://github.com/plumed/plumed2/releases/download/v2.8.0/plumed-2.8.0.tgz"><img style="position:absolute; top:10px; right:40px; width:40px" src="https://www.plumed.org//arrow.png" title="Get latest release"></a>'
)
print(
'<a class="site-title" href="http://www.plumed.org"><img width="220" src="pigeon-teacher.png"></a>'
)
print('<h1 class="project-name">PLUMED</h1>')
print('<h2 class="project-tagline">The community-developed PLUgin for MolEcular Dynamics</h2>')
print('</section>')
print(
'<h2 class="project-tagline">The community-developed PLUgin for MolEcular Dynamics</h2>'
)
print("</section>")
print('<section class="main-content">', flush=True)
# Putting this here You can see render the page while it is being generated
print( PlumedToHTML.get_html_header() )
print(PlumedToHTML.get_html_header())
f = open("./tdata/tests.json")
tests = json.load(f)
f.close()

for item in tests["regtests"] :
actions = set({})
out = PlumedToHTML.test_and_get_html( item["input"], "plinp" + str(item["index"]), actions=actions )

print(f"<h3>Input number {item['index']}</h3>")
#this visualizes the "from-to" and it is more clear to eye-check what is going on
print("<pre>")
print(item["input"])
print("</pre>")
print( out )
for item in tests["regtests"]:
actions = set({})
out = PlumedToHTML.test_and_get_html(
item["input"], "plinp" + str(item["index"]), actions=actions
)

print(f"<h3>Input number {item['index']}</h3>")
# this visualizes the "from-to" and it is more clear to eye-check what is going on
print("<pre>")
print(item["input"])
print("</pre>")
print(out)

f = open("./tdata/cltooltests.json")
tests = json.load(f)
f.close()

for item in tests["regtests"] :
out = PlumedToHTML.get_cltoolarg_html( item["input"], "clinp" + str(item["index"]), ("plumed",) )
#this visualizes the "from-to" and it is more clear to eye-check what is going on
print(f"<h3>CL tool input number {item['index']}</h3>")
print("<pre>")
print(item["input"])
print("</pre>")
print( out )
for item in tests["regtests"]:
out = PlumedToHTML.get_cltoolarg_html(
item["input"], "clinp" + str(item["index"]), ("plumed",)
)
# this visualizes the "from-to" and it is more clear to eye-check what is going on
print(f"<h3>CL tool input number {item['index']}</h3>")
print("<pre>")
print(item["input"])
print("</pre>")
print(out)

f = open("./tdata/clfiletests.json")
tests = json.load(f)
f.close()

for item in tests["regtests"] :
out = PlumedToHTML.get_cltoolfile_html( item["input"], "clinp" + str(item["index"]), ("plumed",) )
#this visualizes the "from-to" and it is more clear to eye-check what is going on
print(f"<h3>CL file input number {item['index']}</h3>")
print("<pre>")
print(item["input"])
print("</pre>")
print( out )
for item in tests["regtests"]:
out = PlumedToHTML.get_cltoolfile_html(
item["input"], "clinp" + str(item["index"]), ("plumed",)
)
# this visualizes the "from-to" and it is more clear to eye-check what is going on
print(f"<h3>CL file input number {item['index']}</h3>")
print("<pre>")
print(item["input"])
print("</pre>")
print(out)

print('</section>')
print('</body>')
print('</html>')
print("</section>")
print("</body>")
print("</html>")
41 changes: 22 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,31 @@ where = ["src"]
#we state which files we want to include per package
PlumedToHTML = ['assets/*.html']

[tool.ruff]
indent-width = 2

#this is not elegant, but having all the settings in a single file is cozier
[tool.tox]
legacy_tox_ini = """
[tox]
env_list =
tests
lint
requires = ["tox>=4.19"]
#enviroments run by simply calling "tox"
envlist=["format", "linting" , "tests"]

[testenv:tests]
deps = pytest
pytest-cov
commands = pytest --cov=PlumedToHTML --cov-report=term-missing
[tool.tox.env_run_base]
deps = ["pytest", "pytest-cov"]
commands = [[ "pytest", "tests", "--cov=PlumedToHTML", "--cov-report=term-missing"]]

[pytest]
testpaths =
tests
[tool.tox.env.linting]
skip_install = true
deps = ["ruff==0.9.6"]
commands = [["ruff", "check", "src/PlumedToHTML", "tests"]]

[testenv:lint]
[tool.tox.env.format]
skip_install = true
deps =
ruff==0.9.6
commands =
ruff check src/PlumedToHTML
ruff format src/PlumedToHTML --check
"""
deps = ["ruff==0.9.6"]
commands = [["ruff", "format", "src/PlumedToHTML", "tests"]]

[tool.tox.env.check-format]
skip_install = true
deps = ["ruff==0.9.6"]
commands = [["ruff", "format", "--check", "src/PlumedToHTML", "tests"]]

43 changes: 22 additions & 21 deletions src/PlumedToHTML/PlumedCLFileLexer.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import Text, Keyword, Name, String, Comment
from pygments.lexer import RegexLexer, bygroups
from pygments.token import Text, Keyword, Name, Comment


class PlumedCLFileLexer(RegexLexer):
name = 'plumedclfile'
aliases = ['plumedclfile']
filenames = ['*.plmd']
name = "plumedclfile"
aliases = ["plumedclfile"]
filenames = ["*.plmd"]

tokens = {
'root': [
# Find the start of a shortcut with a nested default
(r'#NODEFAULT plumed\n',Comment.Special),
# Find the start of a default section
(r'#DEFAULT plumed\n',Comment.Special),
# Find the end of a default section
(r'#ENDDEFAULT plumed\n',Comment.Special),
# The name of the tool that this is an input file for
(r'(#TOOL=\s*)(\S+\b)',bygroups( Comment, Keyword )),
# The lines of instruction for the file
(r'(\S+\b)(\s+)(.+$)',bygroups(Name.Attribute, Text, Text)),
# Find any left over white space
(r'\s+',Text)
]
}
tokens = {
"root": [
# Find the start of a shortcut with a nested default
(r"#NODEFAULT plumed\n", Comment.Special),
# Find the start of a default section
(r"#DEFAULT plumed\n", Comment.Special),
# Find the end of a default section
(r"#ENDDEFAULT plumed\n", Comment.Special),
# The name of the tool that this is an input file for
(r"(#TOOL=\s*)(\S+\b)", bygroups(Comment, Keyword)),
# The lines of instruction for the file
(r"(\S+\b)(\s+)(.+$)", bygroups(Name.Attribute, Text, Text)),
# Find any left over white space
(r"\s+", Text),
]
}
Loading