Repository navigation
Fix requirements -r after other options (#1028) - #1040
Mikola Lysenko (mikolalysenko) merged 3 commits into
Conversation
Assisted-by: Claude Code:claude-opus-5-5
A requirements line like `--pre -r dev.txt` or `-i https://mirror/simple -r base.txt` is an include pip follows, but socket-patch only looked at the first word of the line. Lock-only scans then never discovered the pins in that include and reported "No patches", and the vendored planner, in-use probe and lock inventory were blind to it too. Read the option part of the line the way pip's optparse does: walk every option word, consume the values of value-taking options (so `-i -r x` is an index URL, not an include), accept unique long-option prefixes, and follow the first `-r`. Requirement and `-e` lines stay non-includes. Fixes #1028 Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
|
About 26 All of them were created at 16:39Z and failed about 20 minutes later. None got a runner: the job API shows The CI run is still in progress, so failed jobs can't be re-run yet. I'll re-run them once, when it finishes. Anything that then fails after actually running tests gets root-caused here. Generated by Claude Code |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a2d873e. Configure here.
|
[agent] Ready for review at a2d873e.
Generated by Claude Code |
LLM Description written by Claude Code:claude-opus-5-5
Fixes #1028
Root cause
include_target_with(crates/socket-patch-core/src/vendor/pypi_requirements.rs) only matched the first shlex word of a requirements line against-r/--requirement. pip runs optparse over every option word (break_args_options→shlex.split→ optparse, then followsopts.requirements[0]), so--pre -r dev.txt,-i URL -r dev.txt,-c c.txt -r dev.txtand--prefer-binary --requirement=dev.txtare includes pip follows. Lock-only discovery, the vendored planner walk (walk_requirements_tree),requirements_include_namesand the lock inventory (lock_inventory/pypi.rs) all go through this one function, so all of them skipped those includes: a lock-only scan exited 0 with "No patches" while pip installed the include's unpatched pins.Fix
Parse the option part of the line the way pip's optparse does:
-is a requirement (its per-requirement options never recurse);-i,--extra-index-url,-c,-f,--no-binary,--only-binary,--trusted-host,--hash, ...), so-i -r dev.txtis an index URL, as in pip;--requirem→--requirement);-rvalue wins; an-eanywhere makes the line an editable requirement;--ends options.Existing #994 behaviour (quotes,
${VAR}, attached-rfile,--requirement= dev.txt) is unchanged. The npm/pypi/gem wrappers only dispatch to the binary; nothing to mirror there.Tests (red → green)
include_target_scans_every_option_word(26 cases incl. value-looks-like--r, requirement line, editable,--)"--pre -r dev.txt": None)include_after_other_option_is_followed(planner wires the pin indev.txt, root untouched)scan_requirements_lock_only::lock_only_scan_discovers_include_after_other_options(6 line shapes from the issue, hosted +--vendor)lockfileOnlyPackages0 vs 1)Local runs:
cargo clippy --workspace --all-features -- -D warnings: clean.rustfmt --edition 2021 --checkon both changed files: clean. (cargo fmt --all -- --checkreports pre-existing diffs on untouched files onmaintoo; CI does not run it.)cargo test -p socket-patch-core --all-features --lib: 5560 passed, 4 failed. The 4 (relax_loop_must_not_traverse_symlinked_root,an_unremovable_hidden_lock_keeps_every_store_entry,wire_write_failure_maps_error_and_leaves_lock_untouched,wire_failure_rolls_back_already_written_files) depend on chmod making writes fail, which doesn't happen in this sandbox because it runs as root. They don't touch the changed function.scan_requirements_lock_only5/5,scan_vendor_requirements_unwired3/3,in_process_vendor_pypi_takeover6/6,mode_migration_pypi31/31,e2e_vendor_pypi_build -- --include-ignored36/36 (real pip 24.0 / uv).cargo test --workspacecouldn't finish: the sandbox ran out of disk linking the CLI test binaries. CI runs the full suite.🤖 Generated with Claude Code
https://claude.ai/code/session_01Mh4a2b5NdLiBUqR1vaAzeQ
Note
Medium Risk
Changes shared requirements include discovery used by scan, lock inventory, and vendored wiring; behavior is narrowed to match pip but affects all PyPI lock-only paths.
Overview
Fixes #1028: lock-only scan and requirements-tree walking no longer miss
-rincludes when another pip option appears first on the same line (e.g.--pre -r dev.txt,-i URL -r dev.txt).include_target_withinpypi_requirements.rsis rewritten to mirror pip’s requirements-file optparse: skip requirement lines whose first token isn’t an option; walk every option word; consume values for known value-taking flags; resolve unique long-option prefixes; treat-eas a requirement line; honor--; take the first-r/--requirementas the include target (and don’t treat-rinside another option’s value as an include).Adds unit tests for the parser edge cases, an async test that the planner wires pins through such includes without duplicating the root file, and a CLI lock-only scan test covering six line shapes in hosted and
--vendormode.Reviewed by Cursor Bugbot for commit a2d873e. Configure here.
Generated by Claude Code