1818from types import SimpleNamespace
1919from typing import Annotated , Any , NoReturn
2020
21- import click
2221import typer
2322import yaml
2423from jinja2 import Environment , PackageLoader , StrictUndefined
4847from .exceptions import UserError
4948from .logs import DEFAULT_CONSOLE , set_logger
5049
50+ # typer >= 0.26 vendors its own click (and drops the click dependency), so the
51+ # Context type, exceptions, and context lookups must come from the click typer
52+ # actually runs; fall back to real click on older typer (which still ships it).
53+ try :
54+ from typer ._click .core import Context
55+ from typer ._click .exceptions import UsageError
56+ from typer ._click .globals import get_current_context
57+ except ImportError : # typer < 0.26
58+ from click import Context , UsageError , get_current_context
59+
5160logger = getLogger ("tesseract" )
5261
5362# Jinja2 Template Environment
6271class SpellcheckedTyperGroup (typer .core .TyperGroup ):
6372 """A Typer group that suggests similar commands if a command is not found."""
6473
65- def get_command (self , ctx : click . Context , invoked_command : str ) -> Any :
74+ def get_command (self , ctx : Context , invoked_command : str ) -> Any :
6675 """Get a command from the Typer group, suggesting similar commands if the command is not found."""
6776 import difflib
6877
@@ -72,7 +81,7 @@ def get_command(self, ctx: click.Context, invoked_command: str) -> Any:
7281 invoked_command , possible_commands , n = 1 , cutoff = 0.6
7382 )
7483 if close_match :
75- raise click . UsageError (
84+ raise UsageError (
7685 f"No such command '{ invoked_command } '. Did you mean '{ close_match [0 ]} '?" ,
7786 ctx ,
7887 )
@@ -1124,7 +1133,7 @@ def run_container(
11241133
11251134 if not tesseract_image :
11261135 if invoke_help :
1127- click . get_current_context ().get_help ()
1136+ get_current_context ().get_help ()
11281137 return
11291138 raise typer .BadParameter (
11301139 "Tesseract image name is required." ,
@@ -1133,7 +1142,7 @@ def run_container(
11331142
11341143 if not cmd :
11351144 if invoke_help :
1136- click . get_current_context ().get_help ()
1145+ get_current_context ().get_help ()
11371146 return
11381147 else :
11391148 error_string = f"Command is required. Are you sure your Tesseract image name is `{ tesseract_image } `?"
0 commit comments