Skip to content

Commit e69465b

Browse files
committed
style: switch completly to ruff for formatting and style
1 parent 1a3cb65 commit e69465b

File tree

37 files changed

+128
-95
lines changed

37 files changed

+128
-95
lines changed

.devcontainer/devcontainer.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"tamasfe.even-better-toml",
4242
"gruntfuggly.todo-tree",
4343
"charliermarsh.ruff",
44-
"ms-python.black-formatter",
4544
"ms-python.mypy-type-checker",
4645
"ms-python.debugpy"
4746
],
@@ -82,12 +81,7 @@
8281
"^(.*(/|\\\\)\\.?robot\\.toml|\\.?robot\\.toml)$": "http://localhost:8000/etc/robot.toml.json"
8382
},
8483
"mypy-type-checker.importStrategy": "fromEnvironment",
85-
"debugpy.debugJustMyCode": false,
86-
"black-formatter.importStrategy": "fromEnvironment",
87-
"black-formatter.args": [
88-
"--config",
89-
"${workspaceFolder}./pyproject.toml"
90-
]
84+
"debugpy.debugJustMyCode": false
9185
}
9286
}
9387
}

.pre-commit-config.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,4 @@ repos:
4949
pass_filenames: false
5050
language: system
5151
stages: [pre-commit]
52-
types:
53-
- "javascript"
52+
types_or: [javascript, jsx, ts, tsx]

.vscode/extensions.json

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"tamasfe.even-better-toml",
99
"gruntfuggly.todo-tree",
1010
"charliermarsh.ruff",
11-
"ms-python.black-formatter",
1211
"ms-python.mypy-type-checker"
1312
]
1413
}

hatch.toml

