Skip to content

Commit 08119a1

Browse files
authored
Make typer optional (#55)
* Remove typer dependency * changelog * install typer when testing
1 parent 784c7b1 commit 08119a1

5 files changed

Lines changed: 33 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.5.0] - 2026-01-27
8+
9+
### Changed
10+
11+
- `typer` is now optional dependency, and will not be installed by default.
12+
Packages using `typer` should now explicitly install `typer` as a dependency.
13+
([#55](https://github.com/pyodide/pyodide-cli/pull/55))
14+
715
## [0.4.0] - 2025-09-07
816

917
### Changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ You can register a subcommand in the `pyodide` CLI in your own package by:
4545
do_something = "<your-package>.cli:main"
4646
```
4747

48-
where in this example `main` needs to be a function with type annotations
49-
that can be converted to a CLI with [typer](https://typer.tiangolo.com/).
48+
where in this example `main` needs to be either:
49+
- A [click](https://click.palletsprojects.com/) command/group (recommended)
50+
- A [typer](https://typer.tiangolo.com/) app or function (requires `typer` to be installed)
5051

5152

5253
## License

pyodide_cli/app.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@
44
from importlib.metadata import Distribution, EntryPoint
55
from importlib.metadata import distribution as importlib_distribution
66
from importlib.metadata import entry_points
7-
from typing import override
7+
from typing import TYPE_CHECKING, override
88

99
import click
10-
import typer
1110

1211
from . 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

1524
class 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

178187
if "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

183192
if __name__ == "__main__":
184193
main()

pyodide_cli/tests/test_cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ def test_cli_version(plugins):
3939

4040

4141
def test_click_click_object_defintion():
42-
# By default the typer-click-object is not defined
43-
# Run in a separate process to make s
4442
q = Queue()
4543

4644
def func(q: Queue, with_sphinx=False):
@@ -56,13 +54,13 @@ def func(q: Queue, with_sphinx=False):
5654
p.start()
5755
p.join()
5856
app_dir = q.get()
59-
assert "typer_click_object" not in app_dir
57+
assert "click_object" not in app_dir
6058

6159
p = Process(target=func, args=(q,), kwargs={"with_sphinx": True})
6260
p.start()
6361
p.join()
6462
app_dir = q.get()
65-
assert "typer_click_object" in app_dir
63+
assert "click_object" in app_dir
6664

6765

6866
def test_plugin_origin(plugins):

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ classifiers = [
1414
]
1515
requires-python = ">= 3.12"
1616
dependencies = [
17-
"typer",
17+
"click",
1818
"rich",
1919
]
2020

@@ -28,7 +28,10 @@ Homepage = "https://github.com/pyodide/pyodide"
2828
Documentation = "https://pyodide.org/en/stable/"
2929

3030
[project.optional-dependencies]
31-
test = ["pytest"]
31+
test = [
32+
"pytest",
33+
"typer",
34+
]
3235

3336
[tool.hatch.version]
3437
source = "vcs"

0 commit comments

Comments
 (0)