CLI-tool helpers: mytk command, remote_cli, install_command_on_path, add_file_menu_command#98
Closed
dccote wants to merge 1 commit into
Closed
CLI-tool helpers: mytk command, remote_cli, install_command_on_path, add_file_menu_command#98dccote wants to merge 1 commit into
dccote wants to merge 1 commit into
Conversation
…th, add_file_menu_command Renames the remote CLI console script to `mytk` (keeps `mytk-remote` as a compatibility alias) — one general tool to probe/list/browse/discover and drive any RemoteControllable app. Adds three reusable helpers so downstream apps stop reinventing them: - mytk.remote_cli(argv=None, *, host, port, app_name, prog): an embeddable, branded command-line client. Delegates to the same engine as the `mytk` command (one syntax, one set of exit codes, one implementation) rather than a second parallel CLI. run()/build_parser gain default_host/port/app_name so a wrapper can bake in its target; dict results print as an aligned table. - mytk.install_command_on_path(name, *, arguments=(), directories=None): write a POSIX launcher for this program onto PATH, using sys.executable VERBATIM (never resolve() — following a venv's python symlink drops the venv's site-packages). Falls back across bin dirs, reports a PATH note, raises on Windows. - App.add_file_menu_command(label, command, *, before="Quit", separator=True): insert into the File menu without the tkinter plumbing. Purely additive. New tests in testCliTools.py; docstring + CHANGELOG updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #96 (base =
feature/remote-network-discovery); review/merge #96 first, then this. GitHub will retarget it tomainautomatically once #96 merges.Summary
Moves three pieces of generic framework plumbing into myTk so downstream apps stop reinventing them, and makes the remote CLI a first-class general tool.
What's new
mytkcommand (renamed frommytk-remote) — the one general tool to probe/--list/--browse/--discoverand drive anyRemoteControllableapp.mytk-remoteis kept as a compatibility alias (same entry point), so nothing breaks.mytk.remote_cli(argv=None, *, host, port, app_name, prog)— an embeddable, branded command-line client. A downstream app's entry point doessys.exit(mytk.remote_cli(app_name="My App", prog="my-cli"))and gets a full CLI. It delegates to the same engine as themytkcommand (run()gaineddefault_host/default_port/default_app_name) — one syntax, one set of exit codes, one implementation — rather than a second parallel CLI.dictreturn values now print as an aligned key/value table.mytk.install_command_on_path(name, *, arguments=(), directories=None)— writes a POSIX launcher for the current program onto PATH (first writable of/usr/local/bin,~/.local/bin,~/bin), so an app can distribute its branded CLI (install_command_on_path("my-cli", arguments=("ctl",))). Falls back across bin dirs, returns a PATH note, raisesRuntimeErrorif none writable.App.add_file_menu_command(label, command, *, before="Quit", separator=True)— insert into the File menu without the tkinter menu-bar plumbing.The one line to scrutinize
install_command_on_pathusessys.executableverbatim — never.resolve(). A venv'spythonis a symlink to the base interpreter; resolving it follows the symlink and silently drops the venv'ssite-packages, so the installed command would lose the app's dependencies. This was a real bug hit downstream.Design decisions (surfaced, not silently picked)
remote_clireconciled onto the existing CLI. The original spec proposed a standalone positional-arg client (my-cli add 2 3+ a custom coercer). Since myTk already shipsremotecli(themytkcommand) that introspects and dispatches,remote_clinow wraps it — same paren-call syntax ("add(2, 3)", ast-parsed literals) and exit codes. This matches the intended model ("a wrapper that calls the general tool") and avoids two CLI syntaxes in one library.mytktool's convention, which differs from the spec: connection-refused → 1 (runtime), unknown command → 1 (server fault; not pre-validated, which would cost a round-trip per call), usage error → 2.remote_clialso catches argparse'sSystemExitso it honors its documented "returns an int" contract.install_command_on_pathraisesNotImplementedError(POSIX/bin/shwrapper). A.cmdshim +%LOCALAPPDATA%bin dir is the eventual story.install_command_on_path/remote_cli/add_file_menu_command) and theargumentstuple (vs a singlesubcommand=string) are the maintainer's call — happy to rename before this is depended on downstream. The rename tomytkand theargumentstuple were confirmed with the maintainer.Usage
Tests
mytk/tests/testCliTools.py(17 tests):install_command_on_path(write/exec bits/verbatim executable, bin-dir fallback, RuntimeError, PATH note, overwrite — POSIX-only, skipped on Windows),remote_cliend-to-end against a live server (call, dict table,--list, unknown→1, usage→2, mismatch→2, refused→1),_print_result, andadd_file_menu_command.Verified locally:
testCliTools17/17, the 62-test remote suite, andtestBaseWidgetsall green. (The full local suite hangs on macOS at a pre-existing, unrelated test —testBaseWidgets.test_init_view— onmain/the parent branch too; the CI matrix is the gate.)Compatibility
Purely additive. No existing signature or behavior changes;
mytk-remotestill works.🤖 Generated with Claude Code