From 2ef387f68421f8313f8774cc28e7721c47c92220 Mon Sep 17 00:00:00 2001 From: Jesus Lopez Date: Mon, 2 Mar 2026 14:05:37 -0800 Subject: [PATCH] fix(deps): make typer an optional dependency Move typer to a `cli` optional extra so library consumers (e.g. the jackery-ha Home Assistant integration) don't pull in typer/rich, which can conflict with pre-installed versions in the HA Docker image. Guard the typer import in cli.py with a friendly error message when the extra is not installed. Fixes: #39 Co-Authored-By: Claude Opus 4.6 --- README.md | 15 +++++++++------ pyproject.toml | 5 ++++- src/socketry/cli.py | 5 ++++- uv.lock | 9 ++++++++- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f7a0764..386867f 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,14 @@ the device or its firmware. ## Quick start ```bash -uvx socketry login --email you@example.com --password 'yourpass' -uvx socketry get +uvx 'socketry[cli]' login --email you@example.com --password 'yourpass' +uvx 'socketry[cli]' get ``` Or install it once and use `socketry` directly: ```bash -uv tool install socketry +uv tool install 'socketry[cli]' socketry login --email you@example.com --password 'yourpass' socketry get ``` @@ -49,13 +49,16 @@ properties returned by newer firmware are displayed as raw key/value pairs. ```bash # Install as a CLI tool -uv tool install socketry +uv tool install 'socketry[cli]' # Or run directly without installing -uvx socketry --help +uvx 'socketry[cli]' --help -# Or install as a library +# Or install as a library only (no CLI dependencies) pip install socketry + +# Or install with CLI included +pip install 'socketry[cli]' ``` ## CLI usage diff --git a/pyproject.toml b/pyproject.toml index 62b5637..1a9ea76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,12 +9,14 @@ authors = [ requires-python = ">=3.11" license = "MIT" dependencies = [ - "typer>=0.9", "aiomqtt>=2.0", "aiohttp>=3.9", "pycryptodome>=3.19", ] +[project.optional-dependencies] +cli = ["typer>=0.9"] + [project.scripts] socketry = "socketry.cli:app" @@ -24,6 +26,7 @@ build-backend = "uv_build" [dependency-groups] dev = [ + "socketry[cli]", "aioresponses>=0.7", "mypy>=1.19.1", "pre-commit>=4.5.1", diff --git a/src/socketry/cli.py b/src/socketry/cli.py index a6a48ce..eaeb239 100644 --- a/src/socketry/cli.py +++ b/src/socketry/cli.py @@ -8,7 +8,10 @@ import sys from datetime import datetime -import typer +try: + import typer +except ImportError: + raise SystemExit("socketry CLI requires the 'cli' extra: pip install socketry[cli]") from None from socketry.client import Client from socketry.properties import GROUP_TITLES, MODEL_NAMES, PROPERTIES, Setting, resolve diff --git a/uv.lock b/uv.lock index be5fa39..161c53e 100644 --- a/uv.lock +++ b/uv.lock @@ -1073,6 +1073,10 @@ dependencies = [ { name = "aiohttp" }, { name = "aiomqtt" }, { name = "pycryptodome" }, +] + +[package.optional-dependencies] +cli = [ { name = "typer" }, ] @@ -1085,6 +1089,7 @@ dev = [ { name = "pytest-asyncio" }, { name = "pytest-cov" }, { name = "ruff" }, + { name = "socketry", extra = ["cli"] }, ] [package.metadata] @@ -1092,8 +1097,9 @@ requires-dist = [ { name = "aiohttp", specifier = ">=3.9" }, { name = "aiomqtt", specifier = ">=2.0" }, { name = "pycryptodome", specifier = ">=3.19" }, - { name = "typer", specifier = ">=0.9" }, + { name = "typer", marker = "extra == 'cli'", specifier = ">=0.9" }, ] +provides-extras = ["cli"] [package.metadata.requires-dev] dev = [ @@ -1104,6 +1110,7 @@ dev = [ { name = "pytest-asyncio", specifier = ">=0.26" }, { name = "pytest-cov", specifier = ">=6.0.0" }, { name = "ruff", specifier = ">=0.14.14" }, + { name = "socketry", extras = ["cli"] }, ] [[package]]