Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --color-palette option to pyreverse #8223

Merged
merged 4 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pyenchant_pylint_custom_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ rstrip
rtype
runtime
se
seaborn
sep
setcomp
shortstrings
Expand Down
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/6738.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
`pyreverse` now supports custom color palettes with the `--color-palette` option.

Closes #6738
31 changes: 31 additions & 0 deletions pylint/pyreverse/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@
"html",
)

DEFAULT_COLOR_PALETTE = (
"aliceblue",
"antiquewhite",
"aquamarine",
"burlywood",
"cadetblue",
"chartreuse",
"chocolate",
"coral",
"cornflowerblue",
"cyan",
"darkgoldenrod",
"darkseagreen",
"dodgerblue",
"forestgreen",
"gold",
"hotpink",
"mediumspringgreen",
)

OPTIONS: Options = (
(
"filter-mode",
Expand Down Expand Up @@ -172,6 +192,17 @@
"help": "Use separate colors up to package depth of <depth>",
},
),
(
"color-palette",
{
"dest": "color_palette",
"action": "store",
"default": DEFAULT_COLOR_PALETTE,
"metavar": "<color1,color2,...>",
"type": "csv",
"help": "Comma separated list of colors to use",
},
),
(
"ignore",
{
Expand Down
23 changes: 2 additions & 21 deletions pylint/pyreverse/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,8 @@ def __init__(self, config: argparse.Namespace) -> None:
self.printer: Printer # defined in set_printer
self.file_name = "" # defined in set_printer
self.depth = self.config.max_color_depth
self.available_colors = itertools.cycle(
[
"aliceblue",
"antiquewhite",
"aquamarine",
"burlywood",
"cadetblue",
"chartreuse",
"chocolate",
"coral",
"cornflowerblue",
"cyan",
"darkgoldenrod",
"darkseagreen",
"dodgerblue",
"forestgreen",
"gold",
"hotpink",
"mediumspringgreen",
]
)
# default colors are an adaption of the seaborn colorblind palette
self.available_colors = itertools.cycle(self.config.color_palette)
self.used_colors: dict[str, str] = {}

def write(self, diadefs: Iterable[ClassDiagram | PackageDiagram]) -> None:
Expand Down
4 changes: 4 additions & 0 deletions pylint/testutils/pyreverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from pathlib import Path
from typing import NamedTuple

from pylint.pyreverse.main import DEFAULT_COLOR_PALETTE

if sys.version_info >= (3, 8):
from typing import TypedDict
else:
Expand Down Expand Up @@ -41,6 +43,7 @@ def __init__(
output_format: str = "dot",
colorized: bool = False,
max_color_depth: int = 2,
color_palette: tuple[str, ...] = DEFAULT_COLOR_PALETTE,
ignore_list: tuple[str, ...] = tuple(),
project: str = "",
output_directory: str = "",
Expand All @@ -61,6 +64,7 @@ def __init__(
self.output_format = output_format
self.colorized = colorized
self.max_color_depth = max_color_depth
self.color_palette = color_palette
self.ignore_list = ignore_list
self.project = project
self.output_directory = output_directory
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@startuml classes
set namespaceSeparator none
class "CheckerCollector" as custom_colors.CheckerCollector #red {
checker1
checker2
checker3
}
class "ElseifUsedChecker" as pylint.extensions.check_elif.ElseifUsedChecker #green {
msgs : dict
name : str
leave_module(_: nodes.Module) -> None
process_tokens(tokens: list[TokenInfo]) -> None
visit_if(node: nodes.If) -> None
}
class "ExceptionsChecker" as pylint.checkers.exceptions.ExceptionsChecker #yellow {
msgs : dict
name : str
options : tuple
open() -> None
visit_binop(node: nodes.BinOp) -> None
visit_compare(node: nodes.Compare) -> None
visit_raise(node: nodes.Raise) -> None
visit_tryexcept(node: nodes.TryExcept) -> None
}
class "StdlibChecker" as pylint.checkers.stdlib.StdlibChecker #yellow {
msgs : dict[str, MessageDefinitionTuple]
name : str
deprecated_arguments(method: str) -> tuple[tuple[int | None, str], ...]
deprecated_classes(module: str) -> Iterable[str]
deprecated_decorators() -> Iterable[str]
deprecated_methods() -> set[str]
visit_boolop(node: nodes.BoolOp) -> None
visit_call(node: nodes.Call) -> None
visit_functiondef(node: nodes.FunctionDef) -> None
visit_if(node: nodes.If) -> None
visit_ifexp(node: nodes.IfExp) -> None
visit_unaryop(node: nodes.UnaryOp) -> None
}
pylint.checkers.exceptions.ExceptionsChecker --* custom_colors.CheckerCollector : checker1
pylint.checkers.stdlib.StdlibChecker --* custom_colors.CheckerCollector : checker3
pylint.extensions.check_elif.ElseifUsedChecker --* custom_colors.CheckerCollector : checker2
@enduml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pylint.checkers.exceptions import ExceptionsChecker
from pylint.checkers.stdlib import StdlibChecker
from pylint.extensions.check_elif import ElseifUsedChecker


class CheckerCollector:
def __init__(self):
self.checker1 = ExceptionsChecker(None)
self.checker2 = ElseifUsedChecker(None)
self.checker3 = StdlibChecker(None)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[testoptions]
output_formats=puml
command_line_args=-S --colorized --max-color-depth=2 --color-palette=red,green,yellow