mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:42:02 +00:00
Write full Jupyter notebook to stdout
(#7748)
## Summary When writing back notebooks via `stdout`, we need to write back the entire JSON content, not _just_ the fixed source code. Otherwise, writing the output _back_ to the file will yield an invalid notebook. Closes https://github.com/astral-sh/ruff/issues/7747 ## Test Plan `cargo test`
This commit is contained in:
parent
c71ff7eae1
commit
ebdfcee87f
4 changed files with 190 additions and 6 deletions
|
@ -402,7 +402,7 @@ pub(crate) fn lint_stdin(
|
|||
match fix_mode {
|
||||
flags::FixMode::Apply => {
|
||||
// Write the contents to stdout, regardless of whether any errors were fixed.
|
||||
io::stdout().write_all(transformed.source_code().as_bytes())?;
|
||||
transformed.write(&mut io::stdout().lock())?;
|
||||
}
|
||||
flags::FixMode::Diff => {
|
||||
// But only write a diff if it's non-empty.
|
||||
|
@ -441,7 +441,7 @@ pub(crate) fn lint_stdin(
|
|||
|
||||
// Write the contents to stdout anyway.
|
||||
if fix_mode.is_apply() {
|
||||
io::stdout().write_all(source_kind.source_code().as_bytes())?;
|
||||
source_kind.write(&mut io::stdout().lock())?;
|
||||
}
|
||||
|
||||
(result, fixed)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue