44from importlib .metadata import Distribution , EntryPoint
55from importlib .metadata import distribution as importlib_distribution
66from importlib .metadata import entry_points
7- from typing import override
7+ from typing import TYPE_CHECKING , override
88
99import click
10- import typer
1110
1211from . import __version__
1312
13+ if TYPE_CHECKING :
14+ import typer
15+
16+ try :
17+ import typer # noqa: F811
18+
19+ TYPER_AVAILABLE = True
20+ except ImportError :
21+ TYPER_AVAILABLE = False
22+
1423
1524class OriginGroup (click .Group ):
1625 """A click Group to support grouped command help message by its origin."""
@@ -154,9 +163,9 @@ def register_plugins():
154163 pkgname = _entrypoint_to_pkgname (ep )
155164 if isinstance (module , click .Command ):
156165 cmd = module
157- elif isinstance (module , typer .Typer ):
166+ elif TYPER_AVAILABLE and isinstance (module , typer .Typer ):
158167 cmd = typer .main .get_command (module )
159- elif callable (module ):
168+ elif TYPER_AVAILABLE and callable (module ):
160169 typer_kwargs = getattr (module , "typer_kwargs" , {})
161170 app = typer .Typer ()
162171 app .command (
@@ -176,9 +185,9 @@ def main():
176185
177186
178187if "sphinx" in sys .modules and __name__ != "__main__" :
179- # Create the typer click object to generate docs with sphinx-click
188+ # Create the click object to generate docs with sphinx-click
180189 register_plugins ()
181- typer_click_object = cli
190+ click_object = cli
182191
183192if __name__ == "__main__" :
184193 main ()
0 commit comments