Skip to content

Commit 582e360

Browse files
committed
feat(robotcode): introduce plugin spec for configuration classes
1 parent b0ee6b3 commit 582e360

File tree

24 files changed

+186
-87
lines changed

24 files changed

+186
-87
lines changed

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
// "toml",
4343
// "--no-color",
4444
// "--no-pager",
45-
//"config", "info", "desc",
46-
"discover",
47-
"all"
45+
"config", "info", "list",
46+
// "analyze",
47+
// "."
4848
]
4949
},
5050
{
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# ruff: noqa: RUF009
2+
from dataclasses import dataclass
3+
from typing import List, Optional, Tuple, Union
4+
5+
import click
6+
from robotcode.plugin import Application, pass_application
7+
from robotcode.robot.config.loader import load_config_from_path
8+
from robotcode.robot.config.model import BaseOptions, field
9+
from robotcode.robot.config.utils import get_config_files
10+
11+
from .__version__ import __version__
12+
13+
14+
@dataclass
15+
class Dummy:
16+
some_field: Optional[str] = field(default="some value", description="Some field")
17+
18+
19+
@dataclass
20+
class AnalyzerConfig(BaseOptions):
21+
select: Optional[List[Union[str, Dummy]]] = field(description="Selects which rules are run.")
22+
extra_select: Optional[List[Union[str, Dummy]]] = field(description="Selects which rules are run.")
23+
ignore: Optional[List[str]] = field(description="Ignores which rules are run.")
24+
extra_ignore: Optional[List[str]] = field(description="Ignores which rules are run.")
25+
26+
27+
@click.command(
28+
context_settings={
29+
"allow_extra_args": True,
30+
"ignore_unknown_options": True,
31+
},
32+
add_help_option=True,
33+
)
34+
@click.version_option(
35+
version=__version__,
36+
package_name="robotcode.analyze",
37+
prog_name="RobotCode Analyze",
38+
)
39+
@click.argument("paths", nargs=-1, type=click.Path(exists=True, dir_okay=True))
40+
@pass_application
41+
def analyze(
42+
app: Application,
43+
paths: Tuple[str],
44+
) -> Union[str, int, None]:
45+
"""TODO: Analyzes a Robot Framework project."""
46+
47+
config_files, root_folder, _ = get_config_files(paths, app.config.config_files, verbose_callback=app.verbose)
48+
49+
try:
50+
robot_profile = load_config_from_path(
51+
AnalyzerConfig, *config_files, tool_name="robotcode-analyze", robot_toml_tool_name="robotcode-analyze"
52+
).evaluated()
53+
except (TypeError, ValueError) as e:
54+
raise click.ClickException(str(e)) from e
55+
56+
app.print_data(robot_profile)
57+
return 0

packages/analyze/src/robotcode/analyze/cli/__init__.py

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
from typing import List
1+
from typing import Any, List, Tuple, Type
22

33
import click
44
from robotcode.plugin import hookimpl
55

6-
from .cli import analyze
6+
from .cli import AnalyzerConfig, analyze
77

88

99
@hookimpl
10-
def hatch_register_cli_commands() -> List[click.Command]:
10+
def register_cli_commands() -> List[click.Command]:
1111
return [analyze]
12+
13+
14+
@hookimpl
15+
def register_config_classes() -> List[Tuple[str, Type[Any]]]:
16+
return [("tool.robotcode-analyze", AnalyzerConfig)]

packages/debugger/src/robotcode/debugger/hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99

1010
@hookimpl
11-
def hatch_register_cli_commands() -> List[click.Command]:
11+
def register_cli_commands() -> List[click.Command]:
1212
return [debug, debug_launch]

packages/language_server/src/robotcode/language_server/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
AddressesPort,
1111
add_options,
1212
)
13-
from robotcode.robot.config.loader import load_config_from_path
13+
from robotcode.robot.config.loader import load_robot_config_from_path
1414
from robotcode.robot.config.model import RobotBaseProfile
1515
from robotcode.robot.config.utils import get_config_files
1616

@@ -76,7 +76,7 @@ def language_server(
7676

7777
try:
7878
profile = (
79-
load_config_from_path(*config_files)
79+
load_robot_config_from_path(*config_files)
8080
.combine_profiles(*(app.config.profiles or []), verbose_callback=app.verbose)
8181
.evaluated()
8282
)

packages/language_server/src/robotcode/language_server/common/parts/workspace.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ async def get_configuration_raw(
370370
raise
371371
except JsonRPCErrorException as e:
372372
self._logger.warning(str(e))
373-
pass
374373

375374
result = self.settings
376375
for sub_key in str(section).split("."):

packages/language_server/src/robotcode/language_server/hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88

99
@hookimpl
10-
def hatch_register_cli_commands() -> List[click.Command]:
10+
def register_cli_commands() -> List[click.Command]:
1111
return [language_server]

packages/language_server/src/robotcode/language_server/robotframework/diagnostics/library_doc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,6 @@ def get_test_library(
16301630
raise
16311631
except BaseException:
16321632
lib = None
1633-
pass
16341633

16351634
real_source = lib.source if lib is not None else source
16361635

packages/plugin/src/robotcode/plugin/manager.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, cast
1+
from typing import List, Tuple, Type, cast
22

33
import click
44
import pluggy
@@ -16,5 +16,12 @@ def __init__(self) -> None:
1616
def cli_commands(self) -> List[List[click.Command]]:
1717
return cast(
1818
List[List[click.Command]],
19-
self._plugin_manager.hook.hatch_register_cli_commands(),
19+
self._plugin_manager.hook.register_cli_commands(),
20+
)
21+
22+
@property
23+
def config_classes(self) -> List[List[Tuple[str, Type[specs.TConfigClass]]]]:
24+
return cast(
25+
List[List[Tuple[str, Type[specs.TConfigClass]]]],
26+
self._plugin_manager.hook.register_config_classes(),
2027
)

0 commit comments

Comments
 (0)