robotcode-plugin 0.30.0__tar.gz → 0.31.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: robotcode-plugin
3
- Version: 0.30.0
3
+ Version: 0.31.0
4
4
  Summary: Some classes for RobotCode plugin management
5
5
  Project-URL: Donate, https://github.com/sponsors/d-biehl
6
6
  Project-URL: Documentation, https://github.com/d-biehl/robotcode#readme
@@ -0,0 +1,118 @@
1
+ from dataclasses import dataclass
2
+ from enum import Enum, unique
3
+ from pathlib import Path
4
+ from typing import IO, Any, AnyStr, Callable, Dict, List, Optional, TypeVar, Union, cast
5
+
6
+ import click
7
+ import pluggy
8
+
9
+ from robotcode.core.dataclasses import as_json
10
+
11
+ __all__ = ["hookimpl", "CommonConfig", "pass_application"]
12
+
13
+ F = TypeVar("F", bound=Callable[..., Any])
14
+ hookimpl = cast(Callable[[F], F], pluggy.HookimplMarker("robotcode"))
15
+
16
+
17
+ @unique
18
+ class ColoredOutput(str, Enum):
19
+ AUTO = "auto"
20
+ YES = "yes"
21
+ NO = "no"
22
+
23
+
24
+ @unique
25
+ class OutputFormat(str, Enum):
26
+ TOML = "toml"
27
+ JSON = "json"
28
+ FLAT = "flat"
29
+
30
+ def __str__(self) -> str:
31
+ return self.value
32
+
33
+
34
+ @dataclass
35
+ class CommonConfig:
36
+ config_file: Optional[Path] = None
37
+ profiles: Optional[List[str]] = None
38
+ dry: bool = False
39
+ verbose: bool = False
40
+ colored_output: ColoredOutput = ColoredOutput.AUTO
41
+
42
+
43
+ class Application:
44
+ def __init__(self) -> None:
45
+ self.config = CommonConfig()
46
+
47
+ @property
48
+ def colored(self) -> bool:
49
+ return self.config.colored_output in [ColoredOutput.AUTO, ColoredOutput.YES]
50
+
51
+ def verbose(
52
+ self,
53
+ message: Union[str, Callable[[], Any], None],
54
+ file: Optional[IO[AnyStr]] = None,
55
+ nl: bool = True,
56
+ err: bool = False,
57
+ ) -> None:
58
+ if self.config.verbose:
59
+ click.secho(
60
+ message() if callable(message) else message,
61
+ file=file,
62
+ nl=nl,
63
+ err=err,
64
+ color=self.colored,
65
+ fg="bright_black",
66
+ )
67
+
68
+ def warning(
69
+ self,
70
+ message: Union[str, Callable[[], Any], None],
71
+ file: Optional[IO[AnyStr]] = None,
72
+ nl: bool = True,
73
+ err: bool = False,
74
+ ) -> None:
75
+ click.secho(
76
+ f"WARNING: {message() if callable(message) else message}",
77
+ file=file,
78
+ nl=nl,
79
+ err=err,
80
+ color=self.colored,
81
+ fg="bright_yellow",
82
+ )
83
+
84
+ def print_dict(self, config: Dict[str, Any], format: OutputFormat) -> None:
85
+ text = None
86
+ if format == "toml":
87
+ try:
88
+ import tomli_w
89
+
90
+ text = tomli_w.dumps(config)
91
+ except ImportError:
92
+ self.warning("Package 'tomli_w' is required to use TOML output. Using JSON format instead.")
93
+ format = OutputFormat.JSON
94
+
95
+ if text is None:
96
+ text = as_json(config, indent=True)
97
+
98
+ if not text:
99
+ return
100
+
101
+ if self.colored:
102
+ try:
103
+ from rich.console import Console
104
+ from rich.syntax import Syntax
105
+
106
+ Console().print(Syntax(text, format, background_color="default"))
107
+
108
+ return
109
+ except ImportError:
110
+ if self.config.colored_output == ColoredOutput.YES:
111
+ self.warning('Package "rich" is required to use colored output.')
112
+
113
+ click.echo(text)
114
+
115
+ return
116
+
117
+
118
+ pass_application = click.make_pass_decorator(Application, ensure=True)
@@ -0,0 +1 @@
1
+ __version__ = "0.31.0"
@@ -0,0 +1,23 @@
1
+ from enum import Enum
2
+ from typing import Any, Callable, Type, Union
3
+
4
+ import click
5
+
6
+
7
+ class EnumChoice(click.Choice):
8
+ """A click.Choice that accepts Enum values."""
9
+
10
+ def __init__(self, choices: Type[Enum], case_sensitive: bool = True) -> None:
11
+ super().__init__(choices, case_sensitive) # type: ignore
12
+
13
+
14
+ FC = Union[Callable[..., Any], click.Command]
15
+
16
+
17
+ def add_options(*options: FC) -> FC:
18
+ def _add_options(func: FC) -> FC:
19
+ for option in reversed(options):
20
+ func = option(func)
21
+ return func
22
+
23
+ return _add_options
@@ -1,22 +0,0 @@
1
- from dataclasses import dataclass
2
- from pathlib import Path
3
- from typing import Any, Callable, List, Optional, TypeVar, cast
4
-
5
- import click
6
- import pluggy
7
-
8
- __all__ = ["hookimpl", "CommonConfig", "pass_common_config"]
9
-
10
- F = TypeVar("F", bound=Callable[..., Any])
11
- hookimpl = cast(Callable[[F], F], pluggy.HookimplMarker("robotcode"))
12
-
13
-
14
- @dataclass
15
- class CommonConfig:
16
- config_file: Optional[Path] = None
17
- profiles: Optional[List[str]] = None
18
- dry: bool = False
19
- verbose: bool = False
20
-
21
-
22
- pass_common_config = click.make_pass_decorator(CommonConfig, ensure=True)
@@ -1 +0,0 @@
1
- __version__ = "0.30.0"