mirror of
https://github.com/trailofbits/skills.git
synced 2026-09-14 14:28:48 +08:00
3b316e6ac7
* fix(modern-python): suggest exact `uv run python` so the advice works outside projects The python/python3 shim suggested `uv run $cmd ...`, echoing back whichever name was invoked. For `python3` that advice is self-defeating on machines with no uv-managed interpreters: uv resolves the `python3` command through an ordinary PATH lookup, which hits the shim again and fails with the same suggestion. uv special-cases the exact command name `python` (uv >= 0.4.0) and executes its resolved interpreter directly, so always suggesting `uv run python ...` works everywhere. Reproduced on stock Debian + uv 0.11.27 (apt python3, zero managed pythons, no project): `uv run python3 script.py` fails via the shim while `uv run python script.py` succeeds, across script/-c/-m/REPL forms. Reported in #195. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(modern-python): satisfy shellcheck SC2016 in new bats assertions Escaped backticks in double quotes instead of literal backticks in single quotes, which shellcheck flags as a possible unintended non-expansion. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(modern-python): requote shim suggestions and carry all arguments through Review findings on #196: the -m branch interpolated only the module name, so `python -m http.server 8000` suggested a command missing the port, and `${*}` flattened arguments without quoting, so `python -c 'print(1+1)'` suggested a command that is a bash syntax error if run verbatim (plus a trailing space inside the backticks for bare invocations). Both branches now build the suggestion from %q-requoted arguments, with regression tests for each case. Also consolidates the exact-`python` rationale into a single canonical copy in the shim's header comment; README, setup-shims.sh, and the bats file now point there instead of paraphrasing it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
25 lines
760 B
Bash
Executable File
25 lines
760 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# SessionStart hook: prepend shims directory to PATH so that bare
|
|
# python/pip/pipx/uv-pip invocations are intercepted with uv suggestions.
|
|
#
|
|
# The suggested `uv run python ...` commands are unaffected by the shims;
|
|
# see the header comment in shims/python for why.
|
|
|
|
# Guard: only activate when uv is available
|
|
command -v uv &>/dev/null || exit 0
|
|
|
|
# Guard: CLAUDE_ENV_FILE must be set by the runtime
|
|
if [[ -z "${CLAUDE_ENV_FILE:-}" ]]; then
|
|
echo "modern-python: CLAUDE_ENV_FILE not set; shims will not be installed" >&2
|
|
exit 0
|
|
fi
|
|
|
|
shims_dir="$(cd "$(dirname "$0")/shims" && pwd)" || {
|
|
echo "modern-python: shims directory not found" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "export PATH=\"${shims_dir}:\${PATH}\"" >>"$CLAUDE_ENV_FILE"
|