Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show per-cell diffs when analyzing notebooks over stdin #7789

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

charliermarsh
Copy link
Member

Summary

The implementation here differs from the non-stdin version -- this is now more consistent.

Test Plan

❯ cat Untitled.ipynb | cargo run -p ruff_cli -- check --stdin-filename Untitled.ipynb --diff -n
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/ruff check --stdin-filename Untitled.ipynb --diff -n`
--- Untitled.ipynb:cell 2
+++ Untitled.ipynb:cell 2
@@ -1 +0,0 @@
-import os
--- Untitled.ipynb:cell 4
+++ Untitled.ipynb:cell 4
@@ -1 +0,0 @@
-import sys

@charliermarsh charliermarsh added bug Something isn't working cli Related to the command-line interface labels Oct 3, 2023
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 3, 2023

CodSpeed Performance Report

Merging #7789 will improve performances by 2.58%

Comparing charlie/diff (f35e4f1) with main (600471e)

Summary

⚡ 1 improvements
✅ 24 untouched benchmarks

Benchmarks breakdown

Benchmark main charlie/diff Change
linter/default-rules[pydantic/types.py] 39 ms 38 ms +2.58%

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +431 to +432
match transformed.as_ref() {
SourceKind::Python(_) => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: This is repeated for stdout as well but I think the only difference is that the path is optional. Could we combine them under SourceKind in the same way as done in FixMode::Apply? That would avoid code duplication.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll take a look at this in a follow-up as its leading me to want to make some other changes.

Comment on lines 493 to 496
unified_diff.header(
&format!("cell {}", idx),
&format!("cell {}", idx),
);
Copy link
Member

Choose a reason for hiding this comment

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

Do you think a default value of - (or stdin / STDIN) would be good to show as the filename for stdin? I think we do that in other places. So, the output would something like:

-:cell 0:
...

-:cell 2:
...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, we don't do this in the Python case, so I'll leave it for now.

@charliermarsh charliermarsh merged commit e674e87 into main Oct 4, 2023
15 checks passed
@charliermarsh charliermarsh deleted the charlie/diff branch October 4, 2023 13:58
@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli Related to the command-line interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants