def loadDocumentation(path, name, *apps): assert path try: if public.verbose: log_utility.info('Loading documentation "%s"...' % path) # Prepare the documentation registrar and namespace wrappers and exec the module # The last app passed in is considered the primary one appPrimary = apps[-1] docRegistrar = doc.Registrar(appPrimary.name) wrappers = [] syms = {} for app in apps: wrappers.append(NamespaceWrapper(app, name, path, docRegistrar, False)) syms[app.namespace] = wrappers[-1] doc.setStrucTextSymbols(syms) # Documentation in non-function-bearing modules is added to the "guide" if appPrimary.namespace == public.program.namespace: props = {'all': name, 'guide': name} else: props = {} doc.parserStrucText.parse(open(path).read()) node = doc.parserStrucText.take() node.setProp('module', name) docRegistrar.add(node) docRegistrar.register() except Exception, e: log_utility._tracebackException('Failed to load "%s"' % path, e, 0, 0, True)
def loadScript(path, name, isCore, *apps): assert path try: if public.verbose: log_utility.info('Loading script "%s"...' % path) # Prepare the documentation registrar and namespace wrappers and exec the module # The last app passed in is considered the primary one appPrimary = apps[-1] docRegistrar = doc.Registrar(appPrimary.name) wrappers = [] syms = {} for app in apps: wrappers.append(NamespaceWrapper(app, name, path, docRegistrar, isCore)) syms[app.namespace] = wrappers[-1] doc.setStrucTextSymbols(syms) execfile(path, syms) # Warn about classes flagged for export (should be in a type module) # Export newly-discovered classes of appropriate ancestry namesOrig = [app.namespace for app in apps] for nameNew in syms: if nameNew not in namesOrig and inspect.isclass(syms[nameNew]): for exportedClass in exportedClasses: sym = syms[nameNew] if issubclass(sym, exportedClass): if public.verbose: log_utility.info('Register type "%s.%s"' % (appPrimary.namespace, nameNew)) appPrimary.types[nameNew] = sym # Create function objects for empty decorators (invoked without parens). # Register all discovered functions and track duplicates. if appPrimary.exports.has(name): export = appPrimary.exports.get(name) else: export = appPrimary.exports.add(name, path, None) global duplicateFunctions for wrapper in wrappers: for decorator in wrapper._decoExport: if decorator.function is None: func = decorator.args[0] decorator.args = decorator.args[1:] decorator._register(func) if decorator.isCore: if public.verbose: log_utility.info('Register core function "%s"' % decorator.function.nameShort) global symsCore if decorator.function.nameShort not in symsCore: symsCore[decorator.function.nameShort] = decorator.function else: if public.verbose: log_utility.info('Register function "%s.%s"' % (appPrimary.namespace, decorator.function.name)) if not export.addFunction(decorator.function): duplicateFunctions.append(DuplicateFunction(decorator.function)) # Register documentation if export.countFunctions() > 0: # Documentation in function-bearing modules is added to the "reference" if appPrimary.namespace == public.program.namespace: props = {'all': name, 'reference': name} else: props = {} # For consistent TOC sorting need core to be None, rather than False. if isCore: nodeModule = docRegistrar.wrap( form = 'wrapper', heading = 'Module: (%s)' % name, core = name, **props ) else: nodeModule = docRegistrar.wrap( form = 'wrapper', heading = 'Module: %s' % name, module = name, toc = True, **props ) nodesBody = [] for function in export.iterFunctionsSorted(): if not function.isInternal: nodesDoc = [] if function.doc: nodesDoc.append(function.doc) for wrapper in wrappers: nodesDoc.append(wrapper._nodesFunc.get(function.nameShort, [])) nodesBody.append( doc.Node( form = 'wrapper', heading = 'Function: %s' % function.getProto(), content = FunctionNode(function, nodesDoc), function = function.name, toc = True, ) ) nodeModule.add(doc.Node(content = nodesBody)) else: # Documentation in non-function-bearing modules is added to the "guide" if appPrimary.namespace == public.program.namespace: props = {'all': name, 'guide': name} else: props = {} if isCore: docRegistrar.wrap(form = 'wrapper', core = name, **props) else: docRegistrar.wrap(form = 'wrapper', module = name, **props) docRegistrar.register() except public.ExcLoad, e: log_utility._tracebackException('Failed to load "%s"' % path, e, 1, 1, False)