99from pathlib import Path
1010from datetime import date
1111from bs4 import BeautifulSoup
12+ from contextlib import contextmanager
1213from PlumedToHTML import processMarkdown , processMarkdownString , get_javascript , get_css
1314import networkx as nx
1415
1516PLUMED = "plumed"
1617
18+ @contextmanager
19+ def cd (newdir ):
20+ prevdir = os .getcwd ()
21+ os .chdir (os .path .expanduser (newdir ))
22+ try :
23+ yield
24+ finally :
25+ os .chdir (prevdir )
26+
1727def getActionDocumentationFromPlumed () :
1828 docs = {}
1929 for file in glob .glob ("../src/*/*.cpp" ) :
@@ -326,7 +336,7 @@ def getModuleDictionary( modname ) :
326336 return {"name" : modname , "authors" : "authors" , "description" : "Information about the module" , "dois" : [] }
327337
328338def createModulePage ( version , modname , neggs , nlessons , plumed_syntax , broken_inputs ) :
329- with open ( "docs/ module_" + modname + ".md" , "w" ) as f :
339+ with open ( "module_" + modname + ".md" , "w" ) as f :
330340 f .write ("# [Module](modules.md): " + modname + "\n \n " )
331341 f .write ("| Description | Usage |\n " )
332342 f .write ("|:--------|:--------:|\n " )
@@ -436,7 +446,7 @@ def createCLToolPage( version, tool, value, plumeddocs, broken_inputs, undocumen
436446 if undoc > 0 : undocumented_keywords .append ( ["<a href=\" ../" + action + "\" >" + action + "</a>" , value ["module" ]] )
437447
438448def createActionPage ( version , action , value , plumeddocs , neggs , nlessons , broken_inputs , undocumented_keywords , noexamples , nodocs ) :
439- with open ( "docs/" + action + ".md" , "w" ) as f :
449+ with open ( action + ".md" , "w" ) as f :
440450 hasatoms , hasargs = False , False
441451 for key , docs in value ["syntax" ].items () :
442452 if key == "output" : continue
@@ -508,9 +518,9 @@ def createActionPage( version, action, value, plumeddocs, neggs, nlessons, broke
508518 ninp , nfail = 0 , 0
509519 f .write ("## Further details and examples \n " )
510520 if action in plumeddocs .keys () :
511- if os .path .isfile ("../src/" + value ["module" ] + "/module.yml" ) :
521+ if os .path .isfile ("../../ src/" + value ["module" ] + "/module.yml" ) :
512522 actions = set ()
513- ninp , nf = processMarkdownString ( plumeddocs [action ], "docs/" + action + ".md" , (PLUMED ,), (version ,), actions , f , ghmarkdown = False )
523+ ninp , nf = processMarkdownString ( plumeddocs [action ], action + ".md" , (PLUMED ,), (version ,), actions , f , ghmarkdown = False )
514524 if nf [0 ]> 0 : broken_inputs .append ( ["<a href=\" ../" + action + "\" >" + action + "</a>" , str (nf [0 ])] )
515525 else :
516526 f .write ("Text from manual goes here \n " )
@@ -587,7 +597,8 @@ def createActionPage( version, action, value, plumeddocs, neggs, nlessons, broke
587597 actions = set ()
588598 for page in glob .glob ("*.md" ) :
589599 shutil .copy ( page , "docs/" + page )
590- ninp , nf = processMarkdown ( "docs/" + page , (PLUMED ,), (version ,), actions , ghmarkdown = False )
600+ with cd ("docs" ) :
601+ ninp , nf = processMarkdown ( page , (PLUMED ,), (version ,), actions , ghmarkdown = False )
591602 if nf [0 ]> 0 : broken_inputs .append ( ["<a href=\" ../" + page .replace (".md" ,"" ) + "\" >" + page + "</a>" , str (nf [0 ])] )
592603 if os .path .exists ("docs/colvar" ) : os .remove ("docs/colvar" ) # Do this with Plumed2HTML maybe
593604
@@ -600,7 +611,8 @@ def createActionPage( version, action, value, plumeddocs, neggs, nlessons, broke
600611 if key in nest_map .keys () : neggs = nest_map [key ]
601612 if key in school_map .keys () : nlessons = school_map [key ]
602613 print ("Building action page" , key )
603- createActionPage ( version , key , value , plumeddocs , neggs , nlessons , broken_inputs , undocumented_keywords , noexamples , nodocs )
614+ with cd ("docs" ) :
615+ createActionPage ( version , key , value , plumeddocs , neggs , nlessons , broken_inputs , undocumented_keywords , noexamples , nodocs )
604616 alink = "<a href=\" ../" + key + "\" >" + key + "</a>"
605617 tabledata .append ( [alink , str (value ["description" ])] )
606618 # Create the page with the list of actions
@@ -638,7 +650,8 @@ def createActionPage( version, action, value, plumeddocs, neggs, nlessons, broke
638650 mod_dict = getModuleDictionary ( module )
639651 moduletabledata .append ( [mlink , mod_dict ["description" ], mod_dict ["authors" ], getModuleType (module ) ] )
640652 print ("Building module page" , module )
641- createModulePage ( version , module , value ["neggs" ], value ["nlessons" ], plumed_syntax , broken_inputs )
653+ with cd ("docs" ) :
654+ createModulePage ( version , module , value ["neggs" ], value ["nlessons" ], plumed_syntax , broken_inputs )
642655 if not os .path .exists ("../src/" + module + "/module.md" ) or not os .path .exists ("../src/" + module + "/module.yml" ) :
643656 nodocs .append (["<a href=\" ../module_" + module + "\" >" + module + "</a>" , "module" ])
644657 # And the page with the list of modules
0 commit comments