Skip to content

Commit 90c6c25

Browse files
committed
refactor: move the config command to robotcode package
1 parent 37dca4d commit 90c6c25

File tree

13 files changed

+79
-72
lines changed

13 files changed

+79
-72
lines changed

etc/robot.toml.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@
592592
"d-biehl (https://github.com/d-biehl)"
593593
],
594594
"patterns": [
595-
"^(.*(/|\\\\)\\.?robot\\.toml|\\.?robot\\.toml)$"
595+
"^(.*(/|\\\\)robot\\.toml|robot\\.toml)$"
596596
]
597597
}
598598
}

hatch.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies = [
2323
"robotremoteserver",
2424
"apischema",
2525
"tomli-w",
26-
"rich"
26+
"rich",
2727
]
2828
features = ["yaml", "rest", "lint", "tidy"]
2929
pre-install-commands = ["python ./scripts/install_packages.py"]

packages/robot/README.md

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

99
## Introduction
1010

11-
Support classes and commands for [RobotCode](https://robotcode.io) for handling Robot Framework projects.
11+
Support classes for [RobotCode](https://robotcode.io) for handling Robot Framework projects.
1212

1313
## Installation
1414

packages/robot/pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "robotcode-robot"
7-
description = 'Some Robot Framework robot for RobotCode'
7+
description = 'Support classes for RobotCode for handling Robot Framework projects.'
88
readme = { "file" = "README.md", "content-type" = "text/markdown" }
99
requires-python = ">=3.8"
1010
license = "Apache-2.0"
@@ -29,13 +29,9 @@ dependencies = [
2929
"robotframework>=4.1.0",
3030
"tomli>=1.1.0; python_version < '3.11'",
3131
"robotcode-core",
32-
"robotcode-plugin",
3332
]
3433
dynamic = ["version"]
3534

36-
[project.entry-points.robotcode]
37-
robot = "robotcode.robot.hooks"
38-
3935
[project.urls]
4036
Homepage = "https://robotcode.io"
4137
Donate = "https://github.com/sponsors/d-biehl"

packages/robot/robotcode/robot/hooks.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

pyproject.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "hatchling.build"
77
name = "robotcode"
88
description = "Language server, debugger and tools for Robot Framework"
99
authors = [{ name = "Daniel Biehl", email = "[email protected]" }]
10-
readme = {"file" = "README.md", "content-type" = "text/markdown"}
10+
readme = { "file" = "README.md", "content-type" = "text/markdown" }
1111
license = { text = "Apache-2.0" }
1212
keywords = [
1313
"Test",
@@ -49,7 +49,7 @@ classifiers = [
4949
"Framework :: Robot Framework :: Tool",
5050
]
5151
requires-python = ">=3.8"
52-
dependencies = ["robotcode-plugin"]
52+
dependencies = ["robotcode-plugin", "robotcode-robot"]
5353
dynamic = ["version"]
5454

5555

@@ -74,6 +74,15 @@ yaml = ["PyYAML>=5.4", "types-PyYAML>=5.4"]
7474
lint = ["robotframework-robocop>=2.0.0"]
7575
tidy = ["robotframework-tidy>=2.0.0"]
7676
rest = ["docutils"]
77+
all = [
78+
"runner",
79+
"debugger",
80+
"language-server",
81+
"analyze",
82+
"yaml",
83+
"lint",
84+
"tidy",
85+
]
7786

7887

7988
[tool.semantic_release]
@@ -255,5 +264,5 @@ ignore_missing_imports = true
255264

256265
[tool.pyright]
257266
exclude = ["**/.hatch", "**/node_modules", "**/__pycache__", "bundled/libs"]
258-
typeCheckingMode= "off"
267+
typeCheckingMode = "off"
259268
pythonVersion = "3.8"

robotcode/cli/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from robotcode.plugin.manager import PluginManager
88

99
from .__version__ import __version__
10+
from .commands import config
1011

1112

1213
@click.group(
@@ -61,6 +62,8 @@ def robotcode(
6162
common_config.verbose = verbose
6263

6364

65+
robotcode.add_command(config)
66+
6467
for p in PluginManager().cli_commands:
6568
for c in p:
6669
robotcode.add_command(c)

robotcode/cli/commands/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .config import config
2+
3+
__all__ = ["config"]

packages/robot/robotcode/robot/config/cli/__init__.py renamed to robotcode/cli/commands/config.py

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
from robotcode.core.dataclasses import as_dict, as_json
88
from robotcode.plugin import CommonConfig, pass_common_config
9-
10-
from ...__version__ import __version__
11-
from ..loader import find_project_root, get_config_files_from_folder, load_config_from_path
12-
from ..model import RobotConfig
9+
from robotcode.robot.config.loader import find_project_root, get_config_files_from_folder, load_config_from_path
10+
from robotcode.robot.config.model import RobotConfig
1311

1412
if sys.version_info >= (3, 11):
1513
pass
@@ -21,7 +19,6 @@
2119
context_settings={"help_option_names": ["-h", "--help"], "auto_envvar_prefix": "ROBOTCODE"},
2220
invoke_without_command=False,
2321
)
24-
@click.version_option(version=__version__, package_name="robotcode.robot.config", prog_name="RobotCode Config")
2522
@click.pass_context
2623
@pass_common_config
2724
def config(
@@ -36,6 +33,40 @@ def config(
3633
return 0
3734

3835

36+
def print_config(config: RobotConfig, format: str, color: str) -> int:
37+
text = None
38+
if format == "toml":
39+
try:
40+
import tomli_w
41+
42+
text = tomli_w.dumps(as_dict(config, remove_defaults=True))
43+
except ImportError:
44+
click.secho("tomli-w is required to output toml.", fg="red", err=True)
45+
46+
format = "json"
47+
48+
if text is None:
49+
text = as_json(config, indent=True)
50+
51+
if color in ["auto", "yes"]:
52+
try:
53+
from rich.console import Console
54+
from rich.syntax import Syntax
55+
56+
Console().print(Syntax(text, format, background_color="default"))
57+
58+
return 0
59+
except ImportError:
60+
if color == "yes":
61+
click.secho("rich is required to use colors.", fg="red", err=True)
62+
return 1
63+
pass
64+
65+
click.echo(text)
66+
67+
return 0
68+
69+
3970
@config.command
4071
@click.option(
4172
"-f", "--format", "format", type=click.Choice(["json", "toml"]), default="toml", help="Set the output format."
@@ -97,37 +128,3 @@ def show(
97128
return 1
98129

99130
return print_config(config, format, color)
100-
101-
102-
def print_config(config: RobotConfig, format: str, color: str) -> int:
103-
text = None
104-
if format == "toml":
105-
try:
106-
import tomli_w
107-
108-
text = tomli_w.dumps(as_dict(config, remove_defaults=True))
109-
except ImportError:
110-
click.secho("tomli-w is required to output toml.", fg="red", err=True)
111-
112-
format = "json"
113-
114-
if text is None:
115-
text = as_json(config, indent=True)
116-
117-
if color in ["auto", "yes"]:
118-
try:
119-
from rich.console import Console
120-
from rich.syntax import Syntax
121-
122-
Console().print(Syntax(text, format, background_color="default"))
123-
124-
return 0
125-
except ImportError:
126-
if color == "yes":
127-
click.secho("rich is required to use colors.", fg="red", err=True)
128-
return 1
129-
pass
130-
131-
click.echo(text)
132-
133-
return 0

scripts/create_robot_toml_json_schema.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,27 @@ def method_base_schema(tp: Any, method: Callable[..., Any], alias: str) -> Optio
5454
apischema.settings.base_schema.field = field_base_schema
5555
apischema.settings.base_schema.method = method_base_schema
5656

57+
base_schema = apischema.schema(
58+
extra={
59+
"x-taplo-info": {
60+
"authors": ["d-biehl (https://github.com/d-biehl)"],
61+
"patterns": ["^(.*(/|\\\\)robot\\.toml|robot\\.toml)$"],
62+
}
63+
}
64+
)
5765
schema = apischema.json_schema.deserialization_schema(
5866
RobotConfig,
5967
additional_properties=False,
6068
aliaser=lambda x: x.replace("_", "-"),
6169
version=apischema.json_schema.JsonSchemaVersion.DRAFT_7,
6270
all_refs=True,
71+
schema=base_schema,
6372
)
6473

65-
schema["x-taplo-info"] = {
66-
"authors": ["d-biehl (https://github.com/d-biehl)"],
67-
"patterns": ["^(.*(/|\\\\)robot\\.toml|robot\\.toml)$"],
68-
}
74+
# schema["x-taplo-info"] = {
75+
# "authors": ["d-biehl (https://github.com/d-biehl)"],
76+
# "patterns": ["^(.*(/|\\\\)robot\\.toml|robot\\.toml)$"],
77+
# }
6978

7079
json_str = json.dumps(schema, indent=2, sort_keys=True)
7180
pathlib.Path("etc", "robot.toml.json").write_text(json_str, "utf-8")

0 commit comments

Comments
 (0)