+14-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ dependencies = [
2222
"pytest-cov",
2323
"mypy",
2424
"ruff",
25-
"black",
2625
"debugpy",
2726
"GitPython",
2827
"semantic-version",
@@ -98,7 +97,7 @@ matrix.rf.dependencies = [
9897
{ value = "robotframework>=7.1, <7.2", if = [
9998
"rf71",
10099
] },
101-
{ value = "robotframework>=7.2, <7.3", if = [
100+
{ value = "robotframework>=7.2, <7.3", if = [
102101
"rf72",
103102
] },
104103
]
@@ -150,10 +149,8 @@ features = ["all"]
150149

151150

152151
[envs.lint.scripts]
153-
typing-py = "mypy --no-incremental --cache-dir /dev/null {args:.}"
154-
typing = ["typing-py", "npm run compile"]
155-
style = ["ruff check .", "black --check --diff .", "npx eslint ."]
156-
fmt = ["black .", "ruff check --fix .", "style", "npx eslint --fix ."]
152+
typing = "mypy --no-incremental --cache-dir /dev/null {args:.}"
153+
style = ["ruff check .", "ruff format --diff ."]
157154
all = ["style", "typing"]
158155

159156
[envs.lint.overrides]
@@ -178,3 +175,14 @@ extract-release-notes = ["python scripts/extract_release_notes.py"]
178175
is-prerelease = ["python scripts/is_prerelease.py"]
179176
bump = ["cz bump {args}"]
180177
install-bundled-editable = "python ./scripts/install_bundled_editable.py"
178+
179+
180+
[envs.hatch-static-analysis]
181+
installer="uv"
182+
dependencies = ["ruff"]
183+
184+
[envs.hatch-static-analysis.scripts]
185+
format-check = ["ruff format --check --diff {args:.}"]
186+
format-fix = ["ruff format {args:.}"]
187+
lint-check = ["ruff check {args:.}"]
188+
lint-fix = "ruff check --fix {args:.}"

packages/core/src/robotcode/core/concurrent.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def acquire(self, blocking: bool = True, timeout: Optional[float] = None) -> boo
5353
aquired = self._lock.acquire(blocking, timeout=timeout)
5454
if not aquired and blocking and timeout > 0:
5555
raise RuntimeError(
56-
f"Could not acquire {self.__class__.__qualname__} {self.name+' ' if self.name else ' '}in {timeout}s."
56+
f"Could not acquire {self.__class__.__qualname__} {self.name + ' ' if self.name else ' '}in {timeout}s."
5757
)
5858
return aquired
5959

packages/core/src/robotcode/core/utils/dataclasses.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ def from_dict(
488488
(
489489
(getattr(e, "__name__", None) or str(e) if e is not type(None) else "None")
490490
if _get_origin_cached(e) is not Literal
491-
else repr(e).replace("typing.", "") if e is not None else "None"
491+
else repr(e).replace("typing.", "")
492+
if e is not None
493+
else "None"
492494
)
493495
for e in types
494496
)

packages/core/src/robotcode/core/utils/logging.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ def __init_logger(self) -> LoggingDescriptor:
149149
else (
150150
("" if self.__owner is None else self.__owner.__module__ + "." + self.__owner.__qualname__)
151151
if self.__owner is not None
152-
else get_unwrapped_func(self.__func).__module__ if self.__func is not None else "<unknown>"
152+
else get_unwrapped_func(self.__func).__module__
153+
if self.__func is not None
154+
else "<unknown>"
153155
)
154156
+ self.__postfix
155157
)

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

-2
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@ def set_breakpoints(
547547
lines: Optional[List[int]] = None,
548548
source_modified: Optional[bool] = None,
549549
) -> List[Breakpoint]:
550-
551550
if self.is_windows_path(source.path or ""):
552551
path: pathlib.PurePath = pathlib.PureWindowsPath(source.path or "")
553552
else:
@@ -647,7 +646,6 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
647646
if source_path in self.breakpoints:
648647
breakpoints = [v for v in self.breakpoints[source_path].breakpoints if v.line == line_no]
649648
if len(breakpoints) > 0:
650-
651649
for point in breakpoints:
652650
if point.condition is not None:
653651
hit = False

packages/debugger/src/robotcode/debugger/launcher/server.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ async def _launch(
245245
kind=(
246246
RunInTerminalKind.INTEGRATED
247247
if console == "integratedTerminal"
248-
else RunInTerminalKind.EXTERNAL if console == "externalTerminal" else None
248+
else RunInTerminalKind.EXTERNAL
249+
if console == "externalTerminal"
250+
else None
249251
),
250252
title=name,
251253
)

packages/debugger/src/robotcode/debugger/protocol.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DebugAdapterErrorResponseError(JsonRPCException):
4444
def __init__(self, error: ErrorResponse) -> None:
4545
super().__init__(
4646
f'{error.message} (seq={error.request_seq} command="{error.command}")'
47-
f'{f": {error.body.error}" if error.body is not None and error.body.error else ""}'
47+
f"{f': {error.body.error}' if error.body is not None and error.body.error else ''}"
4848
)
4949
self.error = error
5050

@@ -60,7 +60,7 @@ def __init__(
6060
) -> None:
6161
super().__init__(
6262
f'{(message + " ") if message else ""}(seq={request_seq} command="{command}")'
63-
f'{f": {error_message}" if error_message else ""}'
63+
f"{f': {error_message}' if error_message else ''}"
6464
)
6565
self.message = message
6666
self.request_seq = request_seq

packages/jsonrpc2/src/robotcode/jsonrpc2/server.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def start(self) -> None:
9494
(
9595
self.tcp_params.host
9696
if isinstance(self.tcp_params.host, str)
97-
else self.tcp_params.host[0] if self.tcp_params.host else None
97+
else self.tcp_params.host[0]
98+
if self.tcp_params.host
99+
else None
98100
),
99101
)
100102
else:

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ def run_workspace_diagnostics(self) -> None:
399399
folder = self.parent.workspace.get_workspace_folder(document.uri)
400400
name = path if folder is None else path.relative_to(folder.uri.to_path())
401401

402-
progress.report(f"Analyze {i+1}/{len(documents)}: {name}", current=i + 1)
402+
progress.report(f"Analyze {i + 1}/{len(documents)}: {name}", current=i + 1)
403403
elif analysis_mode == AnalysisProgressMode.SIMPLE:
404404
progress.begin()
405-
progress.report(f"Analyze {i+1}/{len(documents)}", current=i + 1)
405+
progress.report(f"Analyze {i + 1}/{len(documents)}", current=i + 1)
406406

407407
try:
408408
with self._current_diagnostics_task_lock:
@@ -490,10 +490,10 @@ def run_workspace_diagnostics(self) -> None:
490490
folder = self.parent.workspace.get_workspace_folder(document.uri)
491491
name = path if folder is None else path.relative_to(folder.uri.to_path())
492492

493-
progress.report(f"Collect {i+1}/{len(documents_to_collect)}: {name}", current=i + 1)
493+
progress.report(f"Collect {i + 1}/{len(documents_to_collect)}: {name}", current=i + 1)
494494
elif analysis_mode == AnalysisProgressMode.SIMPLE:
495495
progress.begin()
496-
progress.report(f"Collect {i+1}/{len(documents_to_collect)}", current=i + 1)
496+
progress.report(f"Collect {i + 1}/{len(documents_to_collect)}", current=i + 1)
497497

498498
try:
499499
with self._current_diagnostics_task_lock:

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None:
8383
full=(
8484
SemanticTokensOptionsFullType1(delta=True if len(self.collect_full_delta) else None)
8585
if len(self.collect_full) and len(self.collect_full_delta)
86-
else True if len(self.collect_full) else None
86+
else True
87+
if len(self.collect_full)
88+
else None
8789
),
8890
range=True if len(self.collect_range) else None,
8991
)

packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_documentation.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ def collect(
9090
(
9191
node.value
9292
if isinstance(node, (TestTemplate, Template))
93-
else node.keyword if isinstance(node, KeywordCall) else node.name
93+
else node.keyword
94+
if isinstance(node, KeywordCall)
95+
else node.name
9496
),
9597
cast(
9698
Token,

packages/language_server/src/robotcode/language_server/robotframework/parts/completion.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,9 @@ def complete_import() -> Optional[List[CompletionItem]]:
17331733
else (
17341734
CompletionItemKind.FILE
17351735
if e.kind == CompleteResultKind.FILE
1736-
else CompletionItemKind.FOLDER if e.kind == CompleteResultKind.FOLDER else None
1736+
else CompletionItemKind.FOLDER
1737+
if e.kind == CompleteResultKind.FOLDER
1738+
else None
17371739
)
17381740
),
17391741
detail=e.kind.value,
@@ -1928,7 +1930,9 @@ def complete_ResourceImport( # noqa: N802
19281930
else (
19291931
CompletionItemKind.FILE
19301932
if e.kind == CompleteResultKind.FILE
1931-
else CompletionItemKind.FOLDER if e.kind == CompleteResultKind.FOLDER else None
1933+
else CompletionItemKind.FOLDER
1934+
if e.kind == CompleteResultKind.FOLDER
1935+
else None
19321936
)
19331937
),
19341938
detail=e.kind.value,
@@ -2050,7 +2054,9 @@ def complete_import() -> Optional[List[CompletionItem]]:
20502054
else (
20512055
CompletionItemKind.FILE
20522056
if e.kind == CompleteResultKind.FILE
2053-
else CompletionItemKind.FOLDER if e.kind == CompleteResultKind.FOLDER else None
2057+
else CompletionItemKind.FOLDER
2058+
if e.kind == CompleteResultKind.FOLDER
2059+
else None
20542060
)
20552061
),
20562062
detail=e.kind.value,

packages/language_server/src/robotcode/language_server/robotframework/parts/hover.py

