diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-09-16 17:33:50 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-09-17 09:07:42 +0200 |
commit | 3f2842400795ae1aaffc4ae6c35c4ef26857c239 (patch) | |
tree | 057fb96b25b851998edce6dd40b8e496755422a1 /pylint/graph.py | |
parent | c8e0992d31b831b7d60b1e8582b84068d50c3afd (diff) | |
download | pylint-git-3f2842400795ae1aaffc4ae6c35c4ef26857c239.tar.gz |
Reformat the code with black
Diffstat (limited to 'pylint/graph.py')
-rw-r--r-- | pylint/graph.py | 78 |
1 files changed, 52 insertions, 26 deletions
diff --git a/pylint/graph.py b/pylint/graph.py index 2f8f9f4ed..f7790dae8 100644 --- a/pylint/graph.py +++ b/pylint/graph.py @@ -17,18 +17,28 @@ import sys import tempfile import codecs + def target_info_from_filename(filename): """Transforms /some/path/foo.png into ('/some/path', 'foo.png', 'png').""" basename = osp.basename(filename) storedir = osp.dirname(osp.abspath(filename)) - target = filename.split('.')[-1] + target = filename.split(".")[-1] return storedir, basename, target class DotBackend: """Dot File backend.""" - def __init__(self, graphname, rankdir=None, size=None, ratio=None, - charset='utf-8', renderer='dot', additional_param=None): + + def __init__( + self, + graphname, + rankdir=None, + size=None, + ratio=None, + charset="utf-8", + renderer="dot", + additional_param=None, + ): if additional_param is None: additional_param = {} self.graphname = graphname @@ -37,23 +47,24 @@ class DotBackend: self._source = None self.emit("digraph %s {" % normalize_node_id(graphname)) if rankdir: - self.emit('rankdir=%s' % rankdir) + self.emit("rankdir=%s" % rankdir) if ratio: - self.emit('ratio=%s' % ratio) + self.emit("ratio=%s" % ratio) if size: self.emit('size="%s"' % size) if charset: - assert charset.lower() in ('utf-8', 'iso-8859-1', 'latin1'), \ - 'unsupported charset %s' % charset + assert charset.lower() in ("utf-8", "iso-8859-1", "latin1"), ( + "unsupported charset %s" % charset + ) self.emit('charset="%s"' % charset) for param in additional_param.items(): - self.emit('='.join(param)) + self.emit("=".join(param)) def get_source(self): """returns self._source""" if self._source is None: self.emit("}\n") - self._source = '\n'.join(self.lines) + self._source = "\n".join(self.lines) del self.lines return self._source @@ -69,14 +80,15 @@ class DotBackend: :rtype: str :return: a path to the generated file """ - import subprocess # introduced in py 2.4 + import subprocess # introduced in py 2.4 + name = self.graphname if not dotfile: # if 'outputfile' is a dot file use it as 'dotfile' if outputfile and outputfile.endswith(".dot"): dotfile = outputfile else: - dotfile = '%s.dot' % name + dotfile = "%s.dot" % name if outputfile is not None: storedir, _, target = target_info_from_filename(outputfile) if target != "dot": @@ -85,25 +97,36 @@ class DotBackend: else: dot_sourcepath = osp.join(storedir, dotfile) else: - target = 'png' + target = "png" pdot, dot_sourcepath = tempfile.mkstemp(".dot", name) ppng, outputfile = tempfile.mkstemp(".png", name) os.close(pdot) os.close(ppng) - pdot = codecs.open(dot_sourcepath, 'w', encoding='utf8') + pdot = codecs.open(dot_sourcepath, "w", encoding="utf8") pdot.write(self.source) pdot.close() - if target != 'dot': - use_shell = sys.platform == 'win32' + if target != "dot": + use_shell = sys.platform == "win32" if mapfile: - subprocess.call([self.renderer, '-Tcmapx', '-o', - mapfile, '-T', target, dot_sourcepath, - '-o', outputfile], - shell=use_shell) + subprocess.call( + [ + self.renderer, + "-Tcmapx", + "-o", + mapfile, + "-T", + target, + dot_sourcepath, + "-o", + outputfile, + ], + shell=use_shell, + ) else: - subprocess.call([self.renderer, '-T', target, - dot_sourcepath, '-o', outputfile], - shell=use_shell) + subprocess.call( + [self.renderer, "-T", target, dot_sourcepath, "-o", outputfile], + shell=use_shell, + ) os.unlink(dot_sourcepath) return outputfile @@ -117,24 +140,26 @@ class DotBackend: """ attrs = ['%s="%s"' % (prop, value) for prop, value in props.items()] n_from, n_to = normalize_node_id(name1), normalize_node_id(name2) - self.emit('%s -> %s [%s];' % (n_from, n_to, ', '.join(sorted(attrs)))) + self.emit("%s -> %s [%s];" % (n_from, n_to, ", ".join(sorted(attrs)))) def emit_node(self, name, **props): """emit a node with given properties. node properties: see http://www.graphviz.org/doc/info/attrs.html """ attrs = ['%s="%s"' % (prop, value) for prop, value in props.items()] - self.emit('%s [%s];' % (normalize_node_id(name), ', '.join(sorted(attrs)))) + self.emit("%s [%s];" % (normalize_node_id(name), ", ".join(sorted(attrs)))) + def normalize_node_id(nid): """Returns a suitable DOT node id for `nid`.""" return '"%s"' % nid + def get_cycles(graph_dict, vertices=None): - '''given a dictionary representing an ordered graph (i.e. key are vertices + """given a dictionary representing an ordered graph (i.e. key are vertices and values is a list of destination vertices representing edges), return a list of detected cycles - ''' + """ if not graph_dict: return () result = [] @@ -144,6 +169,7 @@ def get_cycles(graph_dict, vertices=None): _get_cycles(graph_dict, [], set(), result, vertice) return result + def _get_cycles(graph_dict, path, visited, result, vertice): """recursive function doing the real work for get_cycles""" if vertice in path: |