Skip to content

fix: References to upstream click causing further side effects (#1754)#1755

Open
Meizzajanor wants to merge 2 commits into
MarketSquare:mainfrom
Meizzajanor:replace-click-with-typer
Open

fix: References to upstream click causing further side effects (#1754)#1755
Meizzajanor wants to merge 2 commits into
MarketSquare:mainfrom
Meizzajanor:replace-click-with-typer

Conversation

@Meizzajanor
Copy link
Copy Markdown
Contributor

This pull request removes the dependency on click and fully migrates the CLI and related error handling to use typer and its APIs. It updates imports, exception handling, and test code accordingly. Additionally, it refactors the version display logic to use importlib.metadata for version retrieval.

Key changes include:

Dependency and Import Cleanup:

  • Removed click from the dependencies in pyproject.toml and all code imports, replacing them with typer or typer._click.exceptions where necessary. [1] [2] [3] [4] [5] [6] [7]

Error and Exception Handling:

  • Replaced all uses of click.FileError and click.BadParameter with typer equivalents throughout the codebase and tests, ensuring consistent error handling. [1] [2] [3] [4]

CLI Output and Echo:

  • Updated all click.echo calls to typer.echo for output and error messages. [1] [2] [3]

CLI Version Handling:

  • Refactored version reporting to use a --version option handled via a typer callback, retrieving the version with importlib.metadata instead of importing from the package. [1] [2] [3] [4] [5]

Test Suite Updates:

  • Updated all test cases to use typer.Exit and related exceptions instead of click exceptions, ensuring tests remain valid after the migration. [1] [2] [3]

These changes collectively modernize the CLI implementation, streamline dependencies, and improve maintainability by unifying on the typer library.

Issues:
Closes #1754 .

Copilot AI review requested due to automatic review settings May 27, 2026 03:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Replaces direct click dependency usage with typer equivalents throughout the codebase, and switches __version__ import to importlib.metadata.

Changes:

  • Remove click from dependencies and replace click.echo, click.BadParameter, click.exceptions.Exit, click.FileError with typer equivalents.
  • Replace click.version_option with an explicit Typer --version callback.
  • Use importlib.metadata.version("robotframework-robocop") instead of robocop.__version__.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pyproject.toml Drops click dependency.
src/robocop/run.py Replaces click version_option with Typer callback; uses importlib.metadata.
src/robocop/runtime/resolver.py Switches click.echo to typer.echo.
src/robocop/formatter/runner.py Updates a comment from click to typer.
src/robocop/formatter/utils/misc.py Uses typer.BadParameter instead of click.
src/robocop/config/parser.py Imports FileError from typer._click.exceptions.
tests/config/test_extend_config.py Updates exception class to typer's FileError.
tests/formatter/init.py Replaces click.exceptions.Exit with typer.Exit.
tests/linter/utils/init.py Replaces click.exceptions.Exit with typer.Exit.
tests/test_cli.py Uses importlib.metadata.version for version assertion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/robocop/config/parser.py
Comment thread src/robocop/run.py
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
Comment thread src/robocop/run.py
Comment on lines +46 to +47
typer.echo(f"robocop, version {metadata.version('robotframework-robocop')}")
raise typer.Exit
Comment thread src/robocop/run.py
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

References to upstream click causing further side effects

3 participants