From e80166f47fda2904b5f9c56fba7416b0064b39b7 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Tue, 27 Jan 2026 15:37:07 +0900 Subject: [PATCH 1/3] Remove typer dependency --- README.md | 5 +++-- pyodide_cli/app.py | 21 +++++++++++++++------ pyodide_cli/tests/test_cli.py | 6 ++---- pyproject.toml | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c972c32..8cbc5b7 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,9 @@ You can register a subcommand in the `pyodide` CLI in your own package by: do_something = ".cli:main" ``` - where in this example `main` needs to be a function with type annotations - that can be converted to a CLI with [typer](https://typer.tiangolo.com/). + where in this example `main` needs to be either: + - A [click](https://click.palletsprojects.com/) command/group (recommended) + - A [typer](https://typer.tiangolo.com/) app or function (requires `typer` to be installed) ## License diff --git a/pyodide_cli/app.py b/pyodide_cli/app.py index b8a7a97..ddd54e3 100644 --- a/pyodide_cli/app.py +++ b/pyodide_cli/app.py @@ -4,13 +4,22 @@ from importlib.metadata import Distribution, EntryPoint from importlib.metadata import distribution as importlib_distribution from importlib.metadata import entry_points -from typing import override +from typing import TYPE_CHECKING, override import click -import typer from . import __version__ +if TYPE_CHECKING: + import typer + +try: + import typer # noqa: F811 + + TYPER_AVAILABLE = True +except ImportError: + TYPER_AVAILABLE = False + class OriginGroup(click.Group): """A click Group to support grouped command help message by its origin.""" @@ -154,9 +163,9 @@ def register_plugins(): pkgname = _entrypoint_to_pkgname(ep) if isinstance(module, click.Command): cmd = module - elif isinstance(module, typer.Typer): + elif TYPER_AVAILABLE and isinstance(module, typer.Typer): cmd = typer.main.get_command(module) - elif callable(module): + elif TYPER_AVAILABLE and callable(module): typer_kwargs = getattr(module, "typer_kwargs", {}) app = typer.Typer() app.command( @@ -176,9 +185,9 @@ def main(): if "sphinx" in sys.modules and __name__ != "__main__": - # Create the typer click object to generate docs with sphinx-click + # Create the click object to generate docs with sphinx-click register_plugins() - typer_click_object = cli + click_object = cli if __name__ == "__main__": main() diff --git a/pyodide_cli/tests/test_cli.py b/pyodide_cli/tests/test_cli.py index 6fa2c15..fdc7daf 100644 --- a/pyodide_cli/tests/test_cli.py +++ b/pyodide_cli/tests/test_cli.py @@ -39,8 +39,6 @@ def test_cli_version(plugins): def test_click_click_object_defintion(): - # By default the typer-click-object is not defined - # Run in a separate process to make s q = Queue() def func(q: Queue, with_sphinx=False): @@ -56,13 +54,13 @@ def func(q: Queue, with_sphinx=False): p.start() p.join() app_dir = q.get() - assert "typer_click_object" not in app_dir + assert "click_object" not in app_dir p = Process(target=func, args=(q,), kwargs={"with_sphinx": True}) p.start() p.join() app_dir = q.get() - assert "typer_click_object" in app_dir + assert "click_object" in app_dir def test_plugin_origin(plugins): diff --git a/pyproject.toml b/pyproject.toml index 3abf02e..b446516 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ classifiers = [ ] requires-python = ">= 3.12" dependencies = [ - "typer", + "click", "rich", ] From 707dbe134e7643ea05cf33d0bbfeafa11a783214 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Tue, 27 Jan 2026 15:41:41 +0900 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4df26c..bafc0d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.5.0] - 2026-01-27 + +### Changed + +- `typer` is now optional dependency, and will not be installed by default. + Packages using `typer` should now explicitly install `typer` as a dependency. + ([#55](https://github.com/pyodide/pyodide-cli/pull/55)) + ## [0.4.0] - 2025-09-07 ### Changed From 64f58359faacb66b4c406def13c3002a8d9297f7 Mon Sep 17 00:00:00 2001 From: ryanking13 Date: Wed, 28 Jan 2026 12:26:58 +0900 Subject: [PATCH 3/3] install typer when testing --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b446516..1cb979a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,10 @@ Homepage = "https://github.com/pyodide/pyodide" Documentation = "https://pyodide.org/en/stable/" [project.optional-dependencies] -test = ["pytest"] +test = [ + "pytest", + "typer", +] [tool.hatch.version] source = "vcs"