Permalink
Browse files

Merge pull request #12537 from aeslaughter/moosetree

Fixes to MooseDocs API changes
  • Loading branch information...
rwcarlsen committed Nov 27, 2018
2 parents b1536f0 + 13e04ab commit 49c4df01f27fc71ac3a1433d5b9090b92a5f3627
@@ -116,6 +116,7 @@ def getSyntaxTree(self, page):
data = self._tree_data.get(page.uid, None)
if data is not None:
data = data.copy()
return data
def getMetaData(self, page, key):
@@ -334,6 +335,9 @@ class ParallelPipe(Executioner):
Parallel execution that performs tokenization and uses a multiprocessing.Pipe to
send the data to the main process. I then starts a new parallel process for
rendering, using the data populated from the first step.
TODO: This isn't working correct, but the ParallelBarrier seams to be the
fastest, so I will need to come back to this at some time.
"""
PROCESS_FINISHED = -1
@@ -398,6 +402,13 @@ class ParallelDemand(Executioner):
"""
Parallel execution that does not perform any communication and re-builds syntax trees
within the getSyntaxTree method.
NOTE: This doesn't work yet. The configuration changes get screwed up when the
getSyntaxTree method is called from another page. I need to re-think the configuration
handling to make this work.
Fixing this is not a high priority, because the ParallelBarrier seems to be the fastest.
"""
def __init__(self, *args, **kwargs):
super(ParallelDemand, self).__init__(*args, **kwargs)
@@ -423,7 +434,7 @@ def __target(self, nodes):
for node in nodes:
ast, meta = self.tokenize(node)
self._tree_data[node.uid] = ast.copy()
self._tree_data[node.uid] = ast
self._meta_data[node.uid] = meta
self.render(node, ast, meta)
@@ -251,8 +251,8 @@ def defaultConfig():
def __init__(self, *args, **kwargs):
HTMLRenderer.__init__(self, *args, **kwargs)
self.__navigation = None # Cache for navigation pages
self.__index = False # page index created
self.__navigation = None # cache for navigation pages
self.__index = False # page index created
self.addCSS('materialize', "contrib/materialize/materialize.min.css",
media="screen,projection")
@@ -169,7 +169,7 @@ def findPages(self, arg):
if items is None:
func = lambda p: p.local.endswith(arg)
items = [page for page in self.__content if func(page)]
self.__page_cache[arg] = items
#self.__page_cache[arg] = items
else:
items = [page for page in self.__content if arg(page)]
@@ -99,7 +99,6 @@ def __init__(self, translator, options, *args, **kwargs):
def build(self):
"""Build the necessary pages based on the current filepath."""
print 'HERE:', self.filepath
# Locate the page to be translated
page = self._getPage(self.filepath)
@@ -114,7 +113,6 @@ def build(self):
if page.uid in uids:
nodes.append(node)
print 'PAGE:', nodes
self._translator.execute(self._options.num_threads, nodes)
def _getPage(self, source):
@@ -222,3 +220,5 @@ def main(options):
watcher = MooseDocsWatcher(translator, options)
server = livereload.Server(watcher=watcher)
server.serve(root=translator['destination'], host=options.host, port=options.port)
return 0
@@ -50,12 +50,13 @@ def main(options):
"""./moosedocs check"""
translator, _ = common.load_config(options.config)
check(translator,
dump=options.dump,
update=options.update,
generate=options.generate,
object_prefix=options.object_prefix,
syntax_prefix=options.syntax_prefix)
err = check(translator,
dump=options.dump,
update=options.update,
generate=options.generate,
object_prefix=options.object_prefix,
syntax_prefix=options.syntax_prefix)
return err
def check(translator,
dump=False,
@@ -77,7 +78,7 @@ def check(translator,
if not extension.active:
LOG.info("Syntax is disabled, skipping the check.")
return
return 0
if app_syntax is None:
msg = "Failed to locate AppSyntaxExtension for the given configuration."
@@ -111,6 +112,8 @@ def check(translator,
syntax.ObjectNode.__name__,
syntax.SyntaxNode.__name__)
return 0
def _check_object_node(node, app_name, generate, update, prefix):
"""
Check that required pages for supplied ObjectNode (i.e., MooseObject/Action).
@@ -118,6 +118,6 @@ def main(options):
for fname in files:
_, ext = os.path.splitext(fname)
if ext in extensions:
errno = compare(os.path.join(root, fname), out_dir, gold_dir, options.update_gold)
errno += compare(os.path.join(root, fname), out_dir, gold_dir, options.update_gold)
sys.exit(errno)
return errno
@@ -21,7 +21,13 @@ def report_error(message, page, info, traceback=None, prefix=u'ERROR'):
traceback: The traceback (should be a string from traceback.format_exc())
"""
title = '{}: {}'.format(prefix, message)
filename = mooseutils.colorText('{}:{}\n'.format(page.source, info.line), 'RESET')
src = mooseutils.colorText(box(info[0], line=info.line, width=100), 'LIGHT_CYAN')
if info is not None:
src = mooseutils.colorText(box(info[0], line=info.line, width=100), 'LIGHT_CYAN')
line = info.line
else:
src = ''
line = u'?'
filename = mooseutils.colorText('{}:{}\n'.format(page.source, line), 'RESET')
trace = u'\n' + mooseutils.colorText(traceback, 'GREY') if traceback else ''
return u'\n{}\n{}{}{}\n'.format(title, filename, src, trace)
@@ -394,7 +394,7 @@ def createHeading(self, parent, page, **kwargs):
if self.settings['heading'] == u'AUTO':
h = ['Objects', 'Actions', 'Subsystems']
idx = [self.settings['objects'], self.settings['actions'], self.settings['subsystems']]
names = [h[i] for i in idx if i]
names = [h[i] for i, v in enumerate(idx) if v]
if len(names) == 1:
self.settings['heading'] = u'Available {}'.format(*names)
elif len(names) == 2:
@@ -434,6 +434,7 @@ def defaultSettings():
settings = SyntaxListCommand.defaultSettings()
settings['group'] = (None, "The group (app) to limit the complete syntax list.")
settings['level'] = (2, "Beginning heading level.")
settings['heading'] = (None, settings['heading'][1])
return settings
def createTokenFromSyntax(self, parent, info, page, obj):
@@ -49,6 +49,13 @@ def extend(self, reader, renderer):
renderer.add('AutoLink', RenderAutoLink())
#def postTokenize(self, ast, page, meta, reader):
# if page.local == 'mega.menu.md':
# print 'AUTOLINK'
# print ast
def createTokenHelper(key, parent, info, page, use_key_in_modal=False):
match = PAGE_LINK_RE.search(info[key])
bookmark = match.group('bookmark')[1:] if match.group('bookmark') else u''
@@ -110,22 +117,22 @@ def createHTMLHelper(self, parent, token, page, desired):
if bookmark:
url += '#{}'.format(bookmark)
link = core.Link(None, url=url)
link = core.Link(None, url=url, info=token.info)
if len(token.children) == 0:
head = heading.find_heading(self.translator, desired)
head = heading.find_heading(self.translator, desired, bookmark)
if head is not None:
for child in head:
child.parent = link
else:
tokens.String(link, content=url)
else:
for child in token:
else:
for child in token.copy():
child.parent = link
self.renderer.render(parent, link, page)
return parent
return None
class RenderLocalLink(RenderLinkBase):
"""
@@ -50,24 +50,28 @@ def defaultSettings():
def createToken(self, parent, info, page):
location = self.settings['location']
tree = dict()
tree[(u'',)] = core.UnorderedList(parent, browser_default=False)
func = lambda p: p.local.startswith(location) and isinstance(p, pages.Directory)
for node in self.translator.findPages(func):
key = tuple(node.local.strip(os.sep).replace(location, '').split(os.sep))
if key not in tree:
col = Collapsible(tree[key[:-1]], summary=key[-1])
li = core.ListItem(col, class_='moose-source-item', tooltip=False)
tree[key] = core.UnorderedList(li, browser_default=False)
location = self.settings['location']
func = lambda p: p.local.startswith(location) and isinstance(p, pages.Source)
for node in self.translator.findPages(func):
dname = os.path.dirname(node.local).strip(os.sep)
key = tuple(dname.replace(location, '').split(os.sep))
nodes = self.translator.findPages(func)
for node in nodes:
key = tuple(node.local.strip(os.sep).replace(location, '').split(os.sep))[:-1]
for i in xrange(1, len(key) + 1):
k = key[:i]
if k not in tree:
col = Collapsible(tree[k[:-1]], summary=k[-1])
li = core.ListItem(col, class_='moose-source-item', tooltip=False)
tree[k] = core.UnorderedList(li, browser_default=False)
for node in nodes:
key = tuple(node.local.strip(os.sep).replace(location, '').split(os.sep))[:-1]
loc = node.relativeDestination(page)
li = core.ListItem(tree[key])
core.Link(li, url=loc, string=node.name, class_='moose-source-item', tooltip=False)
return parent
class AtoZCommand(command.CommandComponent):
@@ -358,7 +358,7 @@ def createToken(self, parent, info, page):
elif tok == u'~':
return Strikethrough(parent)
elif tok == u'`':
return Monospace(parent, code=info['inline'], recursive=False)
return Monospace(parent, content=info['inline'], recursive=False)
####################################################################################################
# Rendering.
@@ -54,7 +54,7 @@ def extend(self, reader, renderer):
self.requires(core, heading)
menu = self.get('menu')
if (menu is None) and (renderer.get('navigation', None) is not None):
if (not menu) and (renderer.get('navigation', None) is not None):
msg = "The navigation setting in the MaterializeRenderer is deprecated, " \
"please update your code to use the 'menu' setting within the " \
"MooseDocs.extensions.navigation extension."
@@ -416,7 +416,11 @@ def _addMegaMenu(self, parent, filename, page):
wrap = html.Tag(div, 'div', class_='moose-mega-menu-wrapper')
node = self.translator.findPage(filename)
ast = self.translator.getSyntaxTree(node) #pylint: disable=no-member
self.translator.renderer.render(wrap, ast, page) #pylint: disable=no-member
if ast is None:
print page.local
else:
self.translator.renderer.render(wrap, ast, page) #pylint: disable=no-member
def _buildDropdown(self, parent, page, tag_id, items):
"""Creates sublist for dropdown navigation."""
@@ -0,0 +1,15 @@
#pylint: disable=missing-docstring
#* This file is part of the MOOSE framework
#* https://www.mooseframework.org
#*
#* All rights reserved, see COPYRIGHT for full restrictions
#* https://github.com/idaholab/moose/blob/master/COPYRIGHT
#*
#* Licensed under LGPL 2.1, please see LICENSE for details
#* https://www.gnu.org/licenses/lgpl-2.1.html
import logging
from MooseDocs.extensions import common
LOG = logging.getLogger(__name__)
def make_extension(**kwargs):
LOG.warning("The panoptic extension has been renamed, use MooseDocs.extensions.common.")
return common.make_extension(**kwargs)
@@ -49,18 +49,18 @@ def run():
log.init_logging(getattr(logging, options.level))
if options.command == 'build':
build.main(options)
errno = build.main(options)
elif options.command == 'check':
check.main(options)
errno = check.main(options)
elif options.command == 'verify':
verify.main(options)
errno = verify.main(options)
critical = log.MooseDocsFormatter.COUNTS['CRITICAL'].value
errors = log.MooseDocsFormatter.COUNTS['ERROR'].value
warnings = log.MooseDocsFormatter.COUNTS['WARNING'].value
print 'CRITICAL:{} ERROR:{} WARNING:{}'.format(critical, errors, warnings)
if critical or errors:
if critical or errors or (errno != 0):
return 1
return 0
Oops, something went wrong.

0 comments on commit 49c4df0

Please sign in to comment.