fix(operator): don't import the server stack on the operator path
cmd_chat/__init__.py eagerly imported run_server (sanic/pydantic) and Client, so any `cmd_chat.*` import — including `python -m cmd_chat.operator` — pulled the server stack at package init. On a phone/Termux operator that installs only the operator deps (and where srp may be unbuildable), this failed before the client's pure-SRP fallback could help. Make both imports lazy inside main()'s serve/connect branches. The operator path now imports cleanly with srp/sanic/pydantic all absent (client falls back to _srp_pure). Add a subprocess regression test to keep it that way. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,11 @@ import argparse
|
||||
import getpass
|
||||
import os
|
||||
|
||||
from cmd_chat.server.server import run_server
|
||||
from cmd_chat.client.client import Client
|
||||
# NOTE: the server (run_server) and client (Client) are imported lazily inside
|
||||
# main() below. Importing them here would pull sanic/pydantic (server) at
|
||||
# package-init time for *any* `cmd_chat.*` import — including
|
||||
# `python -m cmd_chat.operator` on a phone/Termux where those server-only deps
|
||||
# aren't installed. See docs/termux-operator.md (Phase 0).
|
||||
|
||||
|
||||
def resolve_password(args_password: str | None, prompt: str = "Room password: ") -> str:
|
||||
@@ -43,6 +46,8 @@ def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "serve":
|
||||
from cmd_chat.server.server import run_server
|
||||
|
||||
password = resolve_password(args.password)
|
||||
run_server(
|
||||
host=args.ip_address,
|
||||
@@ -53,6 +58,8 @@ def main():
|
||||
no_tls=args.no_tls,
|
||||
)
|
||||
elif args.command == "connect":
|
||||
from cmd_chat.client.client import Client
|
||||
|
||||
password = resolve_password(args.password)
|
||||
Client(
|
||||
server=args.ip_address,
|
||||
|
||||
Reference in New Issue
Block a user