-2
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,12 @@ def _hover_default(self, nodes: List[ast.AST], document: TextDocument, position:
166166
text = f"### {variable.type.value.title()} `{variable.name}`\n\n"
167167

168168
if value:
169-
170169
text += "```python\n"
171170
text += f"value: {type(real_value).__name__} = {value}\n"
172171
text += "```\n"
173172

174173
text += "\n"
175174
if text:
176-
177175
return Hover(
178176
contents=MarkupContent(kind=MarkupKind.MARKDOWN, value=text),
179177
range=highlight_range,

packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py

-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ def generate_sem_sub_tokens(
354354
length: Optional[int] = None,
355355
yield_arguments: bool = False,
356356
) -> Iterator[SemTokenInfo]:
357-
358357
sem_info = self.mapping().get(token.type, None) if token.type is not None else None
359358
if sem_info is not None:
360359
sem_type, sem_mod = sem_info

packages/plugin/src/robotcode/plugin/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ def print_data(
165165
text = tomli_w.dumps(
166166
as_dict(data, remove_defaults=remove_defaults)
167167
if dataclasses.is_dataclass(data)
168-
else data if isinstance(data, dict) else {data: data}
168+
else data
169+
if isinstance(data, dict)
170+
else {data: data}
169171
)
170172

171173
if text is None:

packages/repl/src/robotcode/repl/console_interpreter.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def log_message(
110110
if is_true(html):
111111
message = f"*HTML*{message}"
112112

113-
self.app.echo(f"{' '*self.indent}[ {level} ] {message}", file=sys.__stdout__ if std_err else sys.__stderr__)
113+
self.app.echo(f"{' ' * self.indent}[ {level} ] {message}", file=sys.__stdout__ if std_err else sys.__stderr__)
114114

115115
def message(
116116
self, message: str, level: str, html: Union[str, bool] = False, timestamp: Union[datetime, str, None] = None
@@ -126,7 +126,8 @@ def start_keyword(self, data: "running.Keyword", result: "result.Keyword") -> No
126126
return
127127

128128
self.app.echo(
129-
f"{' '*self.indent}KEYWORD {result.libname}.{result.kwname} {' '.join(result.args)}", file=sys.__stdout__
129+
f"{' ' * self.indent}KEYWORD {result.libname}.{result.kwname} {' '.join(result.args)}",
130+
file=sys.__stdout__,
130131
)
131132
self.indent += 1
132133

packages/robot/src/robotcode/robot/diagnostics/data_cache.py

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def __init__(self, cache_dir: Path) -> None:
4040

4141

4242
class JsonDataCache(FileCacheDataBase):
43-
4443
def build_cache_data_filename(self, section: CacheSection, entry_name: str) -> Path:
4544
return self.cache_dir / section.value / (entry_name + ".json")
4645

packages/robot/src/robotcode/robot/diagnostics/imports_manager.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ def _update(self) -> None:
226226
source_or_origin = (
227227
self._lib_doc.source
228228
if self._lib_doc.source is not None
229-
else self._lib_doc.module_spec.origin if self._lib_doc.module_spec is not None else None
229+
else self._lib_doc.module_spec.origin
230+
if self._lib_doc.module_spec is not None
231+
else None
230232
)
231233

232234
# we are a module, so add the module path into file watchers
@@ -1226,8 +1228,7 @@ def _get_library_libdoc(
12261228
saved_meta = self.data_cache.read_cache_data(CacheSection.LIBRARY, meta_file, LibraryMetaData)
12271229
if saved_meta.has_errors:
12281230
self._logger.debug(
1229-
lambda: f"Saved library spec for {name}{args!r} is not used "
1230-
"due to errors in meta data",
1231+
lambda: f"Saved library spec for {name}{args!r} is not used due to errors in meta data",
12311232
context_name="import",
12321233
)
12331234

packages/robot/src/robotcode/robot/diagnostics/library_doc.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,9 @@ def get_library_doc(
17971797
source=(
17981798
source or module_spec.origin
17991799
if module_spec is not None and module_spec.origin
1800-
else import_name if is_library_by_path(import_name) else None
1800+
else import_name
1801+
if is_library_by_path(import_name)
1802+
else None
18011803
),
18021804
module_spec=module_spec,
18031805
errors=[
@@ -1806,7 +1808,9 @@ def get_library_doc(
18061808
(
18071809
source or module_spec.origin
18081810
if module_spec is not None and module_spec.origin
1809-
else import_name if is_library_by_path(import_name) else None
1811+
else import_name
1812+
if is_library_by_path(import_name)
1813+
else None
18101814
),
18111815
(
18121816
1
@@ -2402,7 +2406,9 @@ def _get_initial_handler(self, library: Any, name: Any, method: Any) -> Any:
24022406
(
24032407
source or module_spec.origin
24042408
if module_spec is not None and module_spec.origin
2405-
else import_name if is_variables_by_path(import_name) else None
2409+
else import_name
2410+
if is_variables_by_path(import_name)
2411+
else None
24062412
),
24072413
(
24082414
1
@@ -2426,7 +2432,9 @@ def _get_initial_handler(self, library: Any, name: Any, method: Any) -> Any:
24262432
(
24272433
source or module_spec.origin
24282434
if module_spec is not None and module_spec.origin
2429-
else import_name if is_variables_by_path(import_name) else None
2435+
else import_name
2436+
if is_variables_by_path(import_name)
2437+
else None
24302438
),
24312439
1 if source is not None or (module_spec is not None and module_spec.origin is not None) else None,
24322440
)

0 commit comments

Comments
 (0)