diff options
author | Andrew Howe <howeaj@users.noreply.github.com> | 2021-03-29 09:00:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-29 10:00:18 +0200 |
commit | a37c643d54ea33285e4c916a296784593af0130c (patch) | |
tree | 27bb49a2cee462ec2b69f1d6c2395ed1d8059166 /pylint/checkers | |
parent | 42bf3b0f4d2aad3e5b40153cf743021de635836d (diff) | |
download | pylint-git-a37c643d54ea33285e4c916a296784593af0130c.tar.gz |
Fix various problems with --import-graph filename parsing (#4259)
Avoids backwards-incompatible changes.
- Raise error if graphvis is not installed (instead of reporting success)
- Fix tempfile creation bug when outputfile includes directories
- Fix bug when using file extension that isn't 3 characters long
- Fix confusing help text
- Rename deprecated .dot extension to .gv
- Default to .png if no extension is specified
* Add typing to modified functions (and ignore mypy thinking codecs.open()
returns an int)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint/checkers')
-rw-r--r-- | pylint/checkers/imports.py | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py index 9d4e60e6f..d3a5ca2f4 100644 --- a/pylint/checkers/imports.py +++ b/pylint/checkers/imports.py @@ -44,6 +44,7 @@ import copy import os import sys from distutils import sysconfig +from typing import Dict, List import astroid @@ -56,7 +57,7 @@ from pylint.checkers.utils import ( from pylint.exceptions import EmptyReportError from pylint.graph import DotBackend, get_cycles from pylint.interfaces import IAstroidChecker -from pylint.reporters.ureports.nodes import Paragraph, VerbatimText +from pylint.reporters.ureports.nodes import Paragraph, VerbatimText, VNode from pylint.utils import IsortDriver, get_global_option @@ -172,10 +173,10 @@ def _repr_tree_defs(data, indent_str=None): return "\n".join(lines) -def _dependencies_graph(filename, dep_info): +def _dependencies_graph(filename: str, dep_info: Dict[str, List[str]]) -> str: """write dependencies as a dot (graphviz) file""" done = {} - printer = DotBackend(filename[:-4], rankdir="LR") + printer = DotBackend(os.path.splitext(os.path.basename(filename))[0], rankdir="LR") printer.emit('URL="." node[shape="box"]') for modname, dependencies in sorted(dep_info.items()): done[modname] = 1 @@ -187,15 +188,15 @@ def _dependencies_graph(filename, dep_info): for depmodname, dependencies in sorted(dep_info.items()): for modname in dependencies: printer.emit_edge(modname, depmodname) - printer.generate(filename) + return printer.generate(filename) -def _make_graph(filename, dep_info, sect, gtype): +def _make_graph(filename: str, dep_info: Dict[str, List[str]], sect: VNode, gtype: str): """generate a dependencies graph and add some information about it in the report's section """ - _dependencies_graph(filename, dep_info) - sect.append(Paragraph(f"{gtype}imports graph has been written to {filename}")) + outputfile = _dependencies_graph(filename, dep_info) + sect.append(Paragraph(f"{gtype}imports graph has been written to {outputfile}")) # the import checker itself ################################################### @@ -332,9 +333,9 @@ class ImportsChecker(DeprecatedMixin, BaseChecker): { "default": "", "type": "string", - "metavar": "<file.dot>", - "help": "Create a graph of every (i.e. internal and" - " external) dependencies in the given file" + "metavar": "<file.gv>", + "help": "Output a graph (.gv or any supported image format) of" + " all (i.e. internal and external) dependencies to the given file" " (report RP0402 must not be disabled).", }, ), @@ -343,9 +344,10 @@ class ImportsChecker(DeprecatedMixin, BaseChecker): { "default": "", "type": "string", - "metavar": "<file.dot>", - "help": "Create a graph of external dependencies in the" - " given file (report RP0402 must not be disabled).", + "metavar": "<file.gv>", + "help": "Output a graph (.gv or any supported image format)" + " of external dependencies to the given file" + " (report RP0402 must not be disabled).", }, ), ( @@ -353,9 +355,10 @@ class ImportsChecker(DeprecatedMixin, BaseChecker): { "default": "", "type": "string", - "metavar": "<file.dot>", - "help": "Create a graph of internal dependencies in the" - " given file (report RP0402 must not be disabled).", + "metavar": "<file.gv>", + "help": "Output a graph (.gv or any supported image format)" + " of internal dependencies to the given file" + " (report RP0402 must not be disabled).", }, ), ( |