def visit_ClassDef(self, node): """This executes every time a class definition is parsed.""" fullname = '.'.join([self.modpath, node.name]) self.localnames[node.name] = fullname bases = [_to_str(b) for b in node.bases if b is not None] bvisitor = _ClassBodyVisitor() bvisitor.visit(node) bases = [self.localnames.get(b, b) for b in bases if b is not None] self.classes[fullname] = ClassInfo(fullname, self.fname, bases, bvisitor.metadata, node.decorator_list) self.tree_analyser.class_map[fullname] = self.classes[fullname] undef_bases = [ b for b in bases if b not in self.classes and not hasattr(__builtin__, b) ] while undef_bases: base = undef_bases.pop() cinfo = self.tree_analyser.find_classinfo(base) if cinfo is None: parts = base.rsplit('.', 1) if len(parts ) == 1: # no dot, so maybe it came in with a '*' import trymods = self.starimports[::-1] basename = base else: trymods = [parts[0]] basename = parts[1] for modname in trymods: excluded = False for m in self.tree_analyser.mod_excludes: if m == modname or modname.startswith(m + '.'): excluded = True break if excluded: continue fpath = find_module(modname) if fpath is not None: fanalyzer = self.tree_analyser.analyze_file(fpath) if '.' not in base: trybase = '.'.join([modname, base]) else: trybase = base if trybase in fanalyzer.classes: break elif basename in fanalyzer.localnames: newname = fanalyzer.localnames[basename] self.tree_analyser.class_map[trybase] = newname if newname not in self.tree_analyser.class_map and \ newname not in self.unresolved_classes: undef_bases.append(newname) break else: self.unresolved_classes.add(base)
def visit_ClassDef(self, node): """This executes every time a class definition is parsed.""" fullname = '.'.join([self.modpath, node.name]) self.localnames[node.name] = fullname bases = [_to_str(b) for b in node.bases] bvisitor = _ClassBodyVisitor() bvisitor.visit(node) bases = [self.localnames.get(b, b) for b in bases] self.classes[fullname] = ClassInfo(fullname, self.fname, bases, bvisitor.metadata, node.decorator_list) self.tree_analyser.class_map[fullname] = self.classes[fullname] undef_bases = [b for b in bases if b not in self.classes and not hasattr(__builtin__, b)] while undef_bases: base = undef_bases.pop() cinfo = self.tree_analyser.find_classinfo(base) if cinfo is None: parts = base.rsplit('.', 1) if len(parts) == 1: # no dot, so maybe it came in with a '*' import trymods = self.starimports[::-1] basename = base else: trymods = [parts[0]] basename = parts[1] for modname in trymods: excluded = False for m in self.tree_analyser.mod_excludes: if m == modname or modname.startswith(m+'.'): excluded = True break if excluded: continue fpath = find_module(modname) if fpath is not None: fanalyzer = self.tree_analyser.analyze_file(fpath) if '.' not in base: trybase = '.'.join([modname, base]) else: trybase = base if trybase in fanalyzer.classes: break elif basename in fanalyzer.localnames: newname = fanalyzer.localnames[basename] self.tree_analyser.class_map[trybase] = newname if newname not in self.tree_analyser.class_map and \ newname not in self.unresolved_classes: undef_bases.append(newname) break else: self.unresolved_classes.add(base)
def find_docs_url(plugin_name=None, build_if_needed=True): """Returns a url for the Sphinx docs for the named plugin. The plugin must be importable in the current environment. plugin_name: str Name of the plugin distribution, module, or class. """ parts = plugin_name.split('.') if len(parts) == 1: # assume it's a class name and try to find unambiguous module modname = None # loop over available types to find a class name that matches for name, version in get_available_types(): mname, cname = name.rsplit('.', 1) if cname == plugin_name: if modname and modname != mname: raise RuntimeError("Can't determine module for class '%s'" " unambiguously. found in %s" % (cname, [mname, modname])) modname = mname parts = modname.split('.') if modname is None: # didn't find a class, so assume plugin_name is a dist name parts = [plugin_name, plugin_name] for i in range(len(parts)-1): mname = '.'.join(parts[:len(parts)-i]) try: __import__(mname) mod = sys.modules[mname] modname = mname modfile = os.path.abspath(mod.__file__) break except ImportError: # we may be able to locate the docs even if the import fails modfile = find_module(mname) modname = mname if modfile: break else: # Possibly something in contrib that's a directory. try: __import__(plugin_name) mod = sys.modules[plugin_name] modname = plugin_name modfile = os.path.abspath(mod.__file__) except ImportError: raise RuntimeError("Can't locate package/module '%s'" % plugin_name) url = 'file://' if modname.startswith('openmdao.'): # lookup in builtin docs import openmdao.main fparts = mod.__file__.split(os.sep) pkg = '.'.join(modname.split('.')[:2]) anchorpath = '/'.join(['srcdocs', 'packages', '%s.html#module-%s' % (pkg, modname)]) if any([p.endswith('.egg') and p.startswith('openmdao.') for p in fparts]): # this is a release version, so use docs packaged with openmdao.main htmldir = os.path.join(os.path.dirname(openmdao.main.__file__), "docs") else: # it's a developer version, so use locally built docs htmldir = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs', '_build', 'html') if not os.path.isfile(os.path.join(htmldir, 'index.html')) and build_if_needed: #make sure the local docs are built print "local docs not found.\nbuilding them now...\n" check_call(['openmdao', 'build_docs']) url += os.path.join(htmldir, anchorpath) else: url += os.path.join(os.path.dirname(modfile), 'sphinx_build', 'html', 'index.html') url = url.replace('\\', '/') return url
def find_docs_url(plugin_name=None, build_if_needed=True): """Returns a url for the Sphinx docs for the named plugin. The plugin must be importable in the current environment. plugin_name: str Name of the plugin distribution, module, or class. """ parts = plugin_name.split('.') if len(parts) == 1: # assume it's a class name and try to find unambiguous module modname = None # loop over available types to find a class name that matches for name, version in get_available_types(): mname, cname = name.rsplit('.', 1) if cname == plugin_name: if modname and modname != mname: raise RuntimeError("Can't determine module for class '%s'" " unambiguously. found in %s" % (cname, [mname, modname])) modname = mname parts = modname.split('.') if modname is None: # didn't find a class, so assume plugin_name is a dist name parts = [plugin_name, plugin_name] for i in range(len(parts) - 1): mname = '.'.join(parts[:len(parts) - i]) try: __import__(mname) mod = sys.modules[mname] modname = mname modfile = os.path.abspath(mod.__file__) break except ImportError: # we may be able to locate the docs even if the import fails modfile = find_module(mname) modname = mname if modfile: break else: # Possibly something in contrib that's a directory. try: __import__(plugin_name) mod = sys.modules[plugin_name] modname = plugin_name modfile = os.path.abspath(mod.__file__) except ImportError: raise RuntimeError("Can't locate package/module '%s'" % plugin_name) url = 'file://' if modname.startswith('openmdao.'): # lookup in builtin docs import openmdao.main fparts = mod.__file__.split(os.sep) pkg = '.'.join(modname.split('.')[:2]) anchorpath = '/'.join(['srcdocs', 'packages', '%s.html#module-%s' % (pkg, modname)]) if any([p.endswith('.egg') and p.startswith('openmdao.') for p in fparts]): # this is a release version, so use docs packaged with openmdao.main htmldir = os.path.join(os.path.dirname(openmdao.main.__file__), "docs") else: # it's a developer version, so use locally built docs htmldir = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs', '_build', 'html') if not os.path.isfile(os.path.join(htmldir, 'index.html')) and build_if_needed: # make sure the local docs are built print "local docs not found.\nbuilding them now...\n" check_call(['openmdao', 'build_docs']) url += os.path.join(htmldir, anchorpath) else: url += os.path.join(os.path.dirname(modfile), 'sphinx_build', 'html', 'index.html') url = url.replace('\\', '/') return url