Method: pylint.graph.DotBackend.generate
Calls: 8, Exceptions: 2, Paths: 3Back
Path 1: 6 calls (0.75)
'foo.dot' (1) 'foo.gv' (1) 'tests/regrtest_data/foo.dot' (1) 'import.dot' (1) 'ext_import.dot' (1) 'int_import.dot' (1)
None (6)
'foo.dot' (1) 'foo.gv' (1) 'tests/regrtest_data/foo.dot' (1) 'import.dot' (1) 'ext_import.dot' (1) 'int_import.dot' (1)
1def generate(
2 self, outputfile: str | None = None, mapfile: str | None = None
3 ) -> str:
4 """Generates a graph file.
5
6 :param str outputfile: filename and path [defaults to graphname.png]
7 :param str mapfile: filename and path
8
9 :rtype: str
10 :return: a path to the generated file
11 :raises RuntimeError: if the executable for rendering was not found
12 """
13 # pylint: disable=duplicate-code
14 graphviz_extensions = ("dot", "gv")
15 name = self.graphname
16 if outputfile is None:
17 target = "png"
18 pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
19 ppng, outputfile = tempfile.mkstemp(".png", name)
20 os.close(pdot)
21 os.close(ppng)
22 else:
23 _, _, target = target_info_from_filename(outputfile)
24 if not target:
25 target = "png"
26 outputfile = outputfile + "." + target
27 if target not in graphviz_extensions:
28 pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
29 os.close(pdot)
30 else:
31 dot_sourcepath = outputfile
32 with codecs.open(dot_sourcepath, "w", encoding="utf8") as file:
33 file.write(self.source)
34 if target not in graphviz_extensions:
35 if shutil.which(self.renderer) is None:
36 raise RuntimeError(
37 f"Cannot generate `{outputfile}` because '{self.renderer}' "
38 "executable not found. Install graphviz, or specify a `.gv` "
39 "outputfile to produce the DOT source code."
40 )
41 if mapfile:
42 subprocess.run(
43 [
44 self.renderer,
45 "-Tcmapx",
46 "-o",
47 mapfile,
48 "-T",
49 target,
50 dot_sourcepath,
51 "-o",
52 outputfile,
53 ],
54 check=True,
55 )
56 else:
57 subprocess.run(
58 [self.renderer, "-T", target, dot_sourcepath, "-o", outputfile],
59 check=True,
60 )
61 os.unlink(dot_sourcepath)
62 return outputfile
Path 2: 1 calls (0.12)
'graph.png' (1)
None (1)
RuntimeError (1)
1def generate(
2 self, outputfile: str | None = None, mapfile: str | None = None
3 ) -> str:
4 """Generates a graph file.
5
6 :param str outputfile: filename and path [defaults to graphname.png]
7 :param str mapfile: filename and path
8
9 :rtype: str
10 :return: a path to the generated file
11 :raises RuntimeError: if the executable for rendering was not found
12 """
13 # pylint: disable=duplicate-code
14 graphviz_extensions = ("dot", "gv")
15 name = self.graphname
16 if outputfile is None:
17 target = "png"
18 pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
19 ppng, outputfile = tempfile.mkstemp(".png", name)
20 os.close(pdot)
21 os.close(ppng)
22 else:
23 _, _, target = target_info_from_filename(outputfile)
24 if not target:
25 target = "png"
26 outputfile = outputfile + "." + target
27 if target not in graphviz_extensions:
28 pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
29 os.close(pdot)
30 else:
31 dot_sourcepath = outputfile
32 with codecs.open(dot_sourcepath, "w", encoding="utf8") as file:
33 file.write(self.source)
34 if target not in graphviz_extensions:
35 if shutil.which(self.renderer) is None:
36 raise RuntimeError(
37 f"Cannot generate `{outputfile}` because '{self.renderer}' "
38 "executable not found. Install graphviz, or specify a `.gv` "
39 "outputfile to produce the DOT source code."
40 )
41 if mapfile:
42 subprocess.run(
43 [
44 self.renderer,
45 "-Tcmapx",
46 "-o",
47 mapfile,
48 "-T",
49 target,
50 dot_sourcepath,
51 "-o",
52 outputfile,
53 ],
54 check=True,
55 )
56 else:
57 subprocess.run(
58 [self.renderer, "-T", target, dot_sourcepath, "-o", outputfile],
59 check=True,
60 )
61 os.unlink(dot_sourcepath)
62 return outputfile
Path 3: 1 calls (0.12)
'graph' (1)
None (1)
RuntimeError (1)
1def generate(
2 self, outputfile: str | None = None, mapfile: str | None = None
3 ) -> str:
4 """Generates a graph file.
5
6 :param str outputfile: filename and path [defaults to graphname.png]
7 :param str mapfile: filename and path
8
9 :rtype: str
10 :return: a path to the generated file
11 :raises RuntimeError: if the executable for rendering was not found
12 """
13 # pylint: disable=duplicate-code
14 graphviz_extensions = ("dot", "gv")
15 name = self.graphname
16 if outputfile is None:
17 target = "png"
18 pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
19 ppng, outputfile = tempfile.mkstemp(".png", name)
20 os.close(pdot)
21 os.close(ppng)
22 else:
23 _, _, target = target_info_from_filename(outputfile)
24 if not target:
25 target = "png"
26 outputfile = outputfile + "." + target
27 if target not in graphviz_extensions:
28 pdot, dot_sourcepath = tempfile.mkstemp(".gv", name)
29 os.close(pdot)
30 else:
31 dot_sourcepath = outputfile
32 with codecs.open(dot_sourcepath, "w", encoding="utf8") as file:
33 file.write(self.source)
34 if target not in graphviz_extensions:
35 if shutil.which(self.renderer) is None:
36 raise RuntimeError(
37 f"Cannot generate `{outputfile}` because '{self.renderer}' "
38 "executable not found. Install graphviz, or specify a `.gv` "
39 "outputfile to produce the DOT source code."
40 )
41 if mapfile:
42 subprocess.run(
43 [
44 self.renderer,
45 "-Tcmapx",
46 "-o",
47 mapfile,
48 "-T",
49 target,
50 dot_sourcepath,
51 "-o",
52 outputfile,
53 ],
54 check=True,
55 )
56 else:
57 subprocess.run(
58 [self.renderer, "-T", target, dot_sourcepath, "-o", outputfile],
59 check=True,
60 )
61 os.unlink(dot_sourcepath)
62 return outputfile