diff options
Diffstat (limited to 'sources/pyside2/doc')
-rw-r--r-- | sources/pyside2/doc/inheritance_diagram.py | 87 | ||||
-rw-r--r-- | sources/pyside2/doc/pysideversion.rst | 18 |
2 files changed, 52 insertions, 53 deletions
diff --git a/sources/pyside2/doc/inheritance_diagram.py b/sources/pyside2/doc/inheritance_diagram.py index a7f376ccd..038c22f29 100644 --- a/sources/pyside2/doc/inheritance_diagram.py +++ b/sources/pyside2/doc/inheritance_diagram.py @@ -52,15 +52,38 @@ from docutils.parsers.rst import directives from sphinx.ext.graphviz import render_dot_html, render_dot_latex from sphinx.util.compat import Directive - -class_sig_re = re.compile(r'''^([\w.]*\.)? # module names - (\w+) \s* $ # class/final module name - ''', re.VERBOSE) - - class InheritanceException(Exception): pass +# When passed something like: +# PySide2.QtCore.QStateMachine.SignalEvent +# try to import the underlying module and return a +# handle to the object. In a loop, import +# PySide2.QtCore.QStateMachine.SignalEvent +# PySide2.QtCore.QStateMachine +# PySide2.QtCore +# until the import succeeds and walk up the attributes +# to obtain the object + +def importClassOrModule(name): + components = name.split('.') + for i in range(len(components), 0, -1): + importPath = '.'.join(components[: i]) + try: + __import__(importPath) + except ImportError: + continue + if i == len(components): + return sys.modules[importPath] + remaining = components[i :] + cls = sys.modules[importPath] + for component in remaining: + try: + cls = getattr(cls, component) + except Exception: # No such attribute + return None + return cls + return None class InheritanceGraph(object): """ @@ -86,38 +109,13 @@ class InheritanceGraph(object): """ Import a class using its fully-qualified *name*. """ - try: - path, base = class_sig_re.match(name).groups() - except (AttributeError, ValueError): - raise InheritanceException('Invalid class or module %r specified ' - 'for inheritance diagram' % name) - - fullname = (path or '') + base - path = (path and path.rstrip('.') or '') - - # two possibilities: either it is a module, then import it - try: - __import__(fullname) - todoc = sys.modules[fullname] - except ImportError: - # else it is a class, then import the module - if not path: - if currmodule: - # try the current module - path = currmodule - else: - raise InheritanceException( - 'Could not import class %r specified for ' - 'inheritance diagram' % base) - try: - __import__(path) - todoc = getattr(sys.modules[path], base) - except (ImportError, AttributeError): - raise InheritanceException( - 'Could not import class or module %r specified for ' - 'inheritance diagram' % (path + '.' + base)) - - # If a class, just return it + todoc = importClassOrModule(name) + if not todoc and currmodule is not None: + todoc = importClassOrModule(currmodule + '.' + name) + if not todoc: + moduleStr = '(module {})'.format(currmodule) if currmodule else '' + raise InheritanceException('Could not import class {} specified for ' + 'inheritance diagram {}.'.format(name, moduleStr)) if inspect.isclass(todoc): return [todoc] elif inspect.ismodule(todoc): @@ -167,7 +165,7 @@ class InheritanceGraph(object): for cls in classes: recurse(cls) - return all_classes.values() + return list(all_classes.values()) def class_name(self, cls, parts=0): """Given a class object, return a fully-qualified name. @@ -200,8 +198,8 @@ class InheritanceGraph(object): 'shape': 'box', 'fontsize': 10, 'height': 0.25, - 'fontname': 'Vera Sans, DejaVu Sans, Liberation Sans, ' - 'Arial, Helvetica, sans', + 'fontname': '"Vera Sans, DejaVu Sans, Liberation Sans, ' + 'Arial, Helvetica, sans"', 'style': '"setlinewidth(0.5)"', } default_edge_attrs = { @@ -314,7 +312,8 @@ class InheritanceDiagram(Directive): def get_graph_hash(node): - return md5(node['content'] + str(node['parts'])).hexdigest()[-10:] + hashString = node['content'] + str(node['parts']) + return md5(hashString.encode('utf-8')).hexdigest()[-10:] def html_visit_inheritance_diagram(self, node): @@ -336,7 +335,7 @@ def html_visit_inheritance_diagram(self, node): urls[child['reftitle']] = '#' + child.get('refid') dotcode = graph.generate_dot(name, urls, env=self.builder.env) - render_dot_html(self, node, dotcode, [], 'inheritance', 'inheritance', + render_dot_html(self, node, dotcode, {}, 'inheritance', 'inheritance', alt='Inheritance diagram of ' + node['content']) raise nodes.SkipNode @@ -352,7 +351,7 @@ def latex_visit_inheritance_diagram(self, node): dotcode = graph.generate_dot(name, env=self.builder.env, graph_attrs={'size': '"6.0,6.0"'}) - render_dot_latex(self, node, dotcode, [], 'inheritance') + render_dot_latex(self, node, dotcode, {}, 'inheritance') raise nodes.SkipNode diff --git a/sources/pyside2/doc/pysideversion.rst b/sources/pyside2/doc/pysideversion.rst index 3bcebe0da..5ad308c1e 100644 --- a/sources/pyside2/doc/pysideversion.rst +++ b/sources/pyside2/doc/pysideversion.rst @@ -1,31 +1,31 @@ Getting PySide and Qt version ***************************** -PySide exports their version numbers among the version of Qt used to compile PySide in a pythonnic way, you can check it using the variables: +PySide exports their version numbers among the version of Qt used to compile PySide in a pythonic way, you can check it using the variables: :: - import PySide + import PySide2.QtCore # Prints PySide version # e.g. 1.0.2 - print PySide.__version__ + print(PySide2.__version__) # Gets a tuple with each version component # e.g. (1, 0, 2, 'final', 1) - print PySide.__version_info__ + print(PySide2.__version_info__) # Prints the Qt version used to compile PySide - # e.g. "4.7.2" - print PySide2.QtCore.__version__ + # e.g. "5.11.0" + print(PySide2.QtCore.__version__) # Gets a tuple with each version components of Qt used to compile PySide - # e.g. (4, 7, 2) - print PySide2.QtCore.__version_info__ + # e.g. (5, 11, 0) + print(PySide2.QtCore.__version_info__) Note that the Qt version used to compile PySide may differ from the version used to run PySide, to get the current running Qt version you can do: :: - print PySide2.QtCore.qVersion() + print(PySide2.QtCore.qVersion()) |