Repository navigation
fix(ruff): preserve explicit check targets - #4787
Aschenbath wants to merge 1 commit into
Conversation
📊 Automated PR Analysis
SummaryFixes a bug in Review Checklist
Linked issues: #4752 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Protocol-zero-0
left a comment
There was a problem hiding this comment.
Independently reviewed exact head 16db8f0f1bfe9bded3fdf4e20444c4a5505d802a against its immediate parent 32b2ec43.
With real Ruff 0.17.0 on Linux, I ran 25 isolated scenarios / 75 native-parent-head processes. The explicit-target cases (a=b.py, implicit check, and -- followed by equals/dash/another-separator names) no longer lint a deliberately failing neighbor. Config/output-format variants, multiple targets, and a missing-path warning were also checked. Ten cases that previously returned an unrelated failure now match native Ruff's exit 0; a genuinely failing equals-name target retains F401 and exit 1. No-target/config defaults and invalid-option/format/separator exit-2 controls retain their behavior.
The PR's five CLI argv tests pass at head; applying that same test file to the parent gives 3 passes / 2 failures. All 18 Ruff unit tests, root and proxy formatting checks, and warnings-denied all-target clippy pass.
One separate inherited issue surfaced in the stdin control: piping import sys into ruff check --stdin-filename a=b.py - under an F401-only config gives native Ruff exit 1, but both parent and head RTK return exit 0 and no F401. The shared runner defaults to null stdin and this call site does not request inherit_stdin(). This PR removes the parent's extra Ignoring file . warning, but does not fix stdin forwarding. I would track that independently rather than broaden this target-inference fix.
No full-suite, other-platform or pending-PR integration validation in this review. No new regression found in this patch's scope; approved.
|
Follow-up to the stdin case in my review: I reproduced it independently on current
The patch enables the runner's existing Validation on Linux with Ruff 0.17.0: 31 scenarios / 93 native–base–patched executions, all patched exit codes equal native, fixing 12 baseline exit-code mismatches. Includes F401/clean/empty/syntax stdin, output-format/exit-zero/quiet controls, format check, 200,011-byte source, usage errors and ordinary file/directory controls. The small formatter-stdout case also matches native byte for byte. Two argv forms retain the base's extra-dot 18 Ruff unit tests, full workspace 5253 passed / 8 ignored, root/proxy fmt and warnings-denied all-targets clippy pass. No pending-PR integration or non-Linux execution. This does not make Apply-ready stdin-only patch for develop e05c7bddiff --git a/src/cmds/python/ruff_cmd.rs b/src/cmds/python/ruff_cmd.rs
index 1830dac1..5f6a231d 100644
--- a/src/cmds/python/ruff_cmd.rs
+++ b/src/cmds/python/ruff_cmd.rs
@@ -121,7 +121,10 @@ pub fn run(args: &[String], verbose: u8) -> Result<i32> {
filter_passthrough_output(stdout, is_analyze_graph)
}
},
- runner::RunOptions::stdout_only().clean_outputs(clean_outputs),
+ // Ruff decides whether to read stdin (for example, `check -` or `format -`).
+ runner::RunOptions::stdout_only()
+ .inherit_stdin()
+ .clean_outputs(clean_outputs),
)
}
diff --git a/tests/ruff_stdin_test.rs b/tests/ruff_stdin_test.rs
new file mode 100644
index 00000000..4295651b
--- /dev/null
+++ b/tests/ruff_stdin_test.rs
@@ -0,0 +1,91 @@
+#![cfg(unix)]
+
+use std::io::Write;
+use std::os::unix::fs::PermissionsExt;
+use std::process::Stdio;
+
+mod common;
+
+fn check_stdin(args: &[&str], input: &[u8], redirected: bool) {
+ let dir = tempfile::tempdir().expect("temporary Ruff directory");
+ let capture = dir.path().join("received");
+ let stub = dir.path().join("ruff");
+ std::fs::write(
+ &stub,
+ "#!/bin/sh\ncat > \"$RUFF_STDIN_CAPTURE\"\nprintf '[]\\n'\nexit 7\n",
+ )
+ .expect("write Ruff stand-in");
+ std::fs::set_permissions(&stub, std::fs::Permissions::from_mode(0o755))
+ .expect("executable Ruff stand-in");
+ let mut cmd = common::rtk_command();
+ let path = format!(
+ "{}:{}",
+ dir.path().display(),
+ std::env::var("PATH").unwrap_or_default()
+ );
+ cmd.arg("ruff")
+ .args(args)
+ .env("PATH", path)
+ .env("RUFF_STDIN_CAPTURE", &capture)
+ .stdout(Stdio::piped())
+ .stderr(Stdio::piped());
+ let output = if redirected {
+ let source = dir.path().join("source");
+ std::fs::write(&source, input).expect("write redirected stdin");
+ cmd.stdin(std::fs::File::open(source).expect("open redirected stdin"))
+ .output()
+ .expect("run rtk ruff")
+ } else {
+ let mut child = cmd.stdin(Stdio::piped()).spawn().expect("spawn rtk ruff");
+ let mut stdin = child.stdin.take().expect("piped stdin");
+ // A writer thread also handles payloads larger than the pipe buffer.
+ let bytes = input.to_vec();
+ let writer = std::thread::spawn(move || stdin.write_all(&bytes));
+ let output = child.wait_with_output().expect("wait for rtk ruff");
+ let _ = writer.join().expect("stdin writer");
+ output
+ };
+ assert_eq!(
+ output.status.code(),
+ Some(7),
+ "native exit code: {output:?}"
+ );
+ assert_eq!(
+ std::fs::read(capture).expect("captured stdin"),
+ input,
+ "Ruff must receive the original stdin bytes"
+ );
+}
+
+#[test]
+fn check_receives_piped_source() {
+ check_stdin(
+ &["check", "--stdin-filename", "sample.py", "-"],
+ b"import sys\n",
+ false,
+ );
+}
+
+#[test]
+fn format_receives_redirected_source() {
+ check_stdin(
+ &["format", "--stdin-filename", "sample.py", "-"],
+ b"x=1\n",
+ true,
+ );
+}
+
+#[test]
+fn check_receives_large_binary_payload_unchanged() {
+ let bytes: Vec<u8> = (0..131072).map(|i| (i % 256) as u8).collect();
+ check_stdin(
+ &["check", "--stdin-filename", "sample.py", "-"],
+ &bytes,
+ false,
+ );
+}
+
+#[test]
+fn empty_stdin_reaches_eof() {
+ check_stdin(&["check", "--stdin-filename", "sample.py", "-"], b"", false);
+} |
Summary
Fixes #4752.
rtk ruff check a=b.pyused to append.and lint unrelated files in the working directory, potentially turning a successful check into an error. The same happened for targets after--that contain=or begin with-.Remove the extra path inference and let Ruff provide its own current-directory default when no target is supplied. Explicit targets remain scoped to the requested files. Ruff routing and output-format handling keep their existing behavior.
Test plan
cargo fmt --all --check, the separate proxy formatting check, andcargo clippy --workspace --all-targetspass.cargo test --all --no-fail-fast: 5,213 pass, zero fail, eight existing ignored tests, and no name filtering.Local builds disabled dev/test debuginfo to bound the RAM build cache; optimization, debug assertions, and test timeouts were unchanged.
CI used the repository's normal build profiles. Upstream Actions is awaiting maintainer approval.
Implementation, tests, and this description were prepared with Codex.