Skip to content

Commit 763fb2c

Browse files
committed
cli: fix compat with newer versions of typer
click-help-colors is no longer compatible with typer and the colours look fine as-is, so drop it. fastapi/typer#47 (comment) fixes #33
1 parent 330c199 commit 763fb2c

File tree

4 files changed

+9
-41
lines changed

4 files changed

+9
-41
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77

88
## [Unreleased]
9+
### Fixed
10+
- Compatibility with newer typer versions (#33).
911

1012

1113
## [1.1.0] - 2023-01-29

callsignlookuptools/__main__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@
1111

1212
from callsignlookuptools import __info__
1313
from callsignlookuptools.common.enums import DataSource
14-
from callsignlookuptools.cli import run_query, ColourTyper
14+
from callsignlookuptools.cli import run_query
1515

1616
try:
1717
import typer
18-
from typer import colors, echo, style
18+
from typer import colors, echo, style, Typer
1919
except ModuleNotFoundError:
2020
print(f"To use the {__info__.__project__} CLI you must install 'typer[all]'", file=stderr)
2121
raise SystemExit(42)
2222

2323

24-
app = ColourTyper(add_completion=False)
24+
epilog = (f"Copyright {__info__.__copyright__} by {__info__.__author__}. "
25+
f"Released under the {__info__.__license__} License")
26+
27+
app = Typer(context_settings={"help_option_names": ["-h", "--help"]}, epilog=epilog, add_completion=False)
2528

2629

2730
def version_callback(value: bool):

callsignlookuptools/cli.py

-37
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
print(f"To use the {__info__.__project__} CLI you must install 'typer[all]'", file=stderr)
2323
raise SystemExit(42)
2424

25-
try:
26-
from click_help_colors import HelpColorsCommand, HelpColorsGroup # type: ignore[import]
27-
except ModuleNotFoundError:
28-
secho(f"To use the {__info__.__project__} CLI you must install 'click-help-colors'", fg=colors.RED, err=True)
29-
raise typer.Exit(42)
30-
3125

3226
lookup_classes = {
3327
DataSource.QRZ: QrzSyncClient,
@@ -107,34 +101,3 @@ def run_query(source: DataSource, query: str, username: Optional[str] = None, pa
107101
else:
108102
secho("No callsign given", fg=colors.RED, err=True)
109103
raise typer.Exit(1)
110-
111-
112-
# The following is for adding colours to command help output
113-
# See https://github.com/tiangolo/typer/issues/47
114-
115-
class CustomHelpColoursGroup(HelpColorsGroup):
116-
def __init__(self, *args, **kwargs) -> None:
117-
super().__init__(*args, **kwargs)
118-
self.help_headers_color = "blue"
119-
self.help_options_color = "yellow"
120-
121-
122-
class CustomHelpColoursCommand(HelpColorsCommand):
123-
def __init__(self, *args, **kwargs) -> None:
124-
super().__init__(*args, **kwargs)
125-
self.help_headers_color = "blue"
126-
self.help_options_color = "yellow"
127-
128-
129-
epilog = (f"Copyright {__info__.__copyright__} by {__info__.__author__}. "
130-
f"Released under the {__info__.__license__} License")
131-
132-
133-
class ColourTyper(typer.Typer):
134-
def __init__(self, *args, cls=CustomHelpColoursGroup, context_settings={"help_option_names": ["-h", "--help"]},
135-
**kwargs) -> None:
136-
super().__init__(*args, cls=cls, context_settings=context_settings, epilog=epilog, **kwargs)
137-
138-
def command(self, *args, cls=CustomHelpColoursCommand, context_settings={"help_option_names": ["-h", "--help"]},
139-
**kwargs) -> Callable:
140-
return super().command(*args, cls=cls, context_settings=context_settings, epilog=epilog, **kwargs)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"requests; extra != 'async'"
4343
],
4444
extras_require={
45-
"cli": ["typer[all]", "click-help-colors"],
45+
"cli": ["typer[all]"],
4646
"async": ["aiohttp"],
4747
"all": ["aiohttp"]
4848
},

0 commit comments

Comments
 (0)