Skip to content
Open
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
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ maintainers = [
]
requires-python = ">=3.10"
dependencies = [
"click>=8.0.0",
"jinja2>=3.1.4",
"robotframework>=5.0,<7.5",
"typer>=0.12.5",
"typer>=0.26.0",
"rich>=10.11.0",
"tomli==2.2.1; python_version < '3.11'",
"tomli-w>=1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/robocop/config/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from pathlib import Path
from typing import Any

import click
import typer
from typer._click.exceptions import FileError
Comment thread
bhirsz marked this conversation as resolved.

try:
import tomllib as toml # type: ignore[import-not-found]
Expand Down Expand Up @@ -141,7 +141,7 @@ def load_toml_file(config_path: Path) -> dict[str, Any]:
config: dict[str, Any] = toml.load(tf)
return config
except (toml.TOMLDecodeError, OSError) as e:
raise click.FileError(filename=str(config_path), hint=f"Error reading configuration file: {e}") from None
raise FileError(filename=str(config_path), hint=f"Error reading configuration file: {e}") from None


def merge_dicts(dict1: dict[str, Any], dict2: dict[str, Any]) -> dict[str, Any]:
Expand Down
2 changes: 1 addition & 1 deletion src/robocop/formatter/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run(self) -> int:
# if str(source) == "-":
# stdin = True
# if self.config.verbose:
# click.echo("Loading file from stdin")
# typer.echo("Loading file from stdin")
# source = self.load_from_stdin()
if self.config.verbose:
print(f"Formatting {source_file.path} file")
Expand Down
4 changes: 2 additions & 2 deletions src/robocop/formatter/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
from typing import TYPE_CHECKING

import click
import typer
from rich.markup import escape
from robot.api.parsing import Comment, End, If, IfHeader, ModelVisitor, Token
from robot.parsing.model import Statement
Expand All @@ -19,7 +19,7 @@ def validate_regex(value: str | None) -> re.Pattern[str] | None:
try:
return re.compile(value) if value is not None else None
except re.error:
raise click.BadParameter("Not a valid regular expression") from None
raise typer.BadParameter("Not a valid regular expression") from None


def decorate_diff_with_color(contents: list[str]) -> list[str]:
Expand Down
31 changes: 24 additions & 7 deletions src/robocop/run.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import textwrap
from importlib import metadata
from pathlib import Path
from typing import Annotated, Any

import click
import typer
from rich.console import Console

from robocop import __version__
from robocop.config import defaults, manager, parser, schema
from robocop.formatter.runner import RobocopFormatter
from robocop.linter import rules_list
Expand All @@ -20,11 +19,7 @@


class CliWithVersion(typer.core.TyperGroup):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
click.version_option(version=__version__)(self)

def list_commands(self, ctx: click.Context) -> list[str]: # noqa: ARG002
def list_commands(self, ctx: Any) -> list[str]: # noqa: ARG002
"""Return the list of commands in the set order."""
commands = ["check", "check-project", "format", "list", "docs"]
for command in self.commands:
Expand All @@ -45,6 +40,28 @@ def list_commands(self, ctx: click.Context) -> list[str]: # noqa: ARG002
app.add_typer(list_app, name="list")


def version_callback(value: bool | None) -> None:
if not value:
return
typer.echo(f"robocop, version {metadata.version('robotframework-robocop')}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already store the version under from robocop import version, why not use it? Is there any reason for chosing metadata.version over the version from the package directly?

raise typer.Exit
Comment on lines +46 to +47


@app.callback()
def main_callback(
version: Annotated[
bool | None,
typer.Option(
"--version",
help="Show the version and exit.",
callback=version_callback,
is_eager=True,
),
] = None,
) -> None:
"""Run Robocop."""


config_option = Annotated[
Path | None,
typer.Option(
Expand Down
8 changes: 4 additions & 4 deletions src/robocop/runtime/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, NamedTuple

import click
import typer

try:
from robot.api import Languages # RF 6.0
Expand Down Expand Up @@ -164,7 +164,7 @@ def check_unmatched_filters(self) -> None:
]

if errors:
click.echo("\n".join(errors), err=True)
typer.echo("\n".join(errors), err=True)


def is_checker(checker_class_def: tuple[str, type]) -> bool:
Expand All @@ -189,14 +189,14 @@ def can_run_in_robot_version(formatter: Formatter, overwritten: bool, target_ver
if overwritten:
# --select FormatterDisabledInVersion or --configure FormatterDisabledInVersion.enabled=True
if target_version == ROBOT_VERSION.major:
click.echo(
typer.echo(
f"{formatter.__class__.__name__} formatter requires Robot Framework {min_version}.* "
f"version but you have {ROBOT_VERSION} installed. "
f"Upgrade installed Robot Framework if you want to use this formatter.",
err=True,
)
else:
click.echo(
typer.echo(
f"{formatter.__class__.__name__} formatter requires Robot Framework {min_version}.* "
f"version but you set --target-version rf{target_version}. "
f"Set --target-version to {min_version} or do not forcefully enable this formatter "
Expand Down
6 changes: 3 additions & 3 deletions tests/config/test_extend_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import textwrap
from pathlib import Path

import click
import pytest
import typer
from typer._click.exceptions import FileError

from robocop.config.parser import read_toml_config
from robocop.config.schema import RawConfig
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_invalid_toml_file(self):
# Arrange
config_path = DATA_DIR / "extends" / "invalid.toml"
# Act
with pytest.raises(click.FileError) as exc_info:
with pytest.raises(FileError) as exc_info:
read_toml_config(config_path)
# Assert
assert (
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_extend_does_not_exist(self, tmp_path):
""",
)
# Act
with pytest.raises(click.FileError) as exc_info:
with pytest.raises(FileError) as exc_info:
read_toml_config(config_path)
# Assert
assert "Error reading configuration file: [Errno 2] No such file or directory:" in exc_info.value.message
4 changes: 2 additions & 2 deletions tests/formatter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from difflib import unified_diff
from pathlib import Path

import click
import pytest
import typer
from packaging import version
from packaging.specifiers import SpecifierSet
from rich.console import Console
Expand Down Expand Up @@ -91,7 +91,7 @@ def run_tidy(
source_path = self.FORMATTERS_DIR / self.FORMATTER_NAME / "source"
else:
source_path = self.FORMATTERS_DIR / self.FORMATTER_NAME / "source" / source
with pytest.raises(click.exceptions.Exit) as exc_info:
with pytest.raises(typer.Exit) as exc_info:
format_files(
sources=[source_path],
select=select,
Expand Down
6 changes: 3 additions & 3 deletions tests/linter/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from typing import TYPE_CHECKING
from unittest import mock

import click.exceptions
import pytest
import typer
from rich.console import Console

from robocop.run import check_files, check_project
Expand Down Expand Up @@ -132,7 +132,7 @@ def check_rule(
configure.append(f"print_issues.output_format={output_format}")
with isolated_output() as output, working_directory(test_data):
try:
with pytest.raises(click.exceptions.Exit) as exc_info:
with pytest.raises(typer.Exit) as exc_info:
test_fn(
sources=paths,
select=select,
Expand Down Expand Up @@ -202,7 +202,7 @@ def check_rule_fix(

with isolated_output() as output, working_directory(test_data):
try:
with pytest.raises(click.exceptions.Exit):
with pytest.raises(typer.Exit):
check_files(
sources=paths,
select=select,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Test CLI commands / options common for linter and formatter."""

from importlib import metadata
from pathlib import Path
from unittest.mock import patch

import pytest
from typer.testing import CliRunner

from robocop import __version__
from robocop.run import app
from robocop.version_handling import ROBOT_VERSION
from tests import working_directory
Expand All @@ -15,7 +15,7 @@
def test_version():
runner = CliRunner()
result = runner.invoke(app, ["--version"])
assert result.stdout == f"robocop, version {__version__}\n"
assert result.stdout == f"robocop, version {metadata.version('robotframework-robocop')}\n"


def test_print_docs_rule():
Expand Down
23 changes: 15 additions & 8 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading