Skip to content

feat(python): recognize poetry run, filtering output like uv run#3003

Open
albatrossflyon-coder wants to merge 1 commit into
rtk-ai:developfrom
albatrossflyon-coder:feat/poetry-run-support
Open

feat(python): recognize poetry run, filtering output like uv run#3003
albatrossflyon-coder wants to merge 1 commit into
rtk-ai:developfrom
albatrossflyon-coder:feat/poetry-run-support

Conversation

@albatrossflyon-coder

Copy link
Copy Markdown

Summary

Fixes #2969.

poetry run <tool> never reached the registry — per the issue, it's the single most frequent unhandled command in rtk discover output (408 calls in 30 days, ahead of everything else unhandled), leaving ~96% noise unfiltered on a typical verbose pytest run through it.

Approach

Added poetry as a first-class command (rtk poetry), mirroring exactly how uv run already works via rtk uvnot as a transparent-prefix strip. poetry run wraps an arbitrary tool the same way uv run does, so the same generic traceback/error-block filter applies regardless of what's actually running underneath (pytest, ruff, black, whatever). poetry_cmd.rs mirrors uv_cmd.rs structurally for exactly that reason: same filtering logic, same passthrough behavior for non-run invocations, same exit code propagation. This repo's existing convention is one file per tool (checked — no shared generic wrapper module exists yet for pip/uv/etc.), so this follows that rather than introducing a new pattern.

Wiring (four places, in case any of it's useful context for review)

  1. New RtkRule (^poetry\s+runrtk poetry, prefix poetry) so rewrite_command picks it up the same way it already does for uv run.
  2. Commands::Poetry variant + dispatch to poetry_cmd::run.
  3. Added to is_operational_command's whitelist — this gates hook-pipeline integrity verification, and per that function's own doc comment a forgotten command here fails open (no check), so it needs the same treatment as every other command already in that list, not just enough to make the rewrite itself work.
  4. Added to PASSTHROUGH in the test_every_subcommand_is_classified consistency check — caught this one by actually running the full suite before opening the PR, not just the commands I wrote.

Verified live

$ rtk rewrite "poetry run pytest tests/"
rtk poetry run pytest tests/
$ rtk rewrite "poetry run ruff check ."
rtk poetry run ruff check .
$ rtk rewrite "poetry run black ."
rtk poetry run black .

(All exit 3 — "ask", the documented default for any rewritten command without an explicit permission rule, same as e.g. git status. Not a bug — see the exit-code-protocol tests in rewrite_cmd.rs.)

Full execution path against a real poetry project:

$ rtk poetry --version                                    # passthrough (non-run)
Poetry (version 2.4.1)

$ rtk poetry run python -c "print('hello')"                # success, filtered
ok

$ rtk poetry run python -c "raise RuntimeError('boom')"     # failure, filtered
Traceback (most recent call last):
File "<string>", line 1, in <module>
raise RuntimeError('boom')
RuntimeError: boom
$ echo $?
1

Testing

  • New unit tests in poetry_cmd.rs: success-noise suppression, traceback truncation, failure-summary-line preservation, failure fallback
  • cargo test: 2448 passed, 8 ignored, 0 failed (initially 1 failed — the whole-repo test_every_subcommand_is_classified consistency check — fixed by point 4 above; leaving it in this summary since it's a good example of why running the full suite before opening matters)
  • cargo clippy --all-targets -- -D warnings: clean

poetry run <tool> never reached the registry -- it's the single most
frequent unhandled command in `rtk discover` output (408 calls/30d,
ahead of every other unhandled entry), leaving ~96% noise unfiltered
on a typical verbose pytest run through it.

Added as a first-class command (`rtk poetry`, mirroring how `uv run`
already works via `rtk uv`) rather than as a transparent-prefix strip:
poetry run wraps an arbitrary tool the same way uv run does, so the
same generic traceback/error-block filter applies regardless of which
tool is being run underneath. poetry_cmd.rs mirrors uv_cmd.rs
structurally for that reason -- same filtering approach, same
passthrough-for-non-run behavior, same exit code propagation.

Wiring: new RtkRule (`^poetry\s+run` -> `rtk poetry`, prefix `poetry`)
so `rewrite_command` picks it up the same way it already does for uv;
Commands::Poetry variant + dispatch; added to is_operational_command's
whitelist (this gates hook-pipeline integrity verification -- a
forgotten command here fails open, per that function's own doc
comment, so it needs the same treatment as every other command in
that list, not just to make rewrite work); added to PASSTHROUGH so
the "every subcommand classified" consistency test passes.

Fixes rtk-ai#2969

@tapheret2 tapheret2 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: feat(python): recognize poetry run, filtering output like uv run

Files: src/cmds/python/poetry_cmd.rs, src/discover/rules.rs, src/main.rs
Size: +348 / -1

Notes

  • Static pass on the patch: no obvious blockers from the diff alone.

Thanks @albatrossflyon-coder — independent review on the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unwrap poetry run <tool> before registry lookup (408 unhandled calls/30d — top unhandled command)

2 